Skip to main content

Basic Java Interview Questions and Answers






Most Frequently asked Interview Questions and Answar in Java:

           In this Java Interview Question blog, we have covered almost 25+ important core Java interview questions and answar for freshers and experienced candidates.
            This post on JAVA Interview Questions and Answars is prepared to help you understand the basic concepts of Java programming for top compnyes interview purposes. All the most important JAVA concepts are explained here with examples for your easy understanding. Like diffrence between and details about JDK, JRE, JVM or some bacis which you know before going and interview.
             This blog covers core JAVA topics, advance java topics and also industry level project related most important Interview Questions with examples to make you get ready perfectly to face any JAVA interview confidently.

basic Java Interview Question and Answer,
OOPs concepts Interview Question and Answer,
Collections Interview Question and Answer,
Exception Handling Interview Question and Answer,
Multi-threading Interview Question and Answer,
Serialization and Deserialization Interview Question and Answer,
Keywords Interview Questions and Answer --------- Static keyword and Final Keyword



Most Popular Java Interview Questions:

          Given below is a comprehensive list of most important and commonly asked basic and advanced Java programming interview questions with detailed answers.



1. What is the difference between JDK and JRE?

                 JDK stands for Java Development Kit. It contains the tools or libraries for development of Java programs. It also contain compilers and debuggers needed to compile Java program, JRE stands for Java Runtime Environment. This is included in JDK. JRE provide libraries and  Java Virtual Machine ( JVM ) that is required to run a Java program.


2. What is Java Virtual Machine (JVM) explain?

               Java Virtual Machine ( JVM )  is an abstract machine that executes Java Byte code. There are different  Java Virtual Machine ( JVM ) use for different hardware and software platforms. So  Java Virtual Machine ( JVM ) is platform dependent.  Java Virtual Machine ( JVM ) is responsible for loading, verifying and executing the Byte code on a platform.



3. What are the different type of memory areas allocated by JVM?

                   In java,  Java Virtual Machine ( JVM ) allocate memory to different processes, methods and objects. Some of the memory areas allocated by JVM are:
1. ClassLoader: It is a component of JVM used to load the class files. 
2. Class (Method) Area: It stores per-class structures such as the runtime constant pool, field, method data, and the code for methods. 
3. Heap: Heap is created at runtime and it contains the runtime data area in which objects are allocated. 
4. Stack: Stack store local variables and partial results at runtime. It also helps in method invocation and return value. Each thread creates a private JVM stack at the same time of thread creation. 
5. Program Counter Register: This memory area contain the address of the Java virtual machine instruction that is currently being executed. 
6. Native Method Stack: This area is reserved for all the native methods used in the java application.



4. What is JIT compiler?

              Just In Time compiler also known  JIT compiler is used for performance improvement in Java. It is enabled by default. It is compilation done at execution time rather than earlier. Java has popularized after the use of JIT compiler by including it in JVM.


5. How Java platform is different from other platforms?

         Java is a platform independent language. Java compiler convert Java code in to byte code that can be interpreted by JVM. There are JVM written for almost all the popular hardware and platforms in the world. 
          Java byte code can run on any platform in same way. Where as other languages require libraries compiled for a specific platform to run code.


6. Why people say that Java is 'write once and run anywhere' type language?

          You can write Java code on Windows and compile in Windows platform. The class and jar files that you get from Windows platform and you can run on Unix environment also. So it is a truly platform independent language.
          Behind all this portability is Java byte code. Byte code generated by Java compiler can be interpreted with any JVM. So it becomes much easier to write program in Java and expect those to run on any platform. Java compiler javac compiles java code and JVM runs that code.



7. How does ClassLoader work in Java?

              In Java, ClassLoader is a class that is used to load class files in JVM. ClassLoader loads files from their physical file locations e.g. Filesystem, Network location etc. There are three main types of ClassLoaders in Java.
1. Bootstrap ClassLoader: This is the first ClassLoader. It loads classes from rt.jar file.  
2. Extension ClassLoader: It loads class files from jre/lib/ext location. 
3. Application ClassLoader: This ClassLoader depends on CLASSPATH to find location of the class files. If you specify your jar in CLASSPATH, then this ClassLoader will load them.

8. Do you think ‘main’ used for main method is a keyword in Java?

                 No, main is just a name of method. There can be multiple methods with same name main in a class file. It is not a keyword in Java.


9. Can we write main method like public void static instead of public static void?

              No, you cannot write it like this. Any method has to first specify the modifier and then the return value. Only we can change modifiers order. We can write static public void main() instead of public static void main() in java.


10.In Java, if we do not specify any value for local variables, then what will be the default value of local variables?

              Java does not initialize local variables with any default value. So these variables will be just null by default.


11. Let say, we run a class without passing any arguments. What will be the value of String array of arguments in Main method in java?

              By default, the value of String array of arguments is empty. It is not null.


12.What is the difference between a byte and a char data types in Java?

          Both byte and char are numeric data types in Java. They are used to represent numbers in a specific range. Major difference between them is that a byte can store raw binary data and a char stores characters or text data. Usage of char is E.g. char ch = ‘x’; Byte values range from -128 to 127. A byte is made of 8 bits. But a char is made of 16 bits. So it is equivalent to 2 bytes.









Comments

Azure DevOps said…
Informative post, thanks for sharing.
AWS Online Training

Popular posts from this blog

DOCKER Interview questions

DOCKER 1. What is Docker? Docker is Open Source software. It provides the automation of Linux application deployment in a software container. We can do operating system level virtualization on Linux with Docker. Docker can package software in a complete file system that contains software code, runtime environment, system tools, & libraries that are required to install and run the software on a server. 2. What is the difference between Docker image and Docker container? Docker container is simply an instance of Docker image. A Docker image is an immutable file, which is a snapshot of container. We create an image with build command. When we use run command, an Image will produce a container. In programming language, an Image is a Class and a Container is an instance of the class. 3. How will you remove an image from Docker? We can use docker rmi command to delete an image from our local system. Exact command is: % docker rmi <Image Id> If we want to fin

Microservices Interview Questions

Microservices Interview Questions 1. What is a Microservice in Java? A Microservice is a small and autonomous piece of code that does one thing very well. It is focused on doing well one specific task in a big system. It is also an autonomous entity that can be designed, developed and deployed independently. Generally, it is implemented as a REST service on HTTP protocol, with technology-agnostic APIs. Ideally, it does not share database with any other service. 2. What are the benefits of Microservices architecture? Microservices provide many benefits. Some of the key benefits are: 1.      Scaling : Since there are multiple Microservices instead of one monolith, it is easier to scale up the service that is being used more. Eg. Let say, you have a Product Lookup service and Product Buy service. The frequency of Product Lookup is much higher than Product Buy service. In this case, you can just scale up the Product Lookup service to run on powerful hardware with multipl

Cloud Computing Interview Questions

Cloud Computing 1. What are the benefits of Cloud Computing? There are ten main benefits of Cloud Computing: Flexibility : The businesses that have fluctuating bandwidth demands need the flexibility of Cloud Computing. If you need high bandwidth, you can scale up your cloud capacity. When you do not need high bandwidth, you can just scale down. There is no need to be tied into an inflexible fixed capacity infrastructure. Disaster Recovery : Cloud Computing provides robust backup and recovery solutions that are hosted in cloud. Due to this there is no need to spend extra resources on homegrown disaster recovery. It also saves time in setting up disaster recovery. Automatic Software Updates : Most of the Cloud providers give automatic software updates. This reduces the extra task of installing new software version and always catching up with the latest software installs. Low Capital Expenditure : In Cloud computing the model is Pay as you Go. This means there is very