- Java Blogs -

Java Interview Questions and Answers for Experienced, Fresher Developer

Java Interview Questions and Answers

Somebody has appropriately said that interviews are more unpleasant than the course itself is. Ordinarily, we simply wish that we don't need to do that whole one on one session. Try not to stress, we are here to scoop you out of the pressure that you may experience for your interview identified with Java Developed. We have gathered an article for you that will enable you to nail your meeting like an ace. In this specially designed Java Interview Questions blog, we are going to let you know some of the most important Java Interview Questions and Answers that will definitely give you an edge and set you class apart in the interview process. Every single IT company, big or small requires Java developer. Java Influences everything, starting from Android to the ecosystems of Hadoop. The career in Java is very promising; the individuals working in this sector have reported that an average yearly remuneration of $50,000 is likely to be received by a fresher.

Java Interview Questions

  1. Explain what is Java?
  2. Explain the meaning of static in Java?
  3. Why is Java perceived to be platform independent?
  4. Why is JAVA not 100% object-oriented?
  5. Explain constructors in JAVA?
  6. How many types of constructors are there in JAVA?
  7. What is singleton class and how can we make a class singleton?
  8. Is it possible to override a private or a static method in Java?
  9. What do you mean by association?
  10. Explain the concept of aggregation in JAVA?
  11. What is a servlet?
  12. What do you understand by Request Dispatcher?
  13. Is it possible to generate array volatile in Java?
  14. Explain the concept of interfaces in JAVA?
  15. What are real-world practices of volatile modifier?
  16. Explain the meaning of thread local variable in Java?
  17. Explain the meaning of platform?
  18. What’s the variance amid an Abstract Class and Interface in Java?
  19. What is the variance amid an Inner Class and a Sub-Class?
  20. Can we affirm a class as Abstract deprived of having an abstract method?
  21. Can volatile generate a non-atomic process to atomic?
  22. Explain wait-notify code for the producer-consumer situation?
  23. Explain thread-safe code Singleton in Java?
  24. What are the performance inferences of Interfaces over abstract classes?
  25. Explain reason that why is a compile-time persistent in Java? What is the risk of using it?
  26. Why Java does not accompaniment manifold inheritances?

Java Interview Questions And Answers

For the person looking forward to attending a JAVA interview soon, here is a list of some of the most popular interview questions and answers which will help you in the right way. Here, we have included the top most frequently asked questions along with relevant answers to help out freshers and the experienced professionals appropriately.

Java Interview questions and answers for Freshers

Q1). Explain that what is Java?

Java is an object programming language that was premeditated to moveable across several platforms and operating structures. This language was developed by Sun Microsystems. Java is exhibited after the C++ programming language and comprises special structures that make it perfect for programs on the Internet.

Q2). Explain the meaning of static in Java?

  • Static stands for one per class, not one for every object no matter how various instance of a class might occur. This entails that you can use them deprived of generating an instance of a class.
  • Static methods are indirectly final since overriding is done grounded on the type of the object and static approaches are involved to a class, not an object.
  • A static technique in a superclass can be followed by an alternative static method in a subclass if the unique method was not acknowledged final.
  • Though, you can’t overrule a static technique with a non-static technique. In other words, you can’t do modification in a static technique into an illustration method of a subclass.

Q3). Why is Java perceived to be platform independent?

This is because platform independent is the term that means “write once run anywhere”. Java is referred to because of its bytecodes that have the capacity to run on any system or device whatsoever irrespective of the underlying operating system.

Q4). Why is JAVA not 100% object-oriented?

Java is not cent percent object-oriented because it utilizes eight types of primitive datatypes named as boolean, byte, char, int, float, double, long, short which are not objects.

Q5). Explain constructors in JAVA?

In Java framework, the constructor is the term that refers to a block of code which is usually used to initiate an object. It should have the same name as that of its class.

Q6). How many types of constructors are there in JAVA? 

There are two types of constructors in JAVA:

  • Default constructor
  • Parameterized constructor

Q7). What is singleton class and how can we make a class singleton?

Singleton class is a class whose only one instance can be created at any given time, in one JVM. A class can be made singleton by making its constructor private.

Read: How to Start a Career as a Java Developer or Programmer

Q8). Is it possible to override a private or a static method in Java?

No, there is no provision to override a private or static method in Java. However, you can use method hiding approach in extraordinary cases.

Q9). What do you mean by association?

Association refers to a relationship where all the object of the class have got their own lifecycle and there is no owner as such. These relationships or associations as we call them can be one to one or one to many or many to one or many to many.

Q10). Explain the concept of aggregation in JAVA?

Aggregation is a concept in JAVA for a specialized form of Association where all the objects have got their own lifecycle but there is an ownership and the child object cannot belongs to another parent object in any manner.

JAVA Interview questions and answers for Experienced

Q11). What is a servlet?

In JAVA atmosphere a Java Servlet is a server-side technology used to extend the capability of the web servers by providing support for dynamic response and data persistence.

Q12). What do you understand by Request Dispatcher?

Request Dispatcher interface in JAVA is used to forward the request to another resource which can be HTML, JSP or any another servlet within the same application.

There are two methods defined in this interface:

  • void forward()
  • void include()

Q13). Is it possible to generate array volatile in Java?

Yes, you can generate an array volatile in Java but then again only the situation which is directing to an array, not the entire array. This means that, if one thread deviates the reference variable to directs to the extra array, that will offer a volatile assurance, but if multiple threads are altering separate array elements they won’t be having ensues before assurance offered by the volatile modifier.

Q14). Explain the concept of interfaces in JAVA?

Interfaces are gentler in performance as likened to abstract classes as additional indirections are compulsory for interfaces. Additional key factor for designers to take into deliberation is that any class can spread only one abstract class through a class can implement numerous interfaces. Use of lines also places an additional burden on the developers at any time an interface is executed in a class; the developer is required to contrivance each and every technique of interface.

Read: What Is The Process To Run A Java Program In CMD?

Q15). What are real-world practices of volatile modifier?

One of the real-world use of the volatile variable is to generate interpretation double and long atomic. Equally double and long are 64-bit extensive and they are reciting in two parts, primary 32-bit first time and following 32-bit another time, which is non-atomic but then again volatile double in addition long read is atomic in Java. Additional use of the volatile variable is to deliver a recall barrier, just like it is cast-off in Disrupter framework. Fundamentally, Java Memory model pull-outs a write barrier subsequently you write to a volatile variable besides a read barrier beforehand you read it. That means, if you inscribe to volatile field then it’s definite that any thread retrieving that variable will see the worth you wrote and everything you did beforehand doing that correct into the thread is certain to have occurred and any rationalized data values will also be noticeable to all threads, since the memory barrier flushed all additional writes to the cache.

Q16). Explain the meaning of thread local variable in Java?

Thread-local variables are variables limited to a thread, it’s like thread’s individual copy which is not public between numerous threads. Java offers a Thread Local class to care thread-local variables. It’s one of the numerous ways to attain thread-safety. Though be cautious while using thread locally adjustable in managed environment e.g. with network servers where operative thread out lives somewhat application variable. Somewhat thread local variable which is not detached once its work is done can possibly reason a memory leak in Java application.

Q17). Explain the meaning of platform?

A platform is the hardware or software setting in which a program executes. Maximum platforms in JAVA can be defined as a grouping of the operating system and hardware, Windows 2000/XP, Linux, Windows 2000/XP, MacOs and Solaris.

Q18). What’s the variance amid an Abstract Class and Interface in Java?

The main difference amid an abstract class and interface is that a boundary cans only own assertion of public static approaches with no existing application while an abstract class can have associated with any admittance specifies (i.e. public, private etc.) with or without real implementation. Additional key variance in the usage of abstract classes and lines is that a class which gears an interface must contrivance all the approaches of the interface while a class which receives from an abstract class doesn’t need execution of all the methods of its superclass. A class can instrument numerous interfaces but it can spread only one abstract class.

Q19). What is the variance amid an Inner Class and a Sub-Class?

An Inner class is a class which is copied up to the additional class. An Inner class has admittance privileges for the class which is nesting it and it can contact all variables and system well-defined in the outer class, whereas a sub-class is a class which receives from another class named Superclass. Sub-class can contact all public and protected approaches and fields of its superclass.

Q20). Can we affirm a class as Abstract deprived of having an abstract method?

Yes, we can generate an abstract class via abstract keyword beforehand class name even if it doesn’t have any abstract method. Though, if a class has even one abstract technique, it must be acknowledged as abstract or else it will give an error.

Q21). Can volatile generate a non-atomic process to atomic?

This additional good question I prefer to ask on volatile, typically as a follow-up of the preceding question. This query is also not simple to response since volatile is not about atomicity, but there are situations where you can practice a volatile flexible to make the operation atomic. One instance I have seen is having a long arena in your class. If you distinguish that a long field is retrieved by extra than one thread e.g. an application, a value field or everything, you well make it volatile. Why? since reading to an extended variable is not atomic in Java and done in double steps, if one thread is lettering or apprising long value, it’s probably for the additional thread to see half value (fist 32-bit). While interpretation/writing a volatile long or dual (64 bit) is atomic.

Q22). Explain wait-notify code for the producer-consumer situation?

Please understand the response for a code example. Just recollect to call wait () and inform () technique from the coordinated block and test waiting for ailment on the loop as an alternative of if block.

Read: What is Inheritance in Java? Different Types of Inheritance in Java

Q23). Explain thread-safe code Singleton in Java?

Please understand the answer for a code instance and stage by stage guide to generating thread-safe singleton code in Java. As soon as we say thread-safe, which means Singleton should continue singleton even if low-level formatting occurs in the case of numerous threads. Using Java enum as Singleton class is one of the simplest ways to generate a thread-safe singleton in Java.

Q24). What are the performance inferences of Interfaces over abstract classes?

Interfaces are gentler in performance as likened to abstract classes as additional indirections are compulsory for interfaces. Additional key factor for designers to take into deliberation is that any class can spread only one abstract class through a class can implement numerous interfaces. Use of lines also places an additional burden on the developers at any time an interface is executed in a class; the developer is required to contrivance each and every technique of interface.

Q25). Explain reason that why is a compile-time persistent in Java? What is the risk of using it?

Public static ultimate variables are also recognized as a compile-time endless, the public is non-compulsory there. They are swapped with definite values at compile time since compiler distinguishes their value up-front and also distinguishes that it cannot be changed throughout run-time. One of the problematic with this is that if you ensued to use a public stationary final variable from some in-house or third-party library and their worth changed advanced than your client will still be using old value even after you organize a new version of JARs. To evade that, make certain you compile your program when your elevation dependence JAR files.

Q26). Why Java does not accompaniment manifold inheritances?

Java development team hit to make Java as

  • Unpretentious, object-oriented and acquainted
  • Vigorous and secure
  • Architecture unbiased and transferrable
  • Extreme performance
  • Understood, threaded and lively
  • The details for overlooking Multiple Inheritance from the Java Language regularly stem from the unassuming, object-oriented and acquainted goal.

You May like:

    Janbask Training

    JanBask Training is a leading Global Online Training Provider through Live Sessions. The Live classes provide a blended approach of hands on experience along with theoretical knowledge which is driven by certified professionals.


Trending Courses

AWS

  • AWS & Fundamentals of Linux
  • Amazon Simple Storage Service
  • Elastic Compute Cloud
  • Databases Overview & Amazon Route 53

Upcoming Class

3 days 22 Oct 2019

DevOps

  • Intro to DevOps
  • GIT and Maven
  • Jenkins & Ansible
  • Docker and Cloud Computing

Upcoming Class

7 days 26 Oct 2019

Data Science

  • Data Science Introduction
  • Hadoop and Spark Overview
  • Python & Intro to R Programming
  • Machine Learning

Upcoming Class

7 days 26 Oct 2019

Hadoop

  • Architecture, HDFS & MapReduce
  • Unix Shell & Apache Pig Installation
  • HIVE Installation & User-Defined Functions
  • SQOOP & Hbase Installation

Upcoming Class

8 days 27 Oct 2019

Salesforce

  • Salesforce Configuration Introduction
  • Security & Automation Process
  • Sales & Service Cloud
  • Apex Programming, SOQL & SOSL

Upcoming Class

6 days 25 Oct 2019

QA

  • Introduction and Software Testing
  • Software Test Life Cycle
  • Automation Testing and API Testing
  • Setup Selenium for UI Automation

Upcoming Class

15 days 03 Nov 2019

Business Analyst

  • BA & Stakeholders Overview
  • BPMN, Requirement Elicitation
  • BA Tools & Design Documents
  • Enterprise Analysis, Agile & Scrum

Upcoming Class

5 days 24 Oct 2019

SQL Server

  • Introduction & Database Query
  • Programming, Indexes & System Functions
  • SSIS Package Development Procedures
  • SSRS Report Design

Upcoming Class

10 days 29 Oct 2019

Comments

Search Posts

Reset

Receive Latest Materials and Offers on Java Course

Interviews