Found 9122 Articles for Object Oriented Programming

How HashTable Works Internally in Java?

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

3K+ 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

953 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

2K+ 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

200 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

204 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

300 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

1K+ 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

Different Ways to Create the Instances of Wrapper Classes in Java

Shriansh Kumar
Updated on 20-Jul-2023 21:14:47

374 Views

To encapsulate or represent a primitive datatype within an object, Java provides theconcept of Wrapper classes. All eight wrapper classes are as follows Double, Float, Long, Integer, Short, Byte, Character, and Boolean. These classes have a variety of in-builtmethods that allows us to integrate primitives into their respective instances as well asdisintegrate instances into their respective primitive datatypes. This article aims to explainthe different ways to create instances of Wrapper Classes. Creating Instances of Wrapper Classes The following approaches are available in Java to create Instances of Wrapper Classes − With the help of Constructor Although we can create an ... Read More

Different Ways to Print First K Characters of the String in Java

Shriansh Kumar
Updated on 20-Jul-2023 21:09:15

238 Views

A string is a class in Java that stores a series of characters enclosed within double quotes.Those characters are actually String-type objects. The string class is available in the‘java.lang’ package. Suppose we have given a string and a positive integer ‘k’. Now, thejob is to print that string's first 'k' characters in Java. Also, check whether the length ofgiven string is less than or not, if so print the original string. Java Program to Print First K Characters of the String Let’s understand the given problem with a few examples − Instance String st1 = “TutorialsPoint”; String st2 = “Tutorial”; ... Read More

Getting Least Value Element From a Set by Using Sorting Logic on TreeSet in Java

Shriansh Kumar
Updated on 20-Jul-2023 21:06:28

82 Views

TreeSet is a class of Java Collection Framework that implements the SortedSet Interface.It stores elements in ascending order and does not allow duplicate values therefore, theaccess and retrieval time becomes faster. Because of this excellent feature, TreeSet isfrequently used to store large amounts of information that need to be searched quickly.We will use the Comparable Interface to sort the given TreeSet and then using in-builtmethod named ‘first()’, we try to get the least value element from that TreeSet. Java Program to get Least value element from TreeSet Before jumping into the program, let’s familiarize ourselves with a few concepts − ... Read More

Advertisements