Category: Java Interview Questions
-
What happens when the main() isn’t declared as static?
When the main method is not declared as static, then the program may be compiled correctly but ends up with a severe ambiguity and throws a run time error that reads “NoSuchMethodError.”
-
What is the final keyword in Java?
The term final is a predefined word in Java that is used while declaring values to variables. When a value is declared using the final keyword, then the variable’s value remains constant throughout the program’s execution.
-
What is an Exception?
An Exception handling in Java is considered an unexpected event that can disrupt the program’s normal flow. These events can be fixed through the process of Exception Handling.
-
Differentiate between instance and local variables.
For instance, variables are declared inside a class, and the scope of variables in javascript is limited to only a specific object. A local variable can be anywhere inside a method or a specific block of code. Also, the scope is limited to the code segment where the variable is declared.
-
Can you implement pointers in a Java Program?
Java Virtual Machine takes care of memory management implicitly. Java’s primary motto was to keep programming simple. So, accessing memory directly through pointers is not a recommended action. Hence, pointers are eliminated in Java.
-
Define package in Java.
The package is a collective bundle of classes and interfaces and the necessary libraries and JAR files. The use of packages helps in code reusability.
-
What is a singleton class in Java? And How to implement a singleton class?
A class that can possess only one object at a time is called a singleton class. To implement a singleton class given steps are to be followed:
-
Define Wrapper Classes in Java.
In Java, when you declare primitive datatypes, then Wrapper classes are responsible for converting them into objects(Reference types).
-
What is an object-oriented paradigm?
A Paradigm that is based on the concepts of “Objects.” It contains data and code. Data that is in the form of fields, and regulation, that is in the form of procedures. The exciting feature of this paradigm is that the object’s procedures can access and often modify the data fields themselves.
-
What is Object Cloning?
An ability to recreate an object entirely similar to an existing object is known as Object Cloning in Java. Java provides a clone() method to clone a current object offering the same functionality as the original object.