Oracle – Java Interview Questions
Here is the list Java Interview Questions which are recently asked in Oracle company. These questions are included for both Freshers and Experienced professionals.
1. Can you explain the thread lifecycle in Java?
The life cycle of the thread in java is controlled by Java virtual machine. The java thread states are as follows:- New
- Runnable
- Running
- Non-Runnable (Blocked)
- Terminated
2. What do you know about Interface in Java?
The interface in Java is a mechanism to achieve abstraction. There can be only abstract methods in the Java interface, not method body. It is used to achieve abstraction and multiple inheritance.
3. How do you make a thread stop in Java?
Modern ways to suspend/stop a thread are by using a boolean flag and Thread. interrupt () method. We can define a boolean variable which is used for stopping/killing threads say 'exit' using a boolean flag. Whenever we want to stop a thread, the 'exit' variable will be set to true.
4. What purpose do the Volatile variable serve in Java?
Volatile keyword is used to modify the value of a variable by different threads and used to make classes thread safe. It means that multiple threads can use a method and instance of the classes at the same time without any problem.
5. Please compare Serialization with Deserialization in Java.
Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory. So, the object serialized on one platform can be deserialized on a different platform.
6. What do you understand by OutOfMemoryError in Java?
OutOfMemoryError is a runtime error which occurs when the Java Virtual Machine is unable to allocate an object due to insufficient space in the Java heap. The Java Garbage Collector cannot free up the space required for a new object.
7. Is Java platform independent?
Java is platform-independent because it does not depend on any type of platform.Programs are compiled into byte code and that byte code is platform-independent. Hence, Java is platform-independent language.
8. What all memory areas are allocated by JVM?
Memory allocation in java refers to the process where the computer programs and services are allocated dedicated to virtual memory spaces. The memory in the JVM divided into 5 different parts:- Class Area.
- Heap.
- Stack.
- Program Counter Register.
- Native Method Stack.
9. Java vs. C ++?
C++ is derived from C and has the features of both procedural and object-oriented programming languages. C++ was designed for application and System development.
Java is built upon a virtual machine which is very secure and highly portable in nature. It is grouped with a comprehensive library to provide support for the abstraction of the existing platform.
10. Explain public static void main(String args[])
public static void main(String[] args) Java main method is the entry point of any java program. Its syntax is always public static void main(String[] args) . You can only change the name of String array argument, for example you can change args to myStringArgs.
Free PDF : Get our updated Java Course Content pdf
11. What is javac ?
The javac command reads source files that contain module, package and type declarations written in the Java programming language, and compiles them into class files that run on the Java Virtual Machine. The javac command can also process annotations in Java source files and classes.
12. What is class?
Java provides a class with name Class in java. lang package. Instances of the class Class represent classes and interfaces in a running Java application. The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects.
13. What is the base class of all classes?
lang. Object class is the root or superclass of the class hierarchy, which is present in java.
14. What is a wrapper class in Java?
A Wrapper class in Java is the type of class that provides a mechanism to convert the primitive data types into the objects and vice-versa. When a wrapper class is created, there is a creation of a new field in which we store the primitive data types.
15. Different Data types in Java.
- Primitive data types - includes byte , short , int , long , float , double , boolean and char.
- Non-primitive data types - such as String, Arrays and Classes (you will learn more about these in a later chapter)
16. What is Type casting in Java?
Type Casting is a feature in Java using which the form or type of a variable or object is cast into some other kind or Object, and the process of conversion from one type to another is called Type Casting.
17. What is an Array?
An array is a group of like-typed variables that are referred to by a common name. Arrays in Java work differently than they do in C/C++.Each item of an array is an element. All the elements in an array must be of the same type.
18. Does Java support Multiple Inheritance?
Java does not support multiple inheritance using classes. “A class can extend only one class but it can implement multiple interfaces.” For example, below inheritance using multiple classes is wrong as two classes cannot be extended or inherited.
19. What is Polymorphism and what are the types of it?
The word "poly" means many and "morphs" means forms. So polymorphism means many forms.Polymorphism is a feature of OOPs that allows the object to behave differently in different conditions There are two types of polymorphism in Java: compile-time polymorphism and runtime polymorphism.
20. What is method overriding in Java?
In any object-oriented programming language, Overriding is a feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super-classes or parent classes.
Get Answer for all the above questions and place in your dream company
Wants to Become an Expert
in Java?
Know MoreTOP MNC's JAVA INTERVIEW QUESTIONS & ANSWERS
Here 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.