Java Interview Questions And Answers

Java Interview Questions list for experienced

  1. What is the difference between a constructor and a method?
  2. What is the purpose of garbage collection in Java, and when is it used?
  3. Describe synchronization in respect to multithreading.
  4. What is an abstract class?
  5. What is the difference between an Interface and an Abstract class?
  6. Explain different way of using thread?
  7. What is an Iterator?
  8. State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers.
  9. What is static in java?
  10. What is final class?
  11. How can one prove that the array is not null but empty using one line of code?
  12. What environment variables do I need to set on my machine in order to be able to run Java programs?
  13. Can I import same package/class twice? Will the JVM load the package twice at runtime?
  14. What are Checked and UnChecked Exception?
  15. What is Overriding?
  16. What is the default value of an object reference declared as an instance variable?
  17. Can a top level class be private or protected?
  18. What type of parameter passing does Java support?
  19. What is Externalizable interface?
  20. What are wrapper classes?
  21. Why do we need wrapper classes?
  22. What are checked exceptions?
  23. What are runtime exceptions?
  24. What is the difference between error and an exception?
  25. How does an exception permeate through the code?
  26. What are the different ways to handle exceptions?
  27. Is it necessary that each try block must be followed by a catch block?
  28. If I write System.exit(0); at the end of the try block, will the finally block still execute?
  29. How are Observer and Observable used?
  30. What is synchronization and why is it important?
  31. What is the difference between preemptive scheduling and time slicing?
  32. When a thread is created and started, what is its initial state?
  33. What is the purpose of finalization?
  34. Can applets communicate with each other?
  35. What are the steps in the JDBC connection?
  36. What method must be implemented by all threads?
  37. What are synchronized methods and synchronized statements?
  38. What is Externalizable?
  39. What modifiers are allowed for methods in an Interface?
  40. What are some alternatives to inheritance?
  41. What does it mean that a method or field is \"static\"?
  42. What will be the initial value of an object reference which is defined as an instance variable?
  43. What are the different scopes for Java variables?
  44. What is the default value of the local variables?
  45. What will be the default values of all the elements of an array defined as an instance variable?
  46. What is JVM ? Why is Java called the "Platform Independent Programming Language" ?
  47. What is the Difference between JDK and JRE ?
  48. What does the "static" keyword mean ? Can you override private or static method in Java ?
  49. Can you access non static variable in static context ?
  50. What are the Data Types supported by Java ? What is Autoboxing and Unboxing ?
  51. What is Function Overriding and Overloading in Java ?
  52. What is a Constructor, Constructor Overloading in Java and Copy-Constructor ?
  53. Does Java support multiple inheritance ?
  54. What are pass by reference and pass by value ?
  55. What is the difference between processes and threads ?
  56. Explain different ways of creating a thread. Which one would you prefer and why ?
  57. What is the difference between a synchronized method and a synchronized block ?
  58. How does thread synchronization occurs inside a monitor ? What levels of synchronization can you apply ?
  59. What's a deadlock ?
  60. How do you ensure that N threads can access N resources without deadlock ?
  61. What are the basic interfaces of Java Collections Framework ?
  62. Why Collection doesn't extend Cloneable and Serializable interfaces ?
  63. What differences exist between Iterator and ListIterator ?
  64. What is difference between Array and ArrayList ? When will you use Array over ArrayList ?
  65. What is difference between ArrayList and LinkedList ?
  66. What is Comparable and Comparator interface ? List their differences
  67. What is Java Priority Queue ?
  68. What do you know about the big-O notation and can you give some examples with respect to different data structures ?
  69. What is the tradeoff between using an unordered array versus an ordered array ?
  70. What are some of the best practices relating to the Java Collection framework ?
  71. What's the difference between Enumeration and Iterator interfaces ?
  72. What is the difference between HashSet and TreeSet ?
  73. What does System.gc() and Runtime.gc() methods do ?
  74. When is the finalize() called ? What is the purpose of finalization ?
  75. If an object reference is set to null, will the Garbage Collector immediately free the memory held by that object ?
  76. What is structure of Java Heap ? What is Perm Gen space in Heap ?
  77. What is the difference between Serial and Throughput Garbage collector ?
  78. When does an Object becomes eligible for Garbage collection in Java ?
  79. What are the two types of Exceptions in Java ? Which are the differences between them ?
  80. What is the difference between Exception and Error in java ?
  81. What is the difference between throw and throws ?
  82. What is the importance of finally block in exception handling ?
  83. What will happen to the Exception object after exception handling ?
  84. How does finally block differ from finalize() method ?
  85. What is an Applet ?
  86. What happens when an applet is loaded ?
  87. What do you mean by platform independence?
  88. What is the difference between C++ & Java?
  89. Why java is not a 100% oops?
  90. Whatisaresourcebundle?
  91. What is the difference between preemptive scheduling and timeslicing?
  92. What is the difference between the Boolean &operator and the &&operator?
  93. Whatisthepurposeofthewait(),notify(),andnotifyAll()methods?
  94. How does Java handle integer overflows and underflows?
  95. What is a transient variable?
  96. What does it mean that a method or class is abstract?
  97. How are this() and super() used with constructors?
  98. What does it mean that a class or member is final?
  99. How many static init can you have ?
  100. What is constructor chaining and how is it achieved in Java ?
  101. Which Java operator is right associative?
  102. Can a double value be cast to a byte?
  103. What restrictions are placed on method overriding?
  104. What is a Java package and how is it used?
  105. What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. import java.net.* versus import java.net.Socket)?
  106. Can a method be overloaded based on different return type but same argument type ?
  107. When does the compiler supply a default constructor for a class?
  108. If a method is declared as protected, where may the method be accessed?
  109. What are the legal operands of the instanceof operator?
  110. What is the diffrence between inner class and nested class?
  111. Can an abstract class be final?
  112. What is numeric promotion?
  113. What is the difference between a public and a non-public class?
  114. To what value is a variable of the boolean type automatically initialized?
  115. What is casting?
  116. Why does Java not support operator overloading?
  117. What is an Abstract Class and what is it\'s purpose?
  118. What is a package?
  119. Which package is imported by default?
  120. What is the impact of declaring a method as final?
  121. Can you give few examples of final classes defined in Java API?
  122. What is the most important feature of Java?
  123. Are JVM\'s platform independent?
  124. What is a JVM?
  125. What is the difference between a JDK and a JVM?
  126. Explain how to create and use sockets in java.
  127. How to connect java with mysql?
  128. QUESTION ON JAVA
  129. What is multithreading?
  130. What is the thread?
  131. Differentiate between process and thread?
  132. What do you understand by inter-thread communication?
  133. What is the purpose of wait() method in Java?
  134. Why must wait() method be called from the synchronized block?
  135. What are the advantages of multithreading?
  136. What are the states in the lifecycle of a Thread?
  137. What is context switching?
  138. Differentiate between the Thread class and Runnable interface for creating a Thread?
  139. What does join() method?
  140. Describe the purpose and working of sleep() method.
  141. Can we call the run() method instead of start()?
  142. What about the daemon threads?
  143. Can we make the user thread as daemon thread if the thread is started?
  144. What is the purpose of the Synchronized block?
  145. How to detect a deadlock condition? How can it be avoided?
  146. What is Thread Scheduler in java?
  147. How is the safety of a thread achieved?
  148. What is race-condition?
  149. What do you understand by thread pool?
  150. List the programming languages used in video games.
  151. Give 10 reasons to learn Java.

Java interview questions and answers on advance and basic Java with example so this page for both freshers and experienced condidate. Fill the form below we will send the all interview questions on Java also add your Questions if any you have to ask and for apply in Java Tutorials and Training course just send a mail on info@pcds.co.in in detail about your self.

Top Java interview questions and answers for freshers and experienced

What is Java ?

Answer :

Questions : 1 :: What is the difference between a constructor and a method?

A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. A...View answers

Questions : 2 :: What is the purpose of garbage collection in Java, and when is it used?

The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage...View answers

Questions : 3 :: Describe synchronization in respect to multithreading.


With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchonization, it is possible for one thread to modify a...View answers

Questions : 4 :: What is an abstract class?

Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie. you may not call its constructor), abstract class may contain...View answers

Questions : 5 :: What is the difference between an Interface and an Abstract class?

An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are...View answers

Questions : 6 :: Explain different way of using thread?


The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cause when you are going for multiple inheritance, the only...View answers

Questions : 7 :: What is an Iterator?

Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk through a collection of objects, operating on each object in...View answers

Questions : 8 :: State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers.

public: Public class is visible in other packages, field is visible everywhere (class must be public too) private : Private variables or methods may be used only by an instance of the same class...View answers

Questions : 9 :: What is static in java?


Static means one per class, not one for each object no matter how many instance of a class might exist. This means that you can use them without creating an instance of a class.Static methods are...View answers

Questions : 10 :: What is final class?

A final class can't be extended ie., final class may not be subclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a...View answers

Questions : 11 :: How can one prove that the array is not null but empty using one line of code?

Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print...View answers

Questions : 12 :: What environment variables do I need to set on my machine in order to be able to run Java programs?

CLASSPATH and PATH are the two variables.

Questions : 13 :: Can I import same package/class twice? Will the JVM load the package twice at runtime?

One can import the same package or same class multiple times. Neither compiler nor JVM complains about it. And the JVM will internally load the class only once no matter how many times you import the...View answers

Questions : 14 :: What are Checked and UnChecked Exception?

A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Making an exception checked forces client programmers to deal with the...View answers

Questions : 15 :: What is Overriding?

When a class defines a method using the same name, return type, and arguments as a method in its superclass, the method in the class overrides the method in the superclass. When the method is...View answers

Questions : 16 :: What is the default value of an object reference declared as an instance variable?

The default value will be null unless we define it explicitly.

Questions : 17 :: Can a top level class be private or protected?

No. A top level class cannot be private or protected. It can have either "public" or no modifier. If it does not have a modifier it is supposed to have a default access. If a top level class is...View answers

Questions : 18 :: What type of parameter passing does Java support?

In Java the arguments are always passed by value.

Questions : 19 :: What is Externalizable interface?

Externalizable is an interface which contains two methods readExternal and writeExternal. These methods give you a control over the serialization mechanism. Thus if your class implements this...View answers

Questions : 20 :: What are wrapper classes?

Java provides specialized classes corresponding to each of the primitive data types. These are called wrapper classes. They are example: Integer, Character, Double etc.

Questions : 21 :: Why do we need wrapper classes?

It is sometimes easier to deal with primitives as objects. Moreover most of the collection classes store objects and not primitive data types. And also the wrapper classes provide many utility...View answers

Questions : 22 :: What are checked exceptions?

Checked exception are those which the Java compiler forces you to catch. Example: IOException are checked exceptions.

Questions : 23 :: What are runtime exceptions?

Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc. These are not checked by the compiler at compile...View answers

Questions : 24 :: What is the difference between error and an exception?

An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. These JVM errors and you can not repair them at runtime. While exceptions are conditions that occur because of...View answers

Questions : 25 :: How does an exception permeate through the code?

An unhandled exception moves up the method stack in search of a matching When an exception is thrown from a code which is wrapped in a try block followed by one or more catch blocks, a search is made...View answers

Questions : 26 :: What are the different ways to handle exceptions?

There are two ways to handle exceptions, 1. By wrapping the desired code in a try block followed by a catch block to catch the exceptions. and 2. List the desired exceptions in the throws clause of...View answers

Questions : 27 :: Is it necessary that each try block must be followed by a catch block?

It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block or a finally block. And whatever exceptions are likely to be thrown should be...View answers

Questions : 28 :: If I write System.exit(0); at the end of the try block, will the finally block still execute?

No. In this case the finally block will not execute because when you say System.exit(0); the control immediately goes out of the program, and thus finally never...View answers

Questions : 29 :: How are Observer and Observable used?

Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it...View answers

Questions : 30 :: What is synchronization and why is it important?

With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a...View answers

Questions : 31 :: What is the difference between preemptive scheduling and time slicing?

Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a...View answers

Questions : 32 :: When a thread is created and started, what is its initial state?

A thread is in the ready state after it has been created and started.

Questions : 33 :: What is the purpose of finalization?

The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.

Questions : 34 :: Can applets communicate with each other?

At this point in time applets may communicate with other applets running in the same virtual machine. If the applets are of the same class, they can communicate via shared static variables. If the...View answers

Questions : 35 :: What are the steps in the JDBC connection?

While making a JDBC connection we go through the following steps : Step 1 : Register the database driver by using : Class.forName(" driver classs for that specific database" ); Step 2 : Now...View answers

Questions : 36 :: What method must be implemented by all threads?

All tasks must implement the run() method, whether they are a subclass of Thread or implement the Runnable interface.

Questions : 37 :: What are synchronized methods and synchronized statements?

Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or...View answers

Questions : 38 :: What is Externalizable?

Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput...View answers

Questions : 39 :: What modifiers are allowed for methods in an Interface?

Only public and abstract modifiers are allowed for methods in interfaces.

Questions : 40 :: What are some alternatives to inheritance?

Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than...View answers

Questions : 41 :: What does it mean that a method or field is "static"?

Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular...View answers

Questions : 42 :: What will be the initial value of an object reference which is defined as an instance variable?

The object references are all initialized to null in Java. However in order to do anything useful with these references, you must set them to a valid object, else you will get NullPointerExceptions...View answers

Questions : 43 :: What are the different scopes for Java variables?

The scope of a Java variable is determined by the context in which the variable is declared. Thus a java variable can have one of the three scopes at any given point in time. 1. Instance : - These...View answers

Questions : 44 :: What is the default value of the local variables?

The local variables are not initialized to any default value, neither primitives nor object references. If you try to use these variables without initializing them explicitly, the java compiler will...View answers

Questions : 45 :: What will be the default values of all the elements of an array defined as an instance variable?

If the array is an array of primitive types, then all the elements of the array will be initialized to the default value corresponding to that primitive type. Example: All the elements of an array...View answers

Questions : 46 :: What is JVM ? Why is Java called the "Platform Independent Programming Language" ?

A Java virtual machine (JVM) is a process Virutal Machine that can execute Java Byte Code Each Java source file is compiled into a byte code file, which is executed by the JVM. Java was designed to...View answers

Questions : 47 :: 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 plug-in for applet execution. The Java Development...View answers

Questions : 48 :: 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...View answers

Questions : 49 :: 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...View answers

Questions : 50 :: 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: byte, short, int, long, float,double, boolean,char.

Questions : 51 :: 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...View answers

Questions : 52 :: 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...View answers

Questions : 53 :: 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.

Questions : 54 :: 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...View answers

Questions : 55 :: What is the difference between processes and threads ?

A process is an execution of a program, while aThread is a single execution sequence within a process. A process can contain multiple threads. A Thread is sometimes called a lightweight...View answers

Questions : 56 :: 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: A class may extend the Thread class. A class may implement the Runnable interface. An application can use the...View answers

Questions : 57 :: 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...View answers

Questions : 58 :: 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...View answers

Questions : 59 :: 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.

Questions : 60 :: How do you ensure that N threads can access N resources without deadlock ?

A very simple way to avoid deadlock while using N threads is to impose an ordering on the locks and force each thread to follow that ordering. Thus, if all threads lock and unlock the mutexes in the...View answers

Questions : 61 :: What are the basic interfaces of Java Collections Framework ?

Java collections Framework provides a well designed set of interfaces and classes that support operations on a collections of objects. The most basic interfaces that reside in the Java Collections...View answers

Questions : 62 :: Why Collection doesn't extend Cloneable and Serializable interfaces ?

The Collection interface specifies groups of objects known as elements. Each concrete implementation of a Collection can choose its own way of how to maintain and order its elements. Some collections...View answers

Questions : 63 :: What differences exist between Iterator and ListIterator ?

The differences of these elements are listed below: An Iterator can be used to traverse the set and List collections, while the ListIterator can be used to iterate only over Lists The Iterator can...View answers

Questions : 64 :: What is difference between Array and ArrayList ? When will you use Array over ArrayList ?

The Array and ArrayList classes differ on the following features: Arrays can contain primitive or objects, while an ArrayList can contain only...View answers

Questions : 65 :: What is difference between ArrayList and LinkedList ?

Both the Array List and Linked List classes implement the List interface, but they differ on the following features: An Array List is an index based data structure...View answers

Questions : 66 :: What is Comparable and Comparator interface ? List their differences

Java provides the Comparable interface, which contains only one method, called compare To. This method compares two objects, in order to impose an order between them. Specifically, it...View answers

Questions : 67 :: What is Java Priority Queue ?

The Priority Queue is an unbounded queue, based on a priority heap and its elements are ordered in their natural order. At the time of its creation, we can provide a Comparator that is...View answers

Questions : 68 :: What do you know about the big-O notation and can you give some examples with respect to different data structures ?

The Big-O notation simply describes how well an algorithm scales or performs in the worst case scenario as the number of elements in a data structure increases. The Big-O notation can also...View answers

Questions : 69 :: What is the tradeoff between using an unordered array versus an ordered array ?

The major advantage of an ordered array is that the search times have time complexity of O(log n), compared to that of an unordered array, which is O (n). The disadvantage of an ordered array is that...View answers

Questions : 70 :: What are some of the best practices relating to the Java Collection framework ?

Choosing the right type of the collection to use, based on the application’s needs, is very crucial for its performance. For example if the size of the elements is fixed and know a priori, we...View answers

Questions : 71 :: What's the difference between Enumeration and Iterator interfaces ?

Enumeration is twice as fast as compared to an Iterator and uses very less memory. However, the Iterator is much safer compared to Enumeration, because other threads are not able...View answers

Questions : 72 :: What is the difference between HashSet and TreeSet ?

The HashSet is Implemented using a hash table and thus, its elements are not ordered. The add, remove, and contains methods of aHashSet have constant time complexity O(1). On the...View answers

Questions : 73 :: What does System.gc() and Runtime.gc() methods do ?

These methods can be used as a hint to the JVM, in order to start a garbage collection. However, this it is up to the Java Virtual Machine (JVM) to start the garbage collection immediately or later...View answers

Questions : 74 :: When is the finalize() called ? What is the purpose of finalization ?

The finalize method is called by the garbage collector, just before releasing the object’s memory. It is normally advised to release resources held by the object inside the finalize...View answers

Questions : 75 :: If an object reference is set to null, will the Garbage Collector immediately free the memory held by that object ?

No, the object will be available for garbage collection in the next cycle of the garbage collector.

Questions : 76 :: What is structure of Java Heap ? What is Perm Gen space in Heap ?

The JVM has a heap that is the runtime data area from which memory for all class instances and arrays is allocated. It is created at the JVM start-up. Heap memory for objects is reclaimed...View answers

Questions : 77 :: What is the difference between Serial and Throughput Garbage collector ?

The throughput garbage collector uses a parallel version of the young generation collector and is meant to be used with applications that have medium to large data sets. On the other hand, the serial...View answers

Questions : 78 :: When does an Object becomes eligible for Garbage collection in Java ?

A Java object is subject to garbage collection when it becomes unreachable to the program in which it is currently used. Garbage Collection does occur in PermGen space and if PermGen space is full...View answers

Questions : 79 :: What are the two types of Exceptions in Java ? Which are the differences between them ?

Java has two types of exceptions: checked exceptions and unchecked exceptions. Unchecked exceptions do not need to be declared in a method or a constructor’s throws clause, if they can be...View answers

Questions : 80 :: What is the difference between Exception and Error in java ?

Exception and Error classes are both subclasses of the Throwable class. The Exception class is used for exceptional conditions that a user’s program should...View answers

Questions : 81 :: What is the difference between throw and throws ?

The throw keyword is used to explicitly raise a exception within the program. On the contrary, the throws clause is used to indicate those exceptions that are not handled by a method. Each method...View answers

Questions : 82 :: What is the importance of finally block in exception handling ?

A finally block will always be executed, whether or not an exception is actually thrown. Even in the case where the catch statement is missing and an exception is thrown, the finally block will still...View answers

Questions : 83 :: What will happen to the Exception object after exception handling ?

The Exception object will be garbage collected in the next garbage collection.

Questions : 84 :: How does finally block differ from finalize() method ?

A finally block will be executed whether or not an exception is thrown and is used to release those resources held by the application. Finalize is a protected method of the Object class, which is...View answers

Questions : 85 :: What is an Applet ?

A java applet is program that can be included in a HTML page and be executed in a java enabled client browser. Applets are used for creating dynamic and interactive web applications. Explain the...View answers

Questions : 86 :: What happens when an applet is loaded ?

First of all, an instance of the applet’s controlling class is created. Then, the applet initializes itself and finally, it starts running.

Questions : 87 :: What do you mean by platform independence?

Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg...View answers

Questions : 88 :: What is the difference between C++ & Java?

Well as Bjarne Stroustrup says "..despite the syntactic similarities, C++ and Java are very different languages. In many ways, Java seems closer to Smalltalk than to C++..". Here are...View answers

Questions : 89 :: Why java is not a 100% oops?

Many people say this because Java uses primitive types such as int, char, double. But then all the rest are objects. Confusing question.

Questions : 90 :: Whatisaresourcebundle?

In its simplest form, a resource bundle is represented by a text file containing keys and a text value for each key.

Questions : 91 :: What is the difference between preemptive scheduling and timeslicing?

Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a...View answers

Questions : 92 :: What is the difference between the Boolean &operator and the &&operator?

If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the &&...View answers

Questions : 93 :: Whatisthepurposeofthewait(),notify(),andnotifyAll()methods?

Questions : 94 :: How does Java handle integer overflows and underflows?

It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.

Questions : 95 :: What is a transient variable?

transient variable is a variable that may not be serialized.

Questions : 96 :: What does it mean that a method or class is abstract?

An abstract class cannot be instantiated. Abstract methods may only be included in abstract classes. However, an abstract class is not required to have any abstract methods, though most of them do....View answers

Questions : 97 :: How are this() and super() used with constructors?

this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.

Questions : 98 :: What does it mean that a class or member is final?

final class cannot be inherited. A final method cannot be overridden in a subclass. A final field cannot be changed after it's initialized, and it must include an initializer statement where it's...View answers

Questions : 99 :: How many static init can you have ?

As many as you want, but the static initializers and class variable initializers are executed in textual order and may not refer to class variables declared in the class whose declarations appear...View answers

Questions : 100 :: What is constructor chaining and how is it achieved in Java ?

A child object constructor always first needs to construct its parent (which in turn calls its parent constructor.). In Java it is done via an implicit call to the no-args constructor as the first...View answers

Questions : 101 :: Which Java operator is right associative?

The = operator is right associative.

Questions : 102 :: Can a double value be cast to a byte?

Yes, a double value can be cast to a byte.

Questions : 103 :: What restrictions are placed on method overriding?

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. The overriding method may not throw any...View answers

Questions : 104 :: What is a Java package and how is it used?

A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces. Packages are also used to organize related...View answers

Questions : 105 :: What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. import java.net.* versus import java.net.Socket)?

It makes no difference in the generated class files since only the classes that are actually used are referenced by the generated class file. There is another practical benefit to importing single...View answers

Questions : 106 :: Can a method be overloaded based on different return type but same argument type ?

No, because the methods can be called without using their return type in which case there is ambiquity for the compiler

Questions : 107 :: When does the compiler supply a default constructor for a class?

The compiler supplies a default constructor for a class if no other constructors are provided.

Questions : 108 :: If a method is declared as protected, where may the method be accessed?

A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

Questions : 109 :: What are the legal operands of the instanceof operator?

The left operand is an object reference or null value and the right operand is a class, interface, or array type.

Questions : 110 :: What is the diffrence between inner class and nested class?

When a class is defined within a scope od another class, then it becomes inner class. If the access modifier of the inner class is static, then it becomes nested class.

Questions : 111 :: Can an abstract class be final?

An abstract class may not be declared as final

Questions : 112 :: What is numeric promotion?

Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short...View answers

Questions : 113 :: What is the difference between a public and a non-public class?

A public class may be accessed outside of its package. A non-public class may not be accessed outside of its package.

Questions : 114 :: To what value is a variable of the boolean type automatically initialized?

The default value of the boolean type is false

Questions : 115 :: What is casting?

There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values,...View answers

Questions : 116 :: Why does Java not support operator overloading?

Operator overloading makes the code very difficult to read and maintain. To maintain code simplicity, Java doesn't support operator overloading.

Questions : 117 :: What is an Abstract Class and what is it's purpose?

A Class which doesn't provide complete implementation is defined as an abstract class. Abstract classes enforce abstraction.

Questions : 118 :: What is a package?

Package is a collection of related classes and interfaces. package declaration should be first statement in a java class.

Questions : 119 :: Which package is imported by default?

java.lang package is imported by default even without a package declaration.

Questions : 120 :: What is the impact of declaring a method as final?

A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation.

Questions : 121 :: Can you give few examples of final classes defined in Java API?

java.lang.String,java.lang.Math are final classes.

Questions : 122 :: What is the most important feature of Java?

Java is a platform independent language

Questions : 123 :: Are JVM's platform independent?

JVM's are not platform independent. JVM's are platform specific run time implementation provided by the vendor.

Questions : 124 :: What is a JVM?

JVM is Java Virtual Machine which is a run time environment for the compiled java class files.

Questions : 125 :: What is the difference between a JDK and a JVM?

JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source...View answers

Questions : 126 :: Explain how to create and use sockets in java.

Sockets are created for client and server. The ServerSocket class is used for creating sockets for server. The Socket class is used for creating sockets for client side. After creating the sockets,...View answers

Questions : 127 :: How to connect java with mysql?

Create a Java project and a package called de.vogella.mysql.first. Create a lib folder and copy the JDBC driver into this folder. Add the JDBC driver to your classpath. Create the following class...View answers

Questions : 128 :: QUESTION ON JAVA

Why wait and notify is declared in Object class instead of Thread ? AND Why is multiple inheritances not supported in Java...View answers

Questions : 129 :: What is multithreading?

Multithreading is a process of executing multiple threads simultaneously. Multithreading is used to obtain the multitasking. It consumes less memory and gives the fast and efficient performance. Its...View answers

Questions : 130 :: What is the thread?

A thread is a lightweight subprocess. It is a separate path of execution because each thread runs in a different stack frame. A process may contain multiple threads. Threads share the process...View answers

Questions : 131 :: Differentiate between process and thread?

There are the following differences between the process and thread. A Program in the execution is called the process whereas; A thread is a subset of the process Processes are independent whereas...View answers

Questions : 132 :: What do you understand by inter-thread communication?

The process of communication between synchronized threads is termed as inter-thread communication. Inter-thread communication is used to avoid thread polling in Java. The thread is paused running...View answers

Questions : 133 :: What is the purpose of wait() method in Java?

The wait() method is provided by the Object class in Java. This method is used for inter-thread communication in Java. The java.lang.Object.wait() is used to pause the current thread, and wait until...View answers

Questions : 134 :: Why must wait() method be called from the synchronized block?

We must call the wait method otherwise it will throw java.lang.IllegalMonitorStateException exception. Moreover, we need wait() method for inter-thread communication with notify() and...View answers

Questions : 135 :: What are the advantages of multithreading?

Multithreading programming has the following advantages: Multithreading allows an application/program to be always reactive for input, even already running with some background...View answers

Questions : 136 :: What are the states in the lifecycle of a Thread?

A thread can have one of the following states during its lifetime: New: In this state, a Thread class object is created using a new operator, but the thread is not alive. Thread doesn't start...View answers

Questions : 137 :: What is context switching?

In Context switching the state of the process (or thread) is stored so that it can be restored and execution can be resumed from the same point later. Context switching enables the multiple processes...View answers

Questions : 138 :: Differentiate between the Thread class and Runnable interface for creating a Thread?

The Thread can be created by using two ways. By extending the Thread class By implementing the Runnable interface However, the primary differences between both the ways are given below: By...View answers

Questions : 139 :: What does join() method?

The join() method waits for a thread to die. In other words, it causes the currently running threads to stop executing until the thread it joins with completes its task. Join method is overloaded in...View answers

Questions : 140 :: Describe the purpose and working of sleep() method.

The sleep() method in java is used to block a thread for a particular time, which means it pause the execution of a thread for a specific time. There are two methods of doing so. Syntax: public...View answers

Questions : 141 :: Can we call the run() method instead of start()?

Yes, calling run() method directly is valid, but it will not work as a thread instead it will work as a normal object. There will not be context-switching between the threads. When we call the...View answers

Questions : 142 :: What about the daemon threads?

The daemon threads are the low priority threads that provide the background support and services to the user threads. Daemon thread gets automatically terminated by the JVM if the program remains...View answers

Questions : 143 :: Can we make the user thread as daemon thread if the thread is started?

No, if you do so, it will throw IllegalThreadStateException. Therefore, we can only create a daemon thread before starting the...View answers

Questions : 144 :: What is the purpose of the Synchronized block?

The Synchronized block can be used to perform synchronization on any specific resource of the method. Only one thread at a time can execute on a particular resource, and all other threads which...View answers

Questions : 145 :: How to detect a deadlock condition? How can it be avoided?

We can detect the deadlock condition by running the code on cmd and collecting the Thread Dump, and if any deadlock is present in the code, then a message will appear on cmd. Ways to avoid the...View answers

Questions : 146 :: What is Thread Scheduler in java?

In Java, when we create the threads, they are supervised with the help of a Thread Scheduler, which is the part of JVM. Thread scheduler is only responsible for deciding which thread should be...View answers

Questions : 147 :: How is the safety of a thread achieved?

If a method or class object can be used by multiple threads at a time without any race condition, then the class is thread-safe. Thread safety is used to make a program safe to use in multithreaded...View answers

Questions : 148 :: What is race-condition?

A Race condition is a problem which occurs in the multithreaded programming when various threads execute simultaneously accessing a shared resource at the same time. The proper use of synchronization...View answers

Questions : 149 :: What do you understand by thread pool?

Java Thread pool represents a group of worker threads, which are waiting for the task to be allocated. Threads in the thread pool are supervised by the service provider which pulls one thread from...View answers

Questions : 150 :: List the programming languages used in video games.

Minecraft: Java Fortnite: C++ Call of Duty: C++ PUBG: C++ Counter Strike:C++ Among Us:...View answers

Questions : 151 :: Give 10 reasons to learn Java.

Java's Popularity and High salary Java is Portable and versatile Java is an OOP Language Demand: Java is everywhere Java Developement Tools Java Applications Tons of resources and community...View answers
More Question

Ask your interview questions on Java

Write Your comment or Questions if you want the answers on Java from Java Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---