Java Object-Oriented Programming is a powerful way to approach the task of programming. OOPs refers to languages that use objects in programming. if you want to crack Java interview, need some Java basic interview questions with answers. You are on right place. In this article, we cover all the popular java interview questions.
Basic java interview Questions and answers.
1. What is java?
Answer: Java is an object-oriented, High -level, general-purpose programming language originally designed by James Gosling and further developed by the Oracle Corporation. It is one of the most popular programming language in the world.
2. Why is Java a platform independent language?
Answer: Java is a programming language that is not depend on any hardware or software due to fact that the compiler compiles the code and then converts it to platform-independent byte code. Which can run on multiple systems.
Note: The only condition to run that byte code is for the machine to have a runtime environment (JRE) installed in it.
3. Why java is not pure “object-oriented programming language”?
Answer: Java supports primitive data types Such as byte, boolean, char, short, int, float, long, and double. Hence Java is, not a pure object-oriented language.
4. Explain about Java virtual machine.
Answer: JVM is the program that interprets the intermediate Java Byte code and generates the desired output. It is because of byte code and JVM that program written in Java are highly portable.
5. Why dose the java not use Pointer?
Answer: Pointers quite complicated for beginner programmers. Java focuses on simple and easy code. But the usage of pointers can make it challenging. Pointer utilization can also cause potential errors. It also unsafe to use. Moreover, the usage of pointers can make the procedure of garbage collection quite slow and erroneous. Java makes use of references as these which you cannot manipulated, unlike pointers.
6. What is an object?
Answer: An instance of a Java class known as an object. Two important think of a Java object are behavior and the sate. An object is created as soon as the JVM comes across the new keyword.
7. What do you mean by data encapsulation?
Answer: Encapsulation is a mechanism of binding the data and methods that operate on them together in a single unit called class. It keeps the data safe from any external interference and misuse. It is a way to install data abstraction. Encapsulation provides services to the external function or other objects that interact with it. But, these external functions or objects do not need to know their internal detail.
8.Tell us something about JIT compiler.
Answer: JIT is stands for Just-In-Time. JIT complier runs after the program is executed and compiles the code into a faster for, hosting CPU’s native instructing set. JIT can access dynamic runtime information. Whereas a standard compiler doesn’t and can make better optimization like inlining functions. That we use frequently.
9. How JIT works?
Answer: The compiler is nothing but a translator of source code to machine-executable code. But what is special about the JIT compiler? Let us see how it works:
1. First, the Java source code (.java) conversion to byte code (.class) occurs with the help of the javac compiler.
2. Then, the .class files loaded at run time by JVM and with the help of an interpreter. These are converted to machine understandable code.
3. JIT compiler is a part of JVM. When the JIT compiler is enabled, the JVM analyzes the method calls in the .class files and compiles them to get more efficient and native code. It also ensures that the prioritized method calls are optimized.
4. Once the above step is done, the JVM executes the optimized code directly instead of interpreting the code again. This increases the performance and speed of the execution.
10. What is an events in java?
Answer: In java, an event is an object which specifies the change of state in the source. It occurs whenever an action takes place. For example, clicking on a button, moving the mouse so on.
11. Types of java events?
Answer: There are two types of events.
Foreground Events – Those events require the direct interaction of the user. They are generated as consequences of a person interacting with the graphical components in Graphical User Interface. For example
1.Clicking on a button
2.Moving the mouse
3.Entering a character through the keyboard
4.Selecting an item from the list
5.Scrolling the page, etc.
Background Events – Those events that require the interaction of the end-user are known as background events. Operating system interrupts, hardware or software failure, the timer expires, an operation completion is the example of background events.
11. Explain Typecasting?
Answer: The concept of assigning a variable of one data type to a variable of another data type. It is not possible for the boolean data type.
It is of two types.
12. Explain the use of final keyword in variable, method and class.
Answer: In Java, the final keyword, used as defining something as constant /final and represents the non-access modifier.
When we declare a variable as final in Java. Then we can’t modified the value once it assigned.
If any value has not been assigned to that variable, then it can be assigned only by the constructor of the class.
When the method declared as final. We cannot be overridden by its children’s classes.
A constructor cannot be marked as final because whenever a class is inherited, the constructors are not inherited. Hence, marking it final doesn’t make sense. Java throws compilation error saying –
modifier final not allowed here
No classes can be inherited from the class declared as final. But that final class can extend other classes for its usage
13. What is Event Handling?
Answer: To handle the generated events, Java provides us several classes and interfaces. It controls the events and decides what should happen if an event occurs.
Event handling steps
|1||The user click the button and event generates.|
|2||Now the object of the concerned event class is created automatically. And information about the source and the events get to populate within the same object|
|3||Event object forwards to the method of registered listener class.|
|4||The method is now get executed and returns.|
14. What are the default for local variable?
Answer: The local variables are not initialized to any default value, neither primitives nor object references.
15. Java is a platform-independent language. Why?
Answer: Java programing language does not depend on any particular hardware or software. Because it compiled by the compiler. And then converted into byte code is platform independent and can run on multiple systems. The only requirement is java needs a runtime environment, i.e. JRE, which is a set of tools that we for developing java application.
Hope you enjoy these java basic interview question and answer. if you have any query regarding this you can ask in comment section.
how to compile and execute java program
How are java objects stored in memory?
what is abstract class in java?
1 thought on “Java Basic interview questions and answers for freshers .”
NICE ARTICLE VERY INFORMATIVE