This
is the 7th part of the 500+ Core JAVA interview questions and answers.
These questions can also be used as a quick study guide for preparing
for an interview or for any Core JAVA concepts revision. These questions
cover all the topics in core JAVA from basics to advanced concepts.
1. Strings are immutable. But String s=”Hello”; String s1=s+”World” returns HelloWorld how?
Here actually a new object is created with the value of HelloWorld
Method overloading is the process of creating a new method with the same name and different signature.
3. What is internationalization?
Internationalization is the process of designing an application so that it can be adapted to various languages and regions without changes.
Multi-threading is the scenario where more than one threads are running.
5.What is deadlock?
Deadlock is a situation when two threads are waiting on each other to release a resource. Each thread waiting for a resource which is held by the other waiting thread.
Byte code is an sort of intermediate code. The byte code is processed by virtual machine.
7.What are the two important TCP Socket classes?
ServerSocket and Socket. ServerSocket is useful for two-way socket communication. Socket class help us to read and write through the sockets. getInputStream() and getOutputStream() are the two methods available in Socket class.
A Locale object represents a specific geographical, political, or cultural region
9.What is method overriding?
Method overriding is the process of giving a new definition for an existing method in its child class.
Finalize is a protected method in java. When the garbage collector is executes , it will first call finalize( ), and on the next garbage-collection it reclaim the objects memory. So finalize( ), gives you the chance to perform some cleanup operation at the time of garbage collection.
11.What is classpath?
Classpath is the path where Java looks for loading class at run time and compile time.
12.What is the difference between URL and URLConnection?
A URL represents the location of a resource, and a URLConnection represents a link for accessing or communicating with the resource at the location.
13.What is anonymous class ?
An anonymous class is a type of inner class that don’t have any name.
14.What is the difference between Iterator and Enumeration?
Iterator differ from enumeration in two ways Iterator allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics. And , method names have been improved.
15.What is path?
It is an the location where the OS will look for finding out the executable files and commands.
16.What is finalize() ?
Finalize is a protected method in java. When the garbage collector is executes , it will first call finalize( ), and on the next garbage-collection it reclaim the objects memory. So finalize( ), gives you the chance to perform some cleanup operation at the time of garbage collection.
17.What is path?
It is an the location where the OS will look for finding out the executable files and commands.
18.What is internationalization?
Internationalization is the process of designing an application so that it can be adapted to various languages and regions without changes.
19.What is multi-threading?
Multi-threading is the scenario where more than one threads are running.
20.Can we compile a java program without main?
Yes, we can. In order to compile a java program, we don’t require any main method. But to execute a java program we must have a main in it (unless it is an applet or servlet). Because main is the starting point of a java program.
21.What are the two important TCP Socket classes?
ServerSocket and Socket. ServerSocket is useful for two-way socket communication. Socket class help us to read and write through the sockets. getInputStream() and getOutputStream() are the two methods available in Socket class.
22.What is deadlock?
Deadlock is a situation when two threads are waiting on each other to release a resource. Each thread waiting for a resource which is held by the other waiting thread.
23.What is anonymous class ?
An anonymous class is a type of inner class that don’t have any name.
24.What is the difference between URL and URLConnection?
A URL represents the location of a resource, and a URLConnection represents a link for accessing or communicating with the resource at the location.
25.Strings are immutable. But String s=”Hello”; String s1=s+”World” returns HelloWorld how ?
Here actually a new object is created with the value of HelloWorld
26.What is the difference between Iterator and Enumeration?
Iterator differ from enumeration in two ways Iterator allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics. And , method names have been improved.
27.What is classpath?
Classpath is the path where Java looks for loading class at run time and compile time.
28.What are the restrictions when overriding a method ?
Overridden methods must have the same name, argument list, and return type (i.e., they must have the exact signature of the method we are going to override, including return type.) The overriding method cannot be less visible than the method it overrides( i.e., a public method cannot be override to private). The overriding method may not throw any exceptions that may not be thrown by the overridden method
29.What are the different ways in which a thread can enter into waiting state?
There are three ways for a thread to enter into waiting state. By invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object’s lock, or by invoking an object’s wait() method.
30.What is the Locale class?
A Locale object represents a specific geographical, political, or cultural region
31.What is java collections?
Java collections is a set of classes, that allows operations on a collection of classes.
32.What are the the different ways for creating a thread?
A thread can be created by sub classing Thread, or by implementing the Runnable interface.
33.How parameters are passed to methods in java program ?
All java method parameters in java are passed by value only. Obviously primitives are passed by value. In case of objects a copy of the reference is passed and so all the changes made in the method will persist.
34.What is a java compilation unit.
A compilation unit is a java source file.
35.How does a try statement determine which catch clause should be used to handle an exception?
When an exception is thrown , the catch block of the try statement are examined in the order in which they appear. The first catch block that is capable of handling the exception is executed. The remaining catch blocks are ignored
36. If a class doesn’t have any constructors, what will happen?
If a class doesn’t have a constructor, the JVM will provide a default constructor for the class.
37.What is static initializer block? What is its use?
A static initializer block is a block of code that declares with the static keyword. It normally contains the block of code that must execute at the time of class loading. The static initializer block will execute only once at the time of loading the class only.
38.How does multithreading occurring on a computer with a single CPU?
The task scheduler of OS allocates an execution time for multiple tasks. By switching between different executing tasks, it creates the impression that tasks execute sequentially. But actually there is only one task is executed at a time.
39.What will happen if a thread cannot acquire a lock on an object?
It enters to the waiting state until lock becomes available.
40.What will happen if you are invoking a thread’s interrupt method while the thread is waiting or sleeping?
When the task enters to the running state, it will throw an InterruptedException.
41.What is the difference between creating a thread by extending Thread class and by implementing Runnable interface? Which one should prefer?
When creating a thread by extending the Thread class, it is not mandatory to override the run method (If we are not overriding the run method , it is useless), because Thread class have already given a default implementation for run method. But if we are implementing Runnable , it is mandatory to override the run method. The preferred way to create a thread is by implementing Runnable interface, because it give loose coupling.
42.What is coupling?
Coupling is the dependency between different components of a system
43. What are the differences between JIT and HotSpot?
The Hotspot VM is a collection of techniques, the most important of which is called adaptive optimization. The original JVMs interpreted byte codes one at a time. Second-generation JVMs added a JIT compiler, which compiles each method to native code upon first execution, then executes the native code. Thereafter, whenever the method is called, the native code is executed. The adaptive optimization technique used by Hotspot is a hybrid approach, one that combines byte code interpretation and run-time compilation to native code. Hotspot, unlike a regular JIT compiling VM, doesn’t do “premature optimization”
44. Why ArrayList is faster than Vector?
Because Vector is synchronized. Synchronization reduces the performance.
45. What is phantom memory?
Phantom memory is the memory that does not exist in reality.
46. What is the difference between Comparable and Comparator ?
The Comparable is for natural ordering and Comparator is for custom ordering. But we can override the compareTo method of comparable interface to give a custom ordering.
47. What are the advantages and disadvantages of reference counting in garbage collection?
An advantage of this scheme is that it can run in small chunks of time closely linked with the execution of the program. These characteristic makes it particularly suitable for real-time environments where the program can’t be interrupted for very long time. A disadvantage of reference counting is that it does not detect cycles. A cycle is two or more objects that refer to one another. Another disadvantage is the overhead of incrementing and decrement the reference count each time. Because of these disadvantages, reference counting currently is out of favor.
48. What is the security mechanism used in java?
Java uses sand box security model.
49. What is reflection?
Reflection is the process of finding out the different features of a class dynamically.
50. Why Java is not 100% pure object oriented language?
Because java uses primitives.
Next : 1000+ core JAVA quick study material & interview Questions and Answers
Next : 1000+ core JAVA quick study material & interview Questions and Answers
0 Comment to "Core Java Study guide and interview questions - Part 7"
Post a Comment