Java Programming – Most frequently asked questions

java


In this article we have selected java questions which are generally asked in technical interviews and technical written exams. If you have any concern regarding any question, please let us know in comments section.

For all the Java fans, Watch videos by JavaZone. They  have made awesome videos.

Questions:

Q: What is Java?
A: Java is a high level programming language which was developed by Sun Microsystems in 1995.

Q: What is the difference between JDK, JRE and JVM.
A: JDK is an acronym for Java Development Kit. It contains JRE and development tools. JRE stands for Java Runtime Environment. It is the implementation of JVM which is an acronym for Java Virtual Machine. It is an abstract machine which provides the runtime environment in which java bytecode can be executed.

Q: Why is Java ‘Write once and run anywhere’?
A: Write once and run anywhere nature of Java is because of Bytecode. Java code is compiled to bytecode which is an intermediate form of source code and machine code. This byte code is not platform or machine specific and hence can be run on any platform.

Q: What is a class?
A: A class is a blueprint from which individual objects are created. A class contains fields and methods to describe the behavior of an object.

Q: What kind of variables a class can consist of?
A: Local variable – methods defined inside methods, constructors and blocks. They are declared and initialized inside block and destroyed once block ends.
Instance variable – Variables defined in class but outside any method and are instantiated when class loads.
Class variable – Variables declared inside a class but outside any method with static keyword.

Q: What are singleton classes?
A: Classes whose only one object can be created.

Q: What is static variable?
A: Variables declared inside a class but outside any method with static keyword. These variables are used to refer the common property of all objects. Static variables get the memory once in class area at the time of loading of class.

Q: What is ‘this’ in Java?
A: ‘This’ keyword in java refers to the current object. ‘

Q: What is inheritance?
A: Inheritance is the mechanism where one object acquires the properties and behavior of another object of another class.

Q: Which class is the super class of every class?
A: Object Class.

Q: What is ‘super’?
A: ‘Super’ keyword refers to the immediate parent of current object.

Q: What is method overloading and overriding?
A: When a class have multiple methods with same name but different parameters, is known as method overloading. And if a class provides a specific implementation of a method which is already defined by its parent class, this mechanism is called method overriding.

Q: What is a final variable?
A: Variables whose value can not be changes. They are constants.

Q: What is polymorphism?
A: Polymorphism means many forms. This is the ability of an object to take many forms. Polymorphism can be seen in OOP when a parent class reference is used to refer child class object.

Q: What is abstraction?
A: Abstraction is the technique to hide complexity of code in class.

Q: What is encapsulation?
A: This is the technique of binding all the related variables and method in a class. This is the technique in which variables are made private and can only be accessed via public methods.

Q: What is an interface?
A: Interface is a collection of abstract methods. A class by implementing an interface forces itself to abide by some rules. Class or its any child class have to implement all the abstract methods define in interface.

Q: What are some data structures used in Java.
A: ArrayList, Vectors, HashMaps, LinkedList, TreeSet and HashSet. We suggest you read about these in detail.

List of questions is too large to cover in here. We have tried our best to cover most frequently asked questions. This is not the complete list. We strongly recommend you to study and prepare from some standard book, specially if Java is the primary language taught in your course.

Book:

Here is the suggestion for Java book for you.

For beginners: Programming with Java by Balagurusamy.

Advance:

Book by Head first series is also a good option.

You may be interested in :

Sharing is caring:

Leave a Reply

Your email address will not be published. Required fields are marked *