Found 2616 Articles for Java

Different Approaches to Concurrent Programming in Java

Shriansh Kumar
Updated on 21-Jul-2023 20:07:38

158 Views

In Java, concurrent programming is a technique that allows multiple tasks or processes to run simultaneously on a single processor or multiple processors. It can improve the performance and responsiveness of applications. However, it also introduces new challenges and complexities to the Java developers, such as synchronization and deadlock. In this article, we will explore some of the different approaches to concurrent programming such as multithreading and executors. Concurrent Programming in Java The following three components of Java are used for Concurrent Programming java.lang.Thread clas java.lang.Runnable java.util.concurrent Multithreading It is a feature of the Java programming language that ... Read More

Different Ways to Achieve Pass By Reference in Java

Shriansh Kumar
Updated on 21-Jul-2023 19:56:29

554 Views

The most frequent query asked by beginner programmers, especially those who have already worked with C and C++ in the past, is whether Java supports pass-by-referenceor pass-by-value. Generally, programming languages use pass-by-value and pass-byreferencefor passing parameters to a method. However, Java does not support both approaches rather it uses pass-by-value to pass both primitive and reference type values. But, it provides a few ways to achieve pass-by-reference, we will explore those through this article. Ways to Achieve Paas By Reference Let’s start this discussion by understanding the storage mechanism of Java. The reference variables, names of methods and classes are ... Read More

How Java filter() Method Works in Background?

Shriansh Kumar
Updated on 21-Jul-2023 19:52:32

208 Views

The Java filter() method allows us to strain elements of the stream based on the specified condition. It is a part of higher-order function that is used to apply a certain behavior on stream items. This method takes a predicate as an argument and returns a list of elements that match the predicate. But the question arises here is that how this filter() method works in the background. This article aims to explain this question through some example programs. Working of filter() method in Background Before going deep into the filter() method, let’s familiarize ourselves with I/O Streams. Itis an ... Read More

How HashTable Works Internally in Java?

Shriansh Kumar
Updated on 20-Jul-2023 22:15:06

1K+ Views

The Hashtable class is a part of the Java Collection Framework that stores its element in key-value pairs in a hash table. The Key is an object that can be used to fetch and receive value associated with it. There exist a few similarities between a Hashtable and HashMapclass but Hash table is synchronized. Also, its keys must be associated with values, they could not be null. This article aims to explain how Hash table works internally in Java. Working of Hashtable in Java We can consider a Hashtable as an array of buckets, where each bucket contains a list ... Read More

How does Java process the backspace terminal control character?

Shriansh Kumar
Updated on 20-Jul-2023 22:10:46

408 Views

The backspace terminal control character is a special character represented by the ‘\b’notation. It is used to move the cursor one character back. It comes under Java escape characters, these characters are used with backslash (\) and hold a special meaning to the compiler. In this article, we will understand and see the practical implementation of‘\b’ notation through Java example programs. Working of Backspace Terminal Control Character Two types of situations may arise while working with this escape character. First, when we hard code the backspace character into a String and the second, when we take input using a keyboard. ... Read More

Different Ways to Copy Files in Java

Shriansh Kumar
Updated on 20-Jul-2023 22:05:36

651 Views

Java provides different ways to copy files including the ‘File’, ‘FileInputStream’ and‘FileOutputStream’ classes. There are times when we need to take a backup, compress a file or share it with others. In these situations, copying that file becomes necessary. Weare going to explore the methods and classes that will help us to copy the content of one file to another file through Java programs. Before jumping to the example program directly, let’s discuss some classes and built-in methods that we will be using. This will build a foundation for understanding the code. Note that these classes and methods are associated ... Read More

Different name reusing techniques in Java

Shriansh Kumar
Updated on 02-Aug-2023 17:06:44

122 Views

In Java, there exist different name reusing techniques for various types of entities, sucha s variables, methods, datatypes or packages. These techniques affect the accessibility and behavior of the entities according to their need and use. In this article, we will discuss four common ways to reuse a name in Java: overriding, hiding, overloading and shadowing Name reusing techniques in Java Shadowing This technique allows a local variable to have the same name as another field or member of the enclosing class. In this case, the previous implementation of the member gets shadowed by the declaration of a new variable. ... Read More

Different Method Calls in Java

Shriansh Kumar
Updated on 20-Jul-2023 21:40:19

84 Views

Java provides different method calls techniques that we can use according to the need andscenario in our program. Here, methods mean a block of code that can be reused multipletimes to perform a single operation. It saves our time and also reduces the size of code.The method call is referred to as invocation of methods. To use the functionality of amethod, it must be invoked by some means. This article aims to explain how methods arecalled in Java User-defined Method in Java Before discussing the method call, let’s familiarize ourselves with syntax of the userdefined methods Syntax accessSpecifier nonAccessModifier return_Type ... Read More

Heap and Stack Memory Errors in Java

Shriansh Kumar
Updated on 21-Jul-2023 11:06:46

170 Views

In Java, every interface, class, object, variable and method of a running program is stored in distinct reasons of computer memory. The heap is the part of memory area where values of variables, methods and classes are stored at runtime. Its allocation happens dynamically and can grow or shrink depending on the application's needs. On the other hand, the reference variables, names of methods and classes are stored in the stack memory area. However, if for some reason their allocation is not handled properly then, it may lead to memory errors that we are going to discuss in this article. ... Read More

How are parameters passed in Java?

Shriansh Kumar
Updated on 20-Jul-2023 21:19:58

782 Views

The most frequent query asked by beginner programmers is that how are parameters passed in Java. Generally, the programming languages use pass by value and pass byreference for passing parameters to a method. However, Java does not support both approaches rather it uses pass by value to pass both primitive and reference type values. In this article, we are going to understand passing parameters by value through exampleprograms. Passing Parameters to a Method in Java Let’s start this discussion by understanding the storage mechanism of Java. The referencevariables, names of methods and classes are stored in stack and their values ... Read More

Advertisements