Java is a powerful, object-oriented programming language used widely in enterprise applications, Android development, and backend systems. Understanding Java fundamentals is essential for clearing interviews and building a strong programming foundation.
It suitable for both freshers and those brushing up their base concepts for technical interviews.
Yes, Java is a Platform Independent language. Unlike many programming languages javac compiles the program to form a bytecode or .class file. This file is independent of the software or hardware running but needs a JVM(Java Virtual Machine) file preinstalled in the operating system for further execution of the bytecode.
Although JVM is platform dependent, the bytecode can be created on any System and can be executed in any other system despite hardware or software being used which makes Java platform independent.
2. What is a classloader?
Classloader is the part of JRE(Java Runtime Environment), during the execution of the bytecode or created .class file classloader is responsible for dynamically loading the java classes and interfaces to JVM(Java Virtual Machine). Because of classloaders Java run time system does not need to know about files and file systems.
To know more about the topic refer to ClassLoader in Java.
3. Difference between JVM, JRE, and JDK.
JVM: JVM also known as Java Virtual Machine is a part of JRE. JVM is a type of interpreter responsible for converting bytecode into machine-readable code. JVM itself is platform dependent but it interprets the bytecode which is the platform-independent reason why Java is platform-independent.
JRE: JRE stands for Java Runtime Environment, it is an installation package that provides an environment to run the Java program or application on any machine.
JDK: JDK stands for Java Development Kit which provides the environment to develop and execute Java programs. JDK is a package that includes two things Development Tools to provide an environment to develop your Java programs and, JRE to execute Java programs or applications.
To know more about the topic refer to the Differences between JVM, JRE, and JDK.
4. What are the differences between Java and C++?
Basis | C++ | Java |
---|
Platform | C++ is Platform Dependent | Java is Platform Independent |
---|
Application | C++ is mainly used for System Programming | Java is Mainly used for Application Programming |
---|
Hardware | C++ is nearer to hardware | Java is not so interactive with hardware |
---|
Global Scope | C++ supports global and namespace scope. | Java doesn't support global scope. |
---|
Not Supporting | Functionality supported in Java but not in C++ are: - thread support
- documentation comment
- unsigned right shift(>>>)
| Functionality supported in C++ but not in Java are: - goto
- Pointers
- Call by reference
- Structures and Unions
- Multiple Inheritance
- Virtual Functions
|
---|
OOPS | C++ is an object-oriented language. It is not a single root hierarchy . | Java is also an object-oriented language. It is a single root hierarchy as everything gets derived from a single class (java.lang.Object). |
---|
Inheritance Tree | C++ always creates a new inheritance tree. | Java uses a Single inheritance tree as classes in Java are the child of object classes in Java. |
---|
5. Explain public static void main(String args[]) in Java.

Unlike any other programming language like C, C++, etc. In Java, we declared the main function as a public static void main (String args[]). The meanings of the terms are mentioned below:
- public: the public is the access modifier responsible for mentioning who can access the element or the method and what is the limit. It is responsible for making the main function globally available. It is made public so that JVM can invoke it from outside the class as it is not present in the current class.
- static: static is a keyword used so that we can use the element without initiating the class so to avoid the unnecessary allocation of the memory.
- void: void is a keyword and is used to specify that a method doesn’t return anything. As the main function doesn't return anything we use void.
- main: main represents that the function declared is the main function. It helps JVM to identify that the declared function is the main function.
- String args[]: It stores Java command-line arguments and is an array of type java.lang.String class.
6. What is Java String Pool?
A Java String Pool is a place in heap memory where all the strings defined in the program are stored. A separate place in a stack is there where the variable storing the string is stored. Whenever we create a new string object, JVM checks for the presence of the object in the String pool, If String is available in the pool, the same object reference is shared with the variable, else a new object is created.

Example:
String str1="Hello";
// "Hello" will be stored in String Pool
// str1 will be stored in stack memory
7. What will happen if we don't declare the main as static?
We can declare the main method without using static and without getting any errors. But, the main method will not be treated as the entry point to the application or the program.
8. What are Packages in Java, Why they used ?
Packages in Java can be defined as the grouping of related types of classes, interfaces, etc providing access to protection and namespace management. Packages are used in Java in order to prevent naming conflicts, control access, and make searching/locating and usage of classes, interfaces, etc easier.
There are various advantages of defining packages in Java.
- Packages avoid name clashes.
- The Package provides easier access control.
- We can also have the hidden classes that are not visible outside and are used by the package.
- It is easier to locate the related classes.
There are two types of packages in Java
- User-defined packages
- Build In packages
9. Can we declare Pointer in Java?
No, Java doesn't provide the support of Pointer. As Java needed to be more secure because which feature of the pointer is not provided in Java.
10. When a byte datatype is used & What is its default value?
A byte is an 8-bit signed two-complement integer. The minimum value supported by bytes is -128 and 127 is the maximum value. It is used in conditions where we need to save memory and the limit of numbers needed is between -128 to 127.
The default value of the byte datatype in Java is 0.
11. What is the Wrapper class in Java & Why we need them?
Wrapper, in general, is referred to a larger entity that encapsulates a smaller entity. Here in Java, the wrapper class is an object class that encapsulates the primitive data types.
The primitive data types are the ones from which further data types could be created. For example, integers can further lead to the construction of long, byte, short, etc. On the other hand, the string cannot, hence it is not primitive.
Getting back to the wrapper class, Java contains 8 wrapper classes. They are Boolean, Byte, Short, Integer, Character, Long, Float, and Double. Further, custom wrapper classes can also be created in Java which is similar to the concept of Structure in the C programming language. We create our own wrapper class with the required data types.
The wrapper class is an object class that encapsulates the primitive data types, and we need them for the following reasons:
- Wrapper classes are final and immutable
- Provides methods like valueOf(), parseInt(), etc.
- It provides the feature of autoboxing and unboxing.
12. differentiate between instance and local variables & What are the default values assigned to variables and instances in Java?
Instance Variable | Local Variable |
---|
Declared outside the method, directly invoked by the method. | Declared within the method. |
Has a default value. | No default value |
It can be used throughout the class. | The scope is limited to the method. |
In Java When we haven’t initialized the instance variables then the compiler initializes them with default values. The default values for instances and variables depend on their data types. Some common types of default data types are:
- The default value for numeric types (byte, short, int, long, float, and double) is 0.
- The default value for the boolean type is false.
- The default value for object types (classes, interfaces, and arrays) is null.
- The null character, "u0000, " is the default value for the char type.
Example:
Java
// Java Program to demonstrate use of default values
import java.io.*;
class GFG {
// static values
static byte b;
static int i;
static long l;
static short s;
static boolean bool;
static char c;
static String str;
static Object object;
static float f;
static double d;
static int[] Arr;
public static void main(String[] args)
{
// byte value
System.out.println("byte value" + b);
// short value
System.out.println("short value" + s);
// int value
System.out.println("int value" + i);
// long value
System.out.println("long value" + l);
System.out.println("boolean value" + bool);
System.out.println("char value" + c);
System.out.println("float value" + f);
System.out.println("double value" + d);
System.out.println("string value" + str);
System.out.println("object value" + object);
System.out.println("Array value" + Arr);
}
}
Output:
byte value0
short value0
int value0
long value0
boolean valuefalse
char value
float value0.0
double value0.0
string valuenull
object valuenull
Array valuenull
13. Explain the difference between instance variable and a class variable.
Instance Variable: A class variable without the static modifier is called an instance variable. It is unique to each object (instance) of the class and is not shared between instances.
Example:
Java
// Java Program to demonstrate Instance Variable
import java.io.*;
class GFG {
private String name;
public void setName(String name) { this.name = name; }
public String getName() { return name; }
public static void main(String[] args)
{
GFG obj = new GFG();
obj.setName("John");
System.out.println("Name " + obj.getName());
}
}
Class Variable: Class Variable variable can be declared anywhere at the class level using the keyword static. These variables can only have one value when applied to various objects. These variables can be shared by all class members since they are not connected to any specific object of the class.
Example:
Java
// Java Program to demonstrate Class Variable
import java.io.*;
class GFG {
// class variable
private static final double PI = 3.14159;
private double radius;
public GFG(double radius) { this.radius = radius; }
public double getArea() { return PI * radius * radius; }
public static void main(String[] args)
{
GFG obj = new GFG(5.0);
System.out.println("Area of circle: "
+ obj.getArea());
}
OutputArea of circle: 78.53975
14. What is the difference between System.out, System.err, and System.in?
System.out: It is a PrintStream that is used for writing characters or can be said it can output the data we want to write on the Command Line Interface console/terminal.
Example:
Java
// Java Program to implement
// System.out
import java.io.*;
// Driver Class
class GFG {
// Main Function
public static void main(String[] args)
{
// Use of System.out
System.out.println("");
}
}
System.err: It is used to display error messages.
Example:
Java
// Java program to demonstrate
// System.err
import java.io.*;
// Driver Class
class GFG {
// Main function
public static void main(String[] args)
{
// Printing error
System.err.println(
"This is how we throw error with System.err");
}
}
Output:
This is how we throw error with System.err
Although, System.err have many similarities both of them have quite a lot of difference also, let us check them.
System.out | System.err |
---|
It will print to the standard out of the system. | It will print to the standard error. |
It is mostly used to display results on the console. | It is mostly used to output error texts. |
It gives output on the console with the default(black) color. | It also gives output on the console but most of the IDEs give it a red color to differentiate. |
System.in: It is an InputStream used to read input from the terminal Window. We can't use the System.in directly so we use Scanner class for taking input with the system.in.
Example:
Java
// Java Program to demonstrate
// System.in
import java.util.*;
// Driver Class
class Main {
// Main Function
public static void main(String[] args)
{
// Scanner class with System.in
Scanner sc = new Scanner(System.in);
// Taking input from the user
int x = sc.nextInt();
int y = sc.nextInt();
// Printing the output
System.out.printf("Addition: %d", x + y);
}
}
Output:
3
4
Addition: 7
15. What do you understand by an IO stream?

Java brings various Streams with its I/O package that helps the user to perform all the input-output operations. These streams support all types of objects, data types, characters, files, etc to fully execute the I/O operations.
The key difference between them is that byte stream data is read and written by input/output stream classes. Characters are handled by the Reader and Writer classes. In contrast to Reader/Writer classes, which accept character arrays as parameters, input/output stream class methods accept byte arrays. In comparison to input/output streams, the Reader/Writer classes are more efficient, handle all Unicode characters, and are useful for internalization. Use Reader/Writer classes instead of binary data, such as pictures, unless you do so.
Example:
Java
// Java Program to demonstrate Reading Writing Binary Data
// with InputStream/OutputStream
import java.io.*;
class GFG {
public static void main(String[] args) {
try {
// Writing binary data to a file using OutputStream
byte[] data = {(byte) 0xe0, 0x4f, (byte) 0xd0, 0x20, (byte) 0xea};
OutputStream os = new FileOutputStream("data.bin");
os.write(data);
os.close();
// Reading binary data from a file using InputStream
InputStream is = new FileInputStream("data.bin");
byte[] newData = new byte[5];
is.read(newData);
is.close();
// Printing the read data
for (byte b : newData) {
System.out.print(b+" ");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
17. What are the super most classes for all the streams?
All the stream classes can be divided into two types of classes that are ByteStream classes and CharacterStream Classes. The ByteStream classes are further divided into InputStream classes and OutputStream classes. CharacterStream classes are also divided into Reader classes and Writer classes. The SuperMost classes for all the InputStream classes is java.io.InputStream and for all the output stream classes is java.io.OutPutStream. Similarly, for all the reader classes, the super-most class is java.io.Reader, and for all the writer classes, it is java.io.Writer.
To read and write data, Java offers I/O Streams. A Stream represents an input source or an output destination, which could be a file, an i/o device, another program, etc. FileInputStream in Java is used to read data from a file as a stream of bytes. It is mostly used for reading binary data such as images, audio files, or serialized objects.
Example:
File file = new File("path_of_the_file");
FileInputStream inputStream = new FileInputStream(file);
In Java, the FileOutputStream function is used to write data byte by byte into a given file or file descriptor. Usually, raw byte data, such as pictures, is written into a file using FileOutputStream.
Example:
File file = new File("path_of_the_file");
FileOutputStream outputStream = new FileOutputStream(file);
When we are working with the files or stream then to increase the Input/Output performance of the program we need to use the BufferedInputStream and BufferedOutputStream classes. These both classes provide the capability of buffering which means that the data will be stored in a buffer before writing to a file or reading it from a stream. It also reduces the number of times our OS needs to interact with the network or the disk. Buffering allows programs to write a big amount of data instead of writing it in small chunks. This also reduces the overhead of accessing the network or the disk.
BufferedInputStream(InputStream inp);
// used to create the bufferinput stream and save the arguments.
BufferedOutputStream(OutputStream output);
// used to create a new buffer with the default size.
20. What are FilterStreams?
Stream filter or Filter Streams returns a stream consisting of the elements of this stream that match the given predicate. While working filter() it doesn't actually perform filtering but instead creates a new stream that, when traversed, contains the elements of initial streams that match the given predicate.
Example:
FileInputStream fis =new FileInoutStream("file_path");
FilterInputStream = new BufferedInputStream(fis);
21. What is an I/O filter?
An I/O filter also defined as an Input Output filter is an object that reads from one stream and writes data to input and output sources. It used java.io package to use this filter.
There are two methods to take input from the console in Java mentioned below:
- Using Command line argument
- Using Buffered Reader Class
- Using Console Class
- Using Scanner Class
The program demonstrating the use of each method is given below.
Example 1:
Java
// Java Program to implement input
// using Command line argument
import java.io.*;
class GFG {
public static void main(String[] args)
{
// check if length of args array is
// greater than 0
if (args.length > 0) {
System.out.println(
"The command line arguments are:");
// iterating the args array and printing
// the command line arguments
for (String val : args)
System.out.println(val);
}
else
System.out.println("No command line "
+ "arguments found.");
}
}
// Use below commands to run the code
// javac GFG.java
// java Main GeeksforGeeks
Example 2:
Java
// Java Program to implement
// Buffer Reader Class
import java.io.*;
class GFG {
public static void main(String[] args)
throws IOException
{
// Enter data using BufferReader
BufferedReader read = new BufferedReader(
new InputStreamReader(System.in));
// Reading data using readLine
String x = read.readLine();
// Printing the read line
System.out.println(x);
}
}
Output:
null
Example 3:
Java
// Java program to implement input
// Using Console Class
public class GfG {
public static void main(String[] args)
{
// Using Console to input data from user
String x = System.console().readLine();
System.out.println("You entered string " + x);
}
}
Example 4:
Java
// Java program to demonstrate
// working of Scanner in Java
import java.util.Scanner;
class GfG {
public static void main(String args[])
{
// Using Scanner for Getting Input from User
Scanner in = new Scanner(System.in);
String str = in.nextLine();
System.out.println("You entered string " + str);
}
}
Output:
GeeksforGeeks
23. Difference in the use of print, println, and printf.
print, println, and printf all are used for printing the elements but print prints all the elements and the cursor remains in the same line. println shifts the cursor to next line. And with printf we can use format identifiers too.
24. Explain the difference between >> and >>> operators.
Operators like >> and >>> seem to be the same but act a bit differently. >> operator shifts the sign bits and the >>> operator is used in shifting out the zero-filled bits.
Example:
Java
import java.io.*;
// Driver
class GFG {
public static void main(String[] args) {
int a = -16, b = 1;
// Use of >>
System.out.println(a >> b);
a = -17;
b = 1;
// Use of >>>
System.out.println(a >>> b);
}
}
25. What is dot operator?
The Dot operator in Java is used to access the instance variables and methods of class objects. It is also used to access classes and sub-packages from the package.
26. What is covariant return type?
The covariant return type specifies that the return type may vary in the same direction as the subclass. It's possible to have different return types for an overriding method in the child class, but the child’s return type should be a subtype of the parent’s return type and because of that overriding method becomes variant with respect to the return type.
We use covariant return type because of the following reasons:
- Avoids confusing type casts present in the class hierarchy and makes the code readable, usable, and maintainable.
- Gives liberty to have more specific return types when overriding methods.
- Help in preventing run-time ClassCastExceptions on returns.
27. What are the differences between String and StringBuffer?
String | StringBuffer |
---|
Store of a sequence of characters. | Provides functionality to work with the strings. |
It is immutable. | It is mutable (can be modified and other string operations could be performed on them.) |
No thread operations in a string. | It is thread-safe (two threads can't call the methods of StringBuffer simultaneously) |
28.. What are the differences between StringBuffer and StringBuilder & Which one should be preferred when there are a lot of updates required to be done in the data?
StringBuffer | StringBuilder |
---|
StringBuffer provides functionality to work with the strings. | StringBuilder is a class used to build a mutable string. |
It is thread-safe (two threads can't call the methods of StringBuffer simultaneously) | It is not thread-safe (two threads can call the methods concurrently) |
Comparatively slow as it is synchronized. | Being non-synchronized, implementation is faster |
29. Why is StringBuffer called mutable?
StringBuffer class in Java is used to represent a changeable string of characters. It offers an alternative to the immutable String class by enabling you to change a string's contents without constantly creating new objects. Mutable (modifiable) strings are created with the help of the StringBuffer class. The StringBuffer class in Java is identical to the String class except that it is changeable.
Example:
Java
// Java Program to demonstrate use of stringbuffer
public class StringBufferExample {
public static void main(String[] args)
{
StringBuffer s = new StringBuffer();
s.append("Geeks");
s.append("for");
s.append("Geeks");
String message = s.toString();
System.out.println(message);
}
}
30. On which memory arrays are created in Java?
Arrays in Java are created in heap memory. When an array is created with the help of a new keyword, memory is allocated in the heap to store the elements of the array. In Java, the heap memory is managed by the Java Virtual Machine(JVM) and it is also shared between all threads of the Java Program. The memory which is no longer in use by the program, JVM uses a garbage collector to reclaim the memory. Arrays in Java are created dynamically which means the size of the array is determined during the runtime of the program. The size of the array is specified during the declaration of the array and it cannot be changed once the array is created.
6. What is the difference between int array[] and int[] array?
Both int array[] and int[] array are used to declare an array of integers in java. The only difference between them is on their syntax no functionality difference is present between them.
int arr[] is a C-Style syntax to declare an Array.
int[] arr is a Java-Style syntax to declare an Array.
However, it is generally recommended to use Java-style syntax to declare an Array. As it is easy to read and understand also it is more consistent with other Java language constructs.
31. How to copy an array in Java?
In Java, there are multiple ways to copy an array based on the requirements:
1. clone() Method (Shallow Copy)
- The clone() method creates a new array with its own memory but contains references to the same objects for non-primitive data types.
- For primitive arrays, it behaves like a deep copy since primitive values are directly copied.
int[] arr = {1, 2, 3, 5, 0};
int[] tempArr = arr.clone(); // Creates a new array with copied values
2. System.arraycopy() Method (Deep Copy)
- This method creates a new array and copies elements from the original array.
- It allows partial copying by specifying an offset and length.
int[] arr = {1, 2, 7, 9, 8};
int[] tempArr = new int[arr.length];
System.arraycopy(arr, 0, tempArr, 0, arr.length);
3. Arrays.copyOf() Method (Creates New Array)
- This method creates a new array and copies the entire original array into it.
- If the specified length is greater than the original array, extra elements are initialized with default values.
int[] arr = {1, 2, 4, 8};
int[] tempArr = Arrays.copyOf(arr, arr.length);
4. Arrays.copyOfRange() Method (Copying a Subset)
- Similar to copyOf(), but allows copying a specific range of elements.
int[] arr = {1, 2, 4, 8};
int[] tempArr = Arrays.copyOfRange(arr, 0, arr.length);
32. What do you understand by the jagged array?
A jagged Array in Java is just a two-dimensional array in which each row of the array can have a different length. Since all the rows in a 2-d Array have the same length but a jagged array allows more flexibility in the size of each row. This feature is very useful in conditions where the data has varying lengths or when memory usage needs to be optimized.
Syntax:
int[][] Arr = new int[][] {
{1, 2, 8},
{7, 5},
{6, 7, 2, 6}
};
33. Is it possible to make an array volatile?
In Java, it is not possible to make a volatile. Volatile keywords in Java can only be applied to individual variables but not to arrays or collections. The value of the Variable is always read from and written to the main memory when it is defined as volatile rather than being cached in a thread's local memory. This makes it easier to make sure that all threads that access the variable can see changes made to it.
34. What is a static variable?
The static keyword is used to share the same variable or method of a given class. Static variables are the variables that once declared then a single copy of the variable is created and shared among all objects at the class level.
35. What is the transient keyword?
The transient keyword is used at the time of serialization if we don’t want to save the value of a particular variable in a file. When JVM comes across a transient keyword, it ignores the original value of the variable and saves the default value of that variable data type
Similar Reads
Java Tutorial Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. Known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Syntax and s
7 min read
Basics
Introduction to JavaJava is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. It is platform-independent, which means we can write code once and run it anywhere using the Java Virtual Machine (JVM). Java is mostly used for building desktop applications, web applications, Android
4 min read
Java Programming BasicsJava is one of the most popular and widely used programming language and platform. A platform is an environment that helps to develop and run programs written in any programming language. Java is fast, reliable and secure. From desktop to web applications, scientific supercomputers to gaming console
4 min read
Java MethodsJava Methods are blocks of code that perform a specific task. A method allows us to reuse code, improving both efficiency and organization. All methods in Java must belong to a class. Methods are similar to functions and expose the behavior of objects.Example: Java program to demonstrate how to crea
7 min read
Access Modifiers in JavaIn Java, access modifiers are essential tools that define how the members of a class, like variables, methods, and even the class itself, can be accessed from other parts of our program. They are an important part of building secure and modular code when designing large applications. In this article
6 min read
Arrays in JavaIn Java, an array is an important linear data structure that allows us to store multiple values of the same type. Arrays in Java are objects, like all other objects in Java, arrays implicitly inherit from the java.lang.Object class. This allows you to invoke methods defined in Object (such as toStri
9 min read
Java StringsIn Java, a String is the type of object that can store a sequence of characters enclosed by double quotes and every character is stored in 16 bits, i.e., using UTF 16-bit encoding. A string acts the same as an array of characters. Java provides a robust and flexible API for handling strings, allowin
8 min read
Regular Expressions in JavaIn Java, Regular Expressions or Regex (in short) in Java is an API for defining String patterns that can be used for searching, manipulating, and editing a string in Java. Email validation and passwords are a few areas of strings where Regex is widely used to define the constraints. Regular Expressi
7 min read
OOPs & Interfaces
Classes and Objects in JavaIn Java, classes and objects are basic concepts of Object Oriented Programming (OOPs) that are used to represent real-world concepts and entities. A class is a template to create objects having similar properties and behavior, or in other words, we can say that a class is a blueprint for objects.An
10 min read
Java ConstructorsIn Java, constructors play an important role in object creation. A constructor is a special block of code that is called when an object is created. Its main job is to initialize the object, to set up its internal state, or to assign default values to its attributes. This process happens automaticall
10 min read
Java OOP(Object Oriented Programming) ConceptsBefore Object-Oriented Programming (OOPs), most programs used a procedural approach, where the focus was on writing step-by-step functions. This made it harder to manage and reuse code in large applications.To overcome these limitations, Object-Oriented Programming was introduced. Java is built arou
10 min read
Java PackagesPackages in Java are a mechanism that encapsulates a group of classes, sub-packages and interfaces. Packages are used for: Prevent naming conflicts by allowing classes with the same name to exist in different packages, like college.staff.cse.Employee and college.staff.ee.Employee.Make it easier to o
7 min read
Java InterfaceAn Interface in Java programming language is defined as an abstract type used to specify the behaviour of a class. An interface in Java is a blueprint of a behaviour. A Java interface contains static constants and abstract methods. Key Properties of Interface:The interface in Java is a mechanism to
11 min read
Collections
Exception Handling
Java Exception HandlingException handling in Java is an effective mechanism for managing runtime errors to ensure the application's regular flow is maintained. Some Common examples of exceptions include ClassNotFoundException, IOException, SQLException, RemoteException, etc. By handling these exceptions, Java enables deve
8 min read
Java Try Catch BlockA try-catch block in Java is a mechanism to handle exceptions. This make sure that the application continues to run even if an error occurs. The code inside the try block is executed, and if any exception occurs, it is then caught by the catch block.Example: Here, we are going to handle the Arithmet
4 min read
Java final, finally and finalizeIn Java, the keywords "final", "finally" and "finalize" have distinct roles. final enforces immutability and prevents changes to variables, methods or classes. finally ensures a block of code runs after a try-catch, regardless of exceptions. finalize is a method used for cleanup before an object is
4 min read
Chained Exceptions in JavaChained Exceptions in Java allow associating one exception with another, i.e. one exception describes the cause of another exception. For example, consider a situation in which a method throws an ArithmeticException because of an attempt to divide by zero.But the root cause of the error was an I/O f
3 min read
Null Pointer Exception in JavaA NullPointerException in Java is a RuntimeException. It occurs when a program attempts to use an object reference that has the null value. In Java, "null" is a special value that can be assigned to object references to indicate the absence of a value.Reasons for Null Pointer ExceptionA NullPointerE
5 min read
Exception Handling with Method Overriding in JavaException handling with method overriding in Java refers to the rules and behavior that apply when a subclass overrides a method from its superclass and both methods involve exceptions. It ensures that the overridden method in the subclass does not declare broader or new checked exceptions than thos
4 min read
Java Advanced
Java Multithreading TutorialThreads are the backbone of multithreading. We are living in the real world which in itself is caught on the web surrounded by lots of applications. With the advancement in technologies, we cannot achieve the speed required to run them simultaneously unless we introduce the concept of multi-tasking
15+ min read
Synchronization in JavaIn multithreading, synchronization is important to make sure multiple threads safely work on shared resources. Without synchronization, data can become inconsistent or corrupted if multiple threads access and modify shared variables at the same time. In Java, it is a mechanism that ensures that only
10 min read
File Handling in JavaIn Java, with the help of File Class, we can work with files. This File Class is inside the java.io package. The File class can be used to create an object of the class and then specifying the name of the file.Why File Handling is Required?File Handling is an integral part of any programming languag
6 min read
Java Method ReferencesIn Java, a method is a collection of statements that perform some specific task and return the result to the caller. A method reference is the shorthand syntax for a lambda expression that contains just one method call. In general, one does not have to pass arguments to method references.Why Use Met
9 min read
Java 8 Stream TutorialJava 8 introduces Stream, which is a new abstract layer, and some new additional packages in Java 8 called java.util.stream. A Stream is a sequence of components that can be processed sequentially. These packages include classes, interfaces, and enum to allow functional-style operations on the eleme
15+ min read
Java NetworkingWhen computing devices such as laptops, desktops, servers, smartphones, and tablets and an eternally-expanding arrangement of IoT gadgets such as cameras, door locks, doorbells, refrigerators, audio/visual systems, thermostats, and various sensors are sharing information and data with each other is
15+ min read
JDBC TutorialJDBC stands for Java Database Connectivity. JDBC is a Java API or tool used in Java applications to interact with the database. It is a specification from Sun Microsystems that provides APIs for Java applications to communicate with different databases. Interfaces and Classes for JDBC API comes unde
12 min read
Java Memory ManagementJava memory management is the process by which the Java Virtual Machine (JVM) automatically handles the allocation and deallocation of memory. It uses a garbage collector to reclaim memory by removing unused objects, eliminating the need for manual memory managementJVM Memory StructureJVM defines va
4 min read
Garbage Collection in JavaGarbage collection in Java is an automatic memory management process that helps Java programs run efficiently. Objects are created on the heap area. Eventually, some objects will no longer be needed.Garbage collection is an automatic process that removes unused objects from heap.Working of Garbage C
6 min read
Memory Leaks in JavaIn programming, a memory leak happens when a program keeps using memory but does not give it back when it's done. It simply means the program slowly uses more and more memory, which can make things slow and even stop working. Working of Memory Management in JavaJava has automatic garbage collection,
3 min read
Practice Java
Java Interview Questions and AnswersJava is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per
15+ min read
Java Programs - Java Programming ExamplesIn this article, we will learn and prepare for Interviews using Java Programming Examples. From basic Java programs like the Fibonacci series, Prime numbers, Factorial numbers, and Palindrome numbers to advanced Java programs.Java is one of the most popular programming languages today because of its
8 min read
Java Exercises - Basic to Advanced Java Practice Programs with SolutionsLooking for Java exercises to test your Java skills, then explore our topic-wise Java practice exercises? Here you will get 25 plus practice problems that help to upscale your Java skills. As we know Java is one of the most popular languages because of its robust and secure nature. But, programmers
7 min read
Java Quiz | Level Up Your Java SkillsThe best way to scale up your coding skills is by practicing the exercise. And if you are a Java programmer looking to test your Java skills and knowledge? Then, this Java quiz is designed to challenge your understanding of Java programming concepts and assess your excellence in the language. In thi
1 min read
Top 50 Java Project Ideas For Beginners and Advanced [Update 2025]Java is one of the most popular and versatile programming languages, known for its reliability, security, and platform independence. Developed by James Gosling in 1982, Java is widely used across industries like big data, mobile development, finance, and e-commerce.Building Java projects is an excel
15+ min read