What’s a deadlock ?
A condition that occurs when two processes are waiting for each other to complete, before proceeding. The result is that both processes wait endlessly.View
How does thread synchronization occurs inside a monitor ? What levels of synchronization can you apply ?
The JVM uses locks in conjunction with monitors. A monitor is basically a guardian that watches over a sequence of synchronized code and ensuring that only one thread at a time executes a synchronized piece of code. Each monitor is associated with an object reference. The thread is not allowed to execute the code until it obtains the lock.View
What is the difference between a synchronized method and a synchronized block ?
In Java programming, each object has a lock. A thread can acquire the lock for an object by using the synchronized keyword. The synchronized keyword can be applied in a method level (coarse grained lock) or block level of code (fine grained lock).View
Explain the available thread states in a high-level.
During its execution, a thread can reside in one of the following
NEW: The thread becomes ready to run, but does not necessarily start running immediately.
RUNNABLE: The Java Virtual Machine (JVM) is actively executing the thread’s code.
BLOCKED: The thread is in a blocked state while waiting for a monitor lock.
WAITING: The thread waits for another thread to perform a particular action.
TIMED_WAITING: The thread waits for another thread to perform a particular action up to a specified waiting time.
TERMINATED: The thread has finished its execution.
Explain different ways of creating a thread. Which one would you prefer and why ?
There are three ways that can be used in order for a
Thread to be created:
Executorframework, in order to create a thread pool.
Runnable interface is preferred, as it does not require an object to inherit the
Thread class. In case your application design requires multiple inheritance, only interfaces can help you. Also, the thread pool is very efficient and can be implemented and used very easily.
What is the difference between processes and threads ?
What are pass by reference and pass by value ?
When an object is passed by value, this means that a copy of the object is passed. Thus, even if changes are made to that object, it doesn’t affect the original value. When an object is passed by reference, this means that the actual object is not passed, rather a reference of the object is passed. Thus, any changes made by the external method, are also reflected in all places.View
What is the difference between an Interface and an Abstract class ?
Java provides and supports the creation both of abstract classes and interfaces. Both implementations share some common characteristics, but they differ in the following features:
Also check out the Abstract class and Interface differences for JDK 8.View
Does Java support multiple inheritance ?
No, Java does not support multiple inheritance. Each class is able to extend only on one class, but is able to implement more than one interfaces.View
What is a Constructor, Constructor Overloading in Java and Copy-Constructor ?
A constructor gets invoked when a new object is created. Every class has a constructor. In case the programmer does not provide a constructor for a class, the Java compiler (Javac) creates a default constructor for that class. The constructor overloading is similar to method overloading in Java. Different constructors can be created for a single class. Each constructor must have its own unique parameter list. Finally, Java does support copy constructors like C++, but the difference lies in the fact that Java doesn’t create a default copy constructor if you don’t write your own.View
What is Function Overriding and Overloading in Java ?
Method overloading in Java occurs when two or more methods in the same class have the exact same name, but different parameters. On the other hand, method overriding is defined as the case when a child class redefines the same method as a parent class. Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides.View
What are the Data Types supported by Java ? What is Autoboxing and Unboxing ?
The eight primitive data types supported by the Java programming language are:
Autoboxing is the automatic conversion made by the Java compiler between the primitive types and their corresponding object wrapper classes. For example, the compiler converts an int to an
Integer, a double to a
Double, and so on. If the conversion goes the other way, this operation is called
Can you access non static variable in static context ?
A static variable in Java belongs to its class and its value remains the same for all its instances. A static variable is initialized when the class is loaded by the JVM. If your code tries to access a non-static variable, without any instance, the compiler will complain, because those variables are not created yet and they are not associated with any instance.View
What does the “static” keyword mean ? Can you override private or static method in Java ?
The static keyword denotes that a member variable or method can be accessed, without requiring an instantiation of the class to which it belongs. A user cannot override static methods in Java, because method overriding is based upon dynamic binding at runtime and static methods are statically binded at compile time. A static method is not associated with any instance of a class so the concept is not applicable.View
What is the Difference between JDK and JRE ?
The Java Runtime Environment (JRE) is basically the Java Virtual Machine (JVM) where your Java programs are being executed. It also includes browser plugins for applet execution. The Java Development Kit (JDK) is the full featured Software Development Kit for Java, including the JRE, the compilers and tools (like
Java Debugger), in order for a user to develop, compile and execute Java applications.
What is JVM ? Why is Java called the “Platform Independent Programming Language” ?
A Java virtual machine (JVM) is a process virtual machine that can execute Java bytecode. Each Java source file is compiled into a bytecode file, which is executed by the JVM. Java was designed to allow application programs to be built that could be run on any platform, without having to be rewritten or recompiled by the programmer for each separate platform. A Java virtual machine makes this possible, because it is aware of the specific instruction lengths and other particularities of the underlying hardware platform.View
© 2017 QuizBucket.org