Found 9776 Articles for Object Oriented Programming

Randomly select items from a List in Java

Shriansh Kumar
Updated on 16-May-2023 10:49:00
List is the sub-interface of Java Collection Interface. It is a linear structure that stores and accesses each element in a sequential manner. To use the features of list, we use ArrayList and LinekdList class that implements the list interface. In this article, we will create an ArrayList and try to select items from that list randomly. Program to Randomly select items from a List in Java Random Class We create an object of this class to generate pseudorandom numbers. We will customize this object and apply our own logic to select any random items from the list. ... Read More

Program to add and Subtract Complex Numbers using Class in Java

Shriansh Kumar
Updated on 16-May-2023 10:45:08
Complex numbers are expressed as the sum of a real number and an imaginary number. Its general form is ‘a + ib’ where a and b represent real numbers and ‘i’ an imaginary number. For example, 5.4 + 2.6i here, 5.4 is the real part and 2.6i is the imaginary part. The various application of complex number includes quantum mechanics, signal processing and so forth. In this article, we will create a Java program to add and subtract complex numbers using class. Although it supports almost all the basic mathematical operations. Program to Add and Subtract Complex Numbers using ... Read More

Reading Text File into Java HashMap

Shriansh Kumar
Updated on 16-May-2023 10:41:30
HashMap is a class that is used to implement Map Interface. It stores its element in key-value pairs. The Key is an object that is used to fetch and receive value associated with it. It has access to all the methods of Map Interface, it does not have any additional methods of its own. Duplicate values are not allowed, although we can store null values and keys. In this article, we will try reading the content of a local text file into Java HashMap. Java Program to Read Text File into Java HashMap The general syntax for HashMap is as ... Read More

Recursion in Java

Shriansh Kumar
Updated on 16-May-2023 10:39:41
Recursion is a programming practice that allows a method to call itself as often as necessary. The method that calls itself is called as recursive method. We can find its application while calculating factorial and Fibonacci series. Recursion reduces a multi-line complex code to significantly lesser lines which makes the code more simpler and easy to understand. In this article, we will learn recursion and apply its concept to solve a few problems. Also, we will discuss the most common error found while working with the recursion in Java. Recursion Every interface, class, object, variable and method of a running ... Read More

Recursive Constructor Invocation in Java

Shriansh Kumar
Updated on 16-May-2023 10:37:38
Recursive Constructor Invocation is a compile time error that occurs when a constructor calls itself. It is similar to recursion where a method calls itself as often as necessary. The method that calls itself is called as recursive method and the constructor that calls itself is called as recursive constructor. In this article, we will understand the Recursive Constructor Invocation error in Java with a few examples. Recursive Constructor Invocation Constructor It is quite similar to methods but the difference is that methods define the behavior of an object but constructor is used to initialize those objects. We can provide ... Read More

Program to print interesting pattern

Shriansh Kumar
Updated on 16-May-2023 12:17:40
Solving interesting pattern problems enhances the understanding of loops. They are essential because they help in building a strong foundation of a particular programming language. There are various kinds of patterns including number-based, star-based and alphabetical patterns as well. In this article, we will discuss a few Java programs to print interesting star patterns. Program to Print Interesting Pattern Pattern 1 Approach Declare and initialize an integer ‘n’ that specifies number of rows and columns. Define a for loop that will run till ‘n’. Inside this loop define an if-else block. The if block will print star ‘n’ ... Read More

StAX vs SAX Parser in Java

Shriansh Kumar
Updated on 15-May-2023 17:41:53
Both StAX and SAX are a type of XML parser APIs. Here, API stands for Application Programming Interface and Parser is used to read and extract content from an XML document in desired format. From this line, it is clear that StAX and SAX are used to read XML documents. APIs are a modern way to migrate real time information on the Web. In this article, we will discuss the difference between StAX and SAX Parser in Java. StAX vs SAX Parser XML Its full form is eXtensible Markup Language and it is said to be a data description language. ... Read More

Similarities between TreeMap and TreeSet in Java

Shriansh Kumar
Updated on 15-May-2023 17:39:43
The TreeMap and TreeSet, both are the part of Collection Framework classes. There exist a few differences as well as a few similarities in their implementation and working. The TreeMap maintains key-value pair on the other hand the TreeSet does not have this feature. In this article, we will discuss the similarities between both classes of Collection Interface. Collection Interface In Java, collection is an object or we can say a container for simplicity that allows us to group several numbers of objects in a single unit. The collection interface is present at the root of all collection framework interfaces. ... Read More

Standard Practice for Protecting Sensitive Data in Java

Shriansh Kumar
Updated on 15-May-2023 17:38:14
Every time we do surfing on the Web or we download any file from Web, we take a risk of a virus attack. Maybe that file contains some malicious code that can breach the security and gain unauthorized access to system resources. If we are building an application that has users’ sensitive data, for example, a banking system contains confidential data like credit and debit card details, addresses, email and so forth. Then securing those data becomes our foremost priority. In this article, we are going to discuss a few standard practices for protecting the sensitive data of users in ... Read More

Non-blocking Server in Java NIO

Deepti S
Updated on 15-May-2023 17:53:07
Non-blocking Server Java NIO (New Input/Output) is a very powerful networking and file-handling application that functions as an alternative to Java's standard IO API. Due to the addition of more sophisticated features since JDK 4's introduction, it has quickly emerged as the preferred I/O system among numerous engineers. The improved support it offers for file handling and file system features is one of the features that distinguish Java NIO. Since the NIO file classes have such incredible capabilities, it is extensively used in file handling. If you look closely, you'll notice that java.nio package specifies the buffer classes employed by ... Read More
Advertisements