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...

Amazon Web Services(AWS) Interview questions

Amazon Web Services 1. What do you know about AWS Region? An AWS Region is a completely independent entity in a geographical area. There are two more Availability Zones in an AWS Region. Within a region, Availability Zones are connected through lowlatency links. Since each AWS Region is isolated from another Region, it provides very high fault tolerance and stability. For launching an EC2 instance, we have to select an AMI within the same region. 2. What are the important components of IAM? The important components of IAM are as follows: 1.     IAM User : An IAM User is a person or service that will interact with AWS. User can sign into AWS Management Console for performing tasks in AWS. 2.     IAM Group : An IAM Group is a collection of IAM users. We can specify permission to an IAM Group. This helps in managing large number of IAM users. We can simply add or remove an IAM User to an IAM Group to manage the permissions. 3. ...

Spring Interview Questions

Spring Interview Questions 1. What is Spring framework? Spring is development framework for Java programming. It is an open source development framework for Enterprise Java. The core features of Spring Framework can be used in developing a Java Enterprise application. It has many extensions and jars for developing web applications on top of Java EE platform. With Spring we can develop large-scale complex Java applications very easily. It is also based on good design patterns like Dependency Injection, Aspect oriented programming for developing extensible feature rich software. 2. What are the benefits of Spring framework in software development? Many benefits of Spring framework are: Lightweight Framework : Basic Spring framework is very small in size. It is easy to use and does not add a lot of overhead on software. It just has 2 MB in basic version. Container : Spring framework provides the basic container that creates and manages the life cycle of application ob...