Java is a programming language and also a platform for computing. Java was first released by Sun Microsystems in the year 1995. There are lots of applications and websites that will not work unless Java is installed in them. Each day there are more and more applications created using Java. It is a very simple, powerful and robust, programming language which provides a fast, secure, and reliable platform to work on. Java is being used everywhere, from laptops to data centers, game consoles to scientific supercomputers, and cell phones to the Internet.
Due to its ease of use and simplicity, Java is used almost everywhere in the IT sector. This means that the professionals who are skilled in Java are always required. If you are someone who is likely to attend a job that would test you on your Java skills, then please go through the list of questions and their answers provided herein. You may also refer to them just to add on to your knowledge.
For a Java enthusiast who is looking to attend a Java interview anytime soon, here are the most popular interview questions and answers that might come your way. We have tried to include the top frequently asked questions as well as their answers to help freshers and the experienced professionals with their job interview.
|JDK stands for Java Development Kit and is the tool used to compile, package and document Java programs.||JRE stands for Java Runtime Environment and is a runtime environment which is a pre-requisite to run java byte-code.||JVM stands for Java Virtual Machine and is a specification that facilitates a run-time environment in which Java’s bytecode can be implemented.|
Java is platform independent because it provides the feasibility to run and compile the program in one platform and execute the program on any other platform of your choice.
Yes, it would be correct to say that Java is not 100% Object-oriented because it utilizes eight kinds of primitive data types and they are – Boolean, byte, char, int, float, double, long, short. These datatypes are not objects.
A constructor is a block of code which is used in a Java environment to initialize an object. It carries the same name that you had given to the class. A Java constructor is automatically called when an object is created.
A constructor constructs the value, by providing data for the object. It is a special type of method that is used to initialize the object. The constructor has the same name as the class itself, has no return type, and is invoked using the new operator.
A method is an ordinary member function of a class. A method can be invoked using the dot operator and has its own name, and a return type. No, declaring the constructor as final is not possible.
A class, in the environment of Java, are some templates which are used for object creation, and to define certain object datatypes and their methods.
A final class is a constant value of a final variable. Extending A final class is not possible ie., final class may not be sub-classed. A final method cannot be overridden when its class is inherited.
The classes that “wrap” the primitive data type into an object of that class are called Java wrapper classes.
Abstract serves as a template. In order to use an abstract class, it must be extended or subclassed. An abstract class may not be instantiated.
Any class with an abstract method is abstract itself, hence is declared as such.
Synchronization is the method to control the access of multiple threads to shared resources, with respect to multi-threading.
One thread can modify a shared variable when not in synchronization even when another thread is in the process of using or updating the same shared variable. This can lead to significant errors.
The main purpose of garbage collection is to analyze a program, identify and discard the objects that are no longer needed. It is helpful as the resources can be reclaimed and reused.
A Java object is subjected to garbage collection when the object is not reachable to the program in which it is used.
The thread can be implemented by
Using runnable interface
Inheriting from the Thread class.
The use of the Runnable interface is more advantageous because when going for multiple inheritances, the only interface can help.
When the main() method is declared as private, the program compiles but during runtime it shows “main() method not public.” Message.
When the static modifier is removed from the signature of the main() method, the Program compiles but at runtime throws an error “NoSuchMethodError”.
Unlike in C/C++ where the first element by default is the program name, the string array in main() has no element, the String array is empty.
A Servlet in Java refers to the server-side technologies which are used to extend the competence of web servers by giving it support for a dynamic response as well as data persistence.
Here is the life-cycle of a Java Servlet-
Request Dispatcher is a Java interface which is used to forward a request to some other resource which can be HTML, JSP or any another Java servlet within the same application.
Follow the given steps to connect to a database in java-
JDBC Driver in Java refers to a software component that allows Java application to relate with the database.
There are 4 types of JDBC drivers in Java-
The applet is a Java program which is designed for transmitting the Java code over the internet. The execution works automatically by Java-enabled Web Browser. The applet can respond to the user input immediately as it is dynamically programmed.
Numeric promotions of a numeric operator are used for the conversion of the operands into a common type. In order to perform calculation easily, numeric promotion, conversion is performed.
It is the conversion of a smaller numeric type to a larger numeric type so that integer and floating-point operations can be performed over it. Here byte, char, and short values are converted to int values. The int values are converted to long values, and the long and float values are converted to double values.
On multi-core systems, false sharing is one of the well-known performance issues. Here each process has its local cache. When threads on a different processor, modify variables false sharing occurs, that resides on the same cache line as shown in the following images
As the thread may access different global variables completely, false sharing can be hard to detect.
Equals and hashcode methods are to be implemented In order to use any object as Key in HashMap, in Java.
Java classes whose objects cannot be modified once they are created are known as Immutable classes. Any modification of Immutable object results formation of the new object.
The only difference between StringBuffer and StringBuilder is that StringBuffer methods are synchronized while StringBuilder is not synchronized. StringBuilder in Java was introduced in Java 5.
Abstract Factory provides one more level of abstraction. Consider different factories each extended from an Abstract Factory and responsible for the creation of different hierarchies of objects based on the type of factory. E.g. Abstract Factory extended by Automobile Factory, User Factory, Role Factory etc. Each individual factory would be responsible for the creation of objects in that genre.
We are going to share Difference between JAR & WAR File:
|JAR FILES||WAR FILES|
|Full form of JAR files is Java Archive Files.||Full form of WAR files is Web Archive Files.|
|Aggregating many files into one is allowed in JAR files||XML, Java classes, and JavaServer pages are stored in WAR|
|The JAR is usually used to hold Java classes in a library.||Mainly used for Web Application purposes.`
Just-In-Time(JIT) compiler is used to improve the performance. JIT compiles parts of the bytecode that has similar functionality which in turn reduces the amount of time needed for compilation. The term “compiler” here refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU.
Multi-catch block makes the code shorter and cleaner when every catch block has a similar code. We can catch multiple exceptions in a single catch block using this feature.
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.