Banner_Ads

Interview Question-Answers | Tutorial For Beginners


tech4allsa2z:This blog provides you tutorial and most common Interview questions for beginners related to the following technology like java, python.

Top 10 Important Core Java Interview questions and answers


 

What is Java?    

Java is a platform-independent, high-level, object-oriented, multithreaded, portable programming language. It was originally designed by James Gosling of Sun Microsystems in June 1991. Released in 1995 as a core component of Sun Microsystems.   Sun Microsystems was then acquired by Oracle, and Java was developed by Oracle. Currently Java is one of the most popular programming languages ​​in the world. It is also considered a platform independent because it has its own JRE and API.

What are the main features of Java?

The main Java features/properties are:  

Object Oriented - Java is an object-oriented programming language. This because Java programs use classes and objects. 

Distributed - Information is distributed among different computers on the network. 

Rugged - Rugged means strong. Java programs are robust and do not crash as easily as C or C++ programs. There are two reasons. First, Java has excellent built-in exception handling capabilities, and second, memory management capabilities.  Most 'C' and 'C++' programs crash prematurely because they don't allocate enough memory. Java does not have this problem because it does not require the user to allocate or handle memory. Everything is done by the JVM.  

Secure – Java eliminates security issues such as viruses, eavesdropping, and tampering.  

System Independent – ​​Java bytecode is machine (system) independent. This means that code can run on a wide variety of machines with any processor and operating system. 

Portable – A program is said to be portable if it produces the same result on every machine.

Why pointers are eliminated from Java?

Here's why pointers were removed from Java:  

• Pointers confuse programs.  

• Pointers can easily crash your program. 

For example, the program immediately crashes when two pointers are added. The same thing can happen if you free memory allocated to one variable and forget to allocate it to another variable.  

• Pointers break security. Pointers can be used to develop malicious programs such as viruses and other hacking programs.

What is the BYTE code?

BYTE code is intermediate level code interpreted by the JVM. You can't run it directly on your machine.  BYTE code is intermediate code between Java programs and operating system (OS) machine code, available in ".class" files. When a Java program or application is compiled, a ".class" file is generated. The BYTE code is the same for all operating systems, but the machine code is different for each operating system.

What is JVM? Explain its working?

A JVM (Java Virtual Machine) is an abstract machine designed to be implemented on existing processors. Hides the underlying operating system (OS) from Java applications. This is actually the heart of the entire Java program execution process.  Programs written in Java are compiled to Java bytecode. It is interpreted by a specific Java interpreter for a specific platform. This Java interpreter is called the "Java Virtual Machine". The JVM's machine language is called Java Byte Code.  First, a Java program is converted into a class file by a Java compiler using bytecode instructions. This class file is passed to the JVM. The JVM has a module called the class loader subsystem that does the following:  

• First, load the class file into memory. 

• Allocate the memory needed to execute the program, if a byte instruction is appropriate.





What is JRE?

JRE stands for "Java Runtime Environment". It is a platform consisting of the Java Virtual Machine, Java libraries, and all other components required to run Java applications and applets.

What is the Java compiler?

A Java compiler is a program that converts Java source code into Java bytecode.  A simple Java compiler is already included in the JDK (Java Development Kit). The Java compiler invoked by "javac".

What is the JIT compiler?

The JIT (Just-In-Time) compiler is the part of the JVM that speeds up the execution of Java programs. A JIT compiler, at runtime he interacts with the JVM. Instead of interpreting bytecode every time a method is called, the JIT compiles the bytecode into machine code instructions for the running machine and then calls the object code. This prevents the JVM from repeatedly interpreting the same sequence of bytecodes, speeding up execution.

What is public static void main (String args []) in Java?

The public static void main (String [] args) line defines the method main. Conceptually, it is similar to the main () function in C/C++.  In Java, main () is the entry point for all Java programs. A Java program can have any number of classes, but only one of them must contain the method that initiates execution. This line contains the following terms:  

public - The term "public" is an access identifier. Declare the main method as unprotected and make it accessible from all other classes. 

Static - The term "static" declares the method as belonging to the class as a whole rather than being part of the class's objects. 

main () should always be declared as "static" because the interpreter uses this method before creating the object. 

void - The void type qualifier indicates that the main method does not return any value, it just prints statements to the screen.  

main () - This is the method where the interpreter starts executing the program. This is actually the name of the method the Java Virtual Machine is looking for as a starting point for applications with a particular signature.  String args [] - This is the parameters passed to the main method.

What happens if string args [] is not written in the main () method?

If you write the main () method without the string args [] . B. public static void main (), the code compiles, but the JVM doesn't run the code because it can't recognize the main () method as the one that starts running the Java program. Note that the JVM always looks for a main () method with a string array as a parameter.

Is Java 100% Object-oriented? Also, give a reason.

Java is not 100% object oriented as it supports non-primitive data types that are not objects. Concepts like polymorphism, inheritance, abstraction, mainly his OOP concepts make Java an object-oriented language. However, it does not support all OOP concepts such as multiple inheritance.

What are the types of Java programs?

There are two main types of Java programs: 

(i) internet applets and (ii) standalone applications.  

Internet Applets - Internet applets are small programs embedded in web pages that run securely on a variety of computers with a Java-enabled browser (with limited access to system resources). Internet applets cannot run by themselves. They can only be run within a web browser.  

Standalone Applications - Standalone applications are much more interesting than Internet applets. These are just software applications that don't require low-level operating system (OS) or hardware access. This type of Java program includes most common desktop applications such as word processors and spreadsheets. All Java standalone applications start by executing the main () method. Java standalone applications can run independently on any platform

What are the different levels of access protection (access modifiers) available in Java?

Access modifiers are a special kind of keyword essentially used to restrict access to classes, constructors, data members, and methods of another class. 

Java has four basic types of access modifiers:  

Private - Private members of a class cannot be accessed anywhere outside the class. They can only be accessed within the class via the methods of that class.  

Public - Public members of a class are accessible anywhere outside the class. So other programs can read and use them.  

Protected - Protected members of a class can be accessed outside the class, but are typically in the same directory.  

Default - If the programmer does not write an access modifier/specifier, the Java compiler will use the default access specifier. "Standard" members are accessible outside the class but within the same directory.

Define ‘packages. What are some advantages of packages?

A package represents a directory or container that contains a set of related classes and interfaces. The functionality of the objects determines how they are grouped.  

Package Benefits: 

• Packages help group related classes and interfaces together. 

• Packages hide classes and interfaces in separate subdirectories to prevent accidental deletion of classes and interfaces. 

• Classes and interfaces in one package are separated from classes and interfaces in another package.

How many types of packages are used in Java?

(i) Built-in packages :

Packages already provided in the Java language. These packages provide programmers with all the classes, interfaces, and methods they need to perform their tasks.

 Some important packages are:  

java. lang: "lang" represents the language. This package contains the main classes and interfaces essential for developing basic programs. 

java. util: "util" stands for utility. This package contains useful classes and interfaces such as Stack, LinkedList, Vector, and Array. A class is called a collection. 

java.io: "io" stands for "input and output". This package contains streams classes. A stream represents the flow of data from one place to another. 

(ii) Custom Packages Similar to the   built-in packages, users can also create their own packages. Such packages are called custom packages.

What are the different types of memory areas used by JVM? 

The following types of memory regions are allocated by the JVM:   Heap: The heap area is the run-time data area where memory is allocated for objects.  Stack:  Java stack save frame. Stores local variables and partial results. The Java stack is responsible for calling and returning methods. A private JVM stack is also created for each thread each time it is created. A new frame is created each time the method is called and ends when the method call completes.

What are the Wrapper classes?

As the name suggests, wrapper classes are used to wrap primitive data types into objects of that particular class. Simply put, wrapper classes are used to convert Java primitives to reference types (objects). These are typically object representations for all eight commonly used primitives in Java. In Java, all wrapper classes are immutable and final.

 

👉Core Java Interview Questions and Answers for Freshers 

👉Important Core Java Interview questions and answers

👉Java Exception handling Interview Questions and Answers

👉Oops Interview Questions in Java for Freshers

👉Java Collection Framework Interview questions for Freshers

👉Java9 Interview Questions & Answers for beginners

👉Java8 Interview Questions & Answers for beginners 

 

 

Post a Comment

0 Comments