Found 2616 Articles for Java

Check if a sequence of path visits any coordinate twice or not

Siva Sai
Updated on 16-Oct-2023 16:21:38

77 Views

In certain applications, we might be interested in checking whether a sequence of path visits any coordinate twice or not. This can be useful, for example, in GPS tracking systems to detect if a vehicle is going back and forth between two points. In this article, we will discuss how to check if a sequence of path visits any coordinate twice or not, along with its implementation in C++. Algorithm To solve this problem, we can use a hash table to keep track of all the coordinates that we have visited so far. We start by visiting the first coordinate ... Read More

Program to print Hut Star pattern

Shriansh Kumar
Updated on 16-May-2023 11:21:11

552 Views

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. This article will guide you to solve a hut star pattern using nested for loop in Java. Java Program to print Hut Star Pattern Since we are going to solve the problem using nested for loop therefore, it is necessary to discuss its syntax. Syntax for ( initial expression; conditional expression; increment/decrement expression ){ for ( ... Read More

Public vs Protected vs Package vs Private Access Modifiers in Java

Shriansh Kumar
Updated on 16-May-2023 11:19:58

386 Views

Java has various levels of protection that allow precise control over the accessibility of member variables and methods within classes, subclasses, and packages. The access control mechanism works with the help of access modifiers such as public, protected, private and package. They define scope of a variable, class and method. We are going to understand the various access modifiers in Java. Access Modifiers in Java Public Access Modifier Java does not restrict the accessibility of public members. Anything declared public can be accessible everywhere means we can access them within the class as well as outside the class and ... Read More

Protected vs Package Access Modifiers in Java

Shriansh Kumar
Updated on 16-May-2023 11:04:21

442 Views

The protected and package access modifiers determine how a member of a class or method can be accessed. The modifiers are attached to the members at the time of declaration. We know that these access modifiers play a major role in Java oops concepts like encapsulation, polymorphism and inheritance. It helps in preventing misuse of functionalities provided by a member. We will try to understand protected and package access modifiers in Java through example programs. Access Modifiers in Java Protected Access Modifier It is mostly used in the case of inheritance to control the access of parent class members ... Read More

Protected vs Final Access Modifier in Java

Shriansh Kumar
Updated on 16-May-2023 11:01:04

708 Views

The protected and final access modifiers determine how a member of a class or method can be accessed. The modifiers are attached to the members at the time of declaration. We know that these access modifiers play a major role in Java oops concepts like encapsulation and inheritance. It helps in preventing misuse of functionalities provided by a member. We will try to understand protected and final access modifiers in Java through example programs. Access Modifiers in Java Protected Access Modifier It is mostly used in the case of inheritance to control the access of parent class members and ... Read More

Program to validate a user using JSP

Shriansh Kumar
Updated on 16-May-2023 10:58:16

3K+ Views

JSP stands for Java Server Pages and is used for the purpose of developing web based applications. A single JSP page consists of HTML tags for static content and JSP tags to construct dynamic content. The JSP tags start with ‘’. We save our JSP file with the extension ‘.jsp’. Validating a user means simply checking whether the user has entered correct login details or not. The validation process in JSP is quite simple and straightforward. This article will guide you to create a program to validate a user using JSP. Steps to create a Program to Validate a ... Read More

Reetrant Lock in Java

Shriansh Kumar
Updated on 16-May-2023 10:53:41

295 Views

ReetrantLock is a class that implements Lock Interface. It provides the synchronization feature with great flexibility which is why it is the most used lock class in Java. It is necessary for the reliable and fair working of thread. Here, threads are small sub-processes of a big operation. In this article, we are going to learn ReetrantLock and how they manage threads so that they can work efficiently. Working of ReetrantLock When multiple threads try to access a shared resource then, ReetrantLock restricts access to a single thread at a time through ‘lock()’ and ‘unlock()’ methods. Suppose there are ... Read More

Randomly select items from a List in Java

Shriansh Kumar
Updated on 16-May-2023 10:49:00

7K+ Views

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

1K+ Views

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

2K+ Views

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

Advertisements