Categories
Java

23 Key Java Programming Interview Questions Asked to Beginners

Interviews are always nerve-wracking, and when you are a fresher, it terrorizes your mind even more. You are still anxious about what the interviewer will ask and whether you are adept enough to answer them confidently. When it comes to programming interviews, you are even more clueless. Well, if you are a beginner in Java, to make things easier, we are listing out some of the most common questions asked in the interview.


Java Programming Beginners - Dynamic Web Training
Click image to enlarge 

To begin with, you always dread the questions which can prop from the unknown territory. Usually, the interviewers test your grasp of the subject by twisting or remodeling the things you may know. But since you are low in confidence as it is your first time, you may quickly acquire those panic pangs which stop your brain from thinking.

You are a programmer, and you need to be efficient in handling crisis and troubleshooting. That is the quality they are looking in you rather than the knowledge. So, to make you prepare better and arm yourself with the boost of confidence, we are listing out the 23 most common, and key Java programming questions asked to beginners in an interview.

So as a JAVA fresher, make sure you have gone through these common questions. We will be dividing the topic into two parts; Basic and Theory ( Practical tests are different). Firstly in the Basic topics, we will talk about basic concepts you should know. Secondly, theory questions, these questions are above basics & you might apply them in practice. Overall, this article will cover every significant aspect of a JAVA Interview. So let’s get started.


Key Java Interview Questions

BASICS


Q1. What does JDK & JVM stand for & what’s the difference?

Ans: JDK stands for JAVA Development Kit and JVM is JAVA Virtual Machine.


JDKJVM
Includes Execution environmentDoesn’t includes execution environment
Development purposeRun-time purpose

Q2. Name the default access modifier?

Ans: There are three primary access modifiers: public, private & protected. However, there’s a default access modifier known as “FRIENDLY.” Friendly is used if no identifier is declared.


Q3. What is/are packages?

Ans: Collection of similar classes & interfaces providing protection & namespace management is called “Package”.


Q4. What is an abstract class?

Ans: Class designed with implementation gaps, subclasses fill in those gaps, such classes are known as Abstract.


Q5. What are the different states related to the thread?

Ans: States related in the thread: Running

  • Running
  • Waiting
  • Dead States

Q6. What is a deadlock?

Ans: In a situation, when two threads are waiting for each other to precede the program. It’s like 1 behind another, creating a cycle. For example, there are R1, R2, F1, and F2.

  • R1 is behind F1
  • F1 is behind R2
  • R2 is behind F2
  • F2 is behind R1

It creates a cycle where every thread is waiting for another to move. But deadlock gets created if none of them can move (because waiting for ahead one).


Q7. What is an applet?

Ans: It is an interactive & dynamic program which runs on Java-capable browsers.


Q8. Tell us about an Applet’s lifecycle?

Ans: Lifecycle of an Applet: It needs the five methods used to define its Lifecycle.

  • init() method – when an applet initially gets loaded.
  • start() method – When an applet starts. It happens after the init()method.
  • paint() method – It creates the Graphic user interface of the applet.
  • stop() method – the execution stops and blocks the applet temporarily.
  • destroy() method – It is where the lifecycle of the applet ends when the applet’s browser page is shut.

Q9. Which method is used for applets’ security?

Ans: setSecurityManager() method


Q10. Which all drivers are available in JAVA?

Ans: Drivers:

  • JDBC-ODBC Bridge Driver
  • Native API -Partly-Java Driver
  • JDBC- NET- Pure Java Driver
  • Native-Protocol – Pure Java Driver

Q11. Why there’s no global variable in Java?

Ans: Variables which are accessible throughout the program/code are known as Global variable. Java doesn’t support global variable because of global variables:

  • Creates collisions in namespace
  • Breaks the referential transparency

Q12. What is RMI & Java Bean?

Ans: RMI or Remote Method Invocation is an API that allows & provides a mechanism for the creation of distributed applications in JAVA. Meanwhile, Java Bean is a component of java that can be reused in different software environments.


THEORY QUESTIONS


Q13. List the three main object-oriented programming concepts.

Ans: 3 Main concepts of Object Oriented Programming are as follows:

  • Encapsulation
  • Inheritance
  • Polymorphism

Encapsulation:
Encapsulation means encapsulating something. Developers can hide implementation using encapsulation. The major two features of encapsulation are; variables are protected, getter & setter method give instance variables. setName() & getName() are access points.


Inheritance:
As the name suggests, this concept allows a class to be a subclass of a superclass. In simple words objects or values can be inherited/called from another class. Inheritance is the core for polymorphism, overloading, overriding & casting.


Polymorphism:
Poly means many & morphism means forms. Thus, polymorphism means many forms. In simple words, one concept/statement having many forms but of the same type. For example, Ronaldo is not in Real Madrid, we can write it as; Real Madrid doesn’t have Ronaldo, Real Madrid no more has Ronaldo, etc. So here, the meaning remains the same, but the form changes.


Q14. What is Polymorphism? What are its features?

Ans: Poly means many & morphism implies form. Hence, polymorphism is one name but many forms. Features of Polymorphism are as follows:

  • Overriding: Method which has the same name, same return type & same formal argument
  • Overloading: Same name but different formal argument/parameters (in C)
  • Use of 1 interface for multiple implementations

Q15. What does Garbage Collection mean?

Ans: Garbage collection is a way to free memory in Java. It cleans objects which are no longer in use or reference & frees the memory for further programming. Steps are as follows:


Garbage Object Collection: Firstly, objects which aren’t useful are collected & grouped accordingly.


Run Finalize method: Java runs the Finalize method to free up space and clean those objects.


Q16. How are this() & super() used with constructors?

Ans: Constructors are blocks that are called when at an instance an object is created to initialize it. A constructor is not a method because it doesn’t have any return type.

this() Constructors:
  • Used with variables & methods
  • Used to call the constructor of the same class
  • Used to point the current class
  • We cannot access private variables using this()
super() Constructors:
  • We can call the constructor of the parent class
  • We can access private variables using super()
  • This constructor needs to be the first statement in the body

Q17. What is user defined Exceptions?

Ans: Exceptions are the unexpected or unwanted events/objects which might occur during the execution. These exceptions interfere the flow of program instructions & output might vary. User-defined exceptions are exceptions defined by the user. We can define exceptions, but there are two things to keep in mind:

  • Use to string() method (display information)
  • Should be extended from the exception class

Q18. What does List interface means & what are its main implementation?

Ans: List is used to make a collection of objects. It preserves the insertion order & allows positional access accompanied by element insertion. List interface is implemented using ArrayList, Vector & LinkedList.

  • ArrayList: Resize array
  • LinkedList: Double-linked list implementation
  • Vector: Synchronized resizable array

Q19. List/Explain life cycle of a thread.

Ans: Thread is the context of the path followed by the program during execution. Java programs get executed according to the sequence & commands in the thread. The life cycle of threads is as follows:

  • Newborn State
  • Runnable State
  • Running State
  • Blocked State
  • Dead State

Q20. What is a TreeSet & HashSet?

Ans:

TreeSet:

  • Set implemented if we want elements arranged in a sorted way
  • Sorting is done using comparator or according to natural order of element.

HashSet:

  • Set which are unsorted or unordered
  • Sorting is done using a comparator or according to the natural order of the element.
  • Uses Hash code
  • Set interface implementation
  • Extends AbstractSet

Q21. How can you decide whether to use HashMap or TreeMap? State their major difference.

Ans: We use HashMap if we want to insert, delete or locate elements in a Map.

We use TreeMap if we traverse the element in sorted order. Adding elements in HashMap is easy.

HashMap:

  • It is unordered or unsorted
  • Unsynchronized
  • Allows us to have null values

HashTable:

  • Doesn’t allows null values
  • Not Synchronized
  • Sorted

Q22. When to use abstract classes & interfaces?

Ans: Java Abstract Classes can implement interfaces. It might not even provide the implementation of interface methods. It is used to give a standard method to all subclasses.


Interface:
When we need to provide a superclass from which other classes can take or inherit. Meanwhile, share the common design
When available abstract implementation doesn’t perform what you want & you need to create your own


Abstract:
Want to share code among several classes
You expect that classes that extend abstract class have numerous common methods or fields, or require get to modifiers other than public, (for example, private and protected).
Need to declare non-static or non-last fields. It allows you to characterize methods that can get to and adjust the state of the object where they belong.


Q23. What is the difference between throw & throws?

Ans:

  • Throw keyword is used to throw an exception. Meanwhile, Throws is for declaring an exception.
  • Throws works like the try-catch block.
  • An instance of exception class precedes Throw in Syntax.
  • Throws is preceded/followed by exception class name.

Few more questions:

  • What is the difference between scheduling, preemptive & time slicing?
  • Explain traversing through collector using Iterator
  • How JAVA becomes Object Oriented?
  • How JAVA becomes Robust?
  • What is ‘public static void main’ signifies?
  • What does ‘System.out.println()’ signifies?
  • What is comparable Interface?
  • What are HashMap, ConcurrentHashMap, and SynchronizedMap?
  • What is Semaphore and Mutex in Java? Provide detailed explanation related to MultiThreading
  • What is JSON and How to read a JSON object from a file?
  • What are Heapsize, Stacksize & Garbage Collection?
  • Are you aware of Daemon Thread in Java?
  • What is Singleton Pattern and Do you know how to make it Thread-Safe and Fast?

Conclusion:

These were few commonly asked JAVA Programming interview questions. Interviewers don’t tend to ask advance practical questions which are long as they consume time. They want an interview to be short, but the time-span should be enough to judge you. So they would check your basics, then a bit of theory.


You must know the answers to the questions we listed above. So, have a look at these questions or take it as a revision part.


Our courses on Java cover the subjects extensively for you to excel in your career.

Avatar for Dynamic Web Training
By Dynamic Web Training

Dynamic Web Training is Australia's leading provider of instructor led software training.

We offer training courses in Adobe, Web Design, Graphic Design, Photoshop, InDesign, Dreamweaver and many more.