Indium – Java Interview Questions
Here is the list Java Interview Questions which are recently asked in Indium company. These questions are included for both Freshers and Experienced professionals.
1. What is the difference between an Inner Class and a Sub-Class?
There are big differences between inner classes and subclasses: inner classes are in the same file, whereas subclasses can be in another file, maybe in another package.
2. What are the various access specifiers for Java classes?
Java provides four types of access modifiers or visibility specifiers i.e. default, public, private, and protected. The default modifier does not have any keyword associated with it.
3. What's the purpose of Static methods and static variables?
Static variables are used with the class name and the dot operator, since they are associated with a class, not objects of a class. Static methods cannot access or change the values of instance variables, but they can access or change the values of static variables and cannot call non-static methods.
4. What is data encapsulation and what's its significance?
Data encapsulation is the mechanism whereby the implementation details of a class are kept hidden from the user. The user can only perform a restricted set of operations on the hidden members of the class by executing special functions commonly called methods.
5. What are Loops in Java? What are three types of loops?
In Java, there are three kinds of loops which are – the for loop, the while loop, and the do-while loop. All these three loop constructs of Java executes a set of repeated statements as long as a specified condition remains true. This particular condition is generally known as loop control.
6. What is an infinite Loop? How infinite loop is declared?
An infinite loop is a piece of coding that lacks a functional exit so that it repeats indefinitely. A loop is a sequence of instruction s that is continually repeated until a certain condition is reached. An infinite loop occurs when a condition always evaluates to true. Usually, this is an error.
7. What is the difference between continue and break statement?
The break statement is used to terminate the loop immediately. Break keyword is used to indicate break statements. The continue statement is used to skip the current iteration of the loop. Continue keyword is used to indicate continue statement.
Free PDF : Get our updated Java Course Content pdf
8. What is Final Keyword in Java? Give an example.
A final class cannot be extended (inherited). There are two uses of a final class : One is definitely to prevent inheritance, as final classes cannot be extended. For example, all Wrapper Classes like Integer, Float etc.
9. How can you generate random numbers in Java?
- Import the class java.util.Random.
- Make the instance of the class Random, i.e., Random rand = new Random()
- Invoke one of the following methods of rand object: nextInt(upperbound) generates random numbers in the range 0 to upperbound-1.
10. Can main() method in Java can return any data?
Java main method does not return anything that is why its return type is void. If we try to return anything from main method, it will give an unexpected value error because it is predefined signature in JVM.
11. How an object is serialized in java?
To serialize an object means to convert its state to a byte stream so that the byte stream can be reverted back into a copy of the object. Serialization allows to convert the state of an object into a byte stream, which then can be saved into a file on the local disk or sent over the network to any other machine.
12. Can we have any other return type than void for main method?
No, the main method in Java cannot have any return type other than void because the language specification (rules) doesn't allow it.
13. How objects are stored in Java?
In Java, all objects are dynamically allocated on Heap. When we only declare a variable of a class type, only a reference is created. To allocate memory to an object, we must use new (). So the object is always allocated memory on heap (See this for more details).
14. What's the base class of all exception classes?
All exception and errors types are sub classes of class Throw able, which is base class of hierarchy.
Get Answer for all the above questions and place in your dream company
TOP MNC JAVA INTERVIEWWants to Become an Expert
in Java?
Know MoreTOP MNC's JAVA INTERVIEW QUESTIONS & ANSWERS
Wants to Become an Expert
in Java?
Know MoreHere we listed all Java Interview Questions and Answers which are asked in Top MNCs. Periodically we update this page with recently asked Questions, please do visit our page often and be updated in Java.
QUESTIONS