Saturday 24 August 2013

Top Most Core Java Popular Interview Questions - 3

80
Q
What is garbage collection?
A
Garbage collection is the process of releasing memory used by unreferenced objects. It relieves the programmer from the process of manually releasing the memory used by objects .
81
Q
What is the disadvantage of garbage collection?
A
It adds an overhead that can affect performance. Additionally there is no guarantee that the object will be garbage collected.
82
Q
What is a Dictionary?
A
Dictionary is a parent class for any class that maps keys to values., In a dictionary every key is associated with at most one value.
83
Q
What is JAR file ?
A
JAR stands for Java Archive. This is a file format that enables you to bundle multiple files into a single archive file.  A jar file will contains a manifest.mf file inside META-INF folder that describes the version and other features of jar file.
84
Q
Why Java is not fully objective oriented ?
A
Due to the use of primitives in java, which are not objects.
85
Q
What is a marker interface ?
A
An interface that contains no methods. Eg: Serializable, Cloneable, SingleThreadModel etc. It is used to just mark java classes that support certain capability.
86
Q
What are tag interfaces?
A
Tag interface is an alternate name for marker interface.
87
Q
What are the restrictions placed on static method ?
A
We cannot override static methods. We cannot access any object variables inside static method. Also the this reference also not available in static methods. 
88
Q
What is JVM?
A
JVM stands for Java Virtual Machine. It is the run time for java programs. All are java programs are running inside this JVM only. It converts java byte code to OS specific commands. In addition to governing the execution of an application's byte codes, the virtual machine handles related tasks such as managing the system's memory, providing security against malicious code, and managing multiple threads of program execution.
89
Q
What is JIT?
A
JIT stands for Just In Time compiler. It compiles java byte code to native code.
90
Q
What is java byte code?
A
Byte code is an sort of intermediate code. The byte code is processed by virtual machine.
91
Q
What is method overloading?
A
Method overloading is the process of creating a new method with the same name and different signature.
92
Q
What is method overriding?
A
Method overriding is the process of giving a new definition for an existing method in its child class.
93
Q
What is finalize() ?
A
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.
94
Q
What is multi-threading?
A
Multi-threading is the scenario where more than one threads are running.
95
Q
What is deadlock?
A
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.
96
Q
What is the difference between Iterator and Enumeration?
A
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.
97
Q
What is the Locale class?
A
A Locale object represents a specific geographical, political, or cultural region
98
Q
What is internationalization?
A
Internationalization is the process of designing an application so that it can be adapted to various languages and regions without changes.
99
Q
What is anonymous class ?
A
An anonymous class is a type of inner class that don't have any name.
100
Q
What is the difference between URL and URLConnection?
A
A URL represents the location of a resource, and a URLConnection represents a link for accessing or communicating with the resource at the location.
101
Q
What are the two important TCP Socket classes?
A
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.
102
Strings are immutable. But String s="Hello"; String s1=s+"World" returns HelloWorld how ?
AQ
Here actually a new object is created with the value of HelloWorld
103
What is classpath?
A
Classpath is the path where Java looks for loading class at run time and compile time.
104
Q
What is path?
A
It is an the location where the OS will look for finding out the executable files and commands.

106
Q
What is java collections?

A
Java collections is a set of classes, that allows operations on  a collection of classes.



107
Q
Can we compile a java program without main?

A
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.



108
Q
What is a java compilation unit.

A
A compilation unit is a java source file.



109
Q
What are the restrictions when overriding a method ?

A
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

110
Q
What is static initializer block? What is its use?

A
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.



111
Q
How does a try statement determine which catch clause should be used to handle an exception?

A
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



112
Q
How parameters are passed to methods in java program ?

A
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.



113
Q
If a class doesn't have any constructors, what will happen?

A
If a class doesn't have a constructor, the JVM will provide a default constructor for the class.



114
Q
What will happen  if a thread cannot acquire a lock on an object?

A
It enters to the waiting state until lock becomes available.



115
Q
How does multithreading occurring on a computer with a single CPU?

A
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.



116
Q
What will happen if you are invoking a thread's interrupt method while the thread is  waiting or sleeping?

A
When the task enters to the running state, it will throw an InterruptedException.



117
Q
What are the different ways in which a thread can enter into waiting state?

A
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.



118
Q
What are the the different ways for creating a thread?

A
A thread can be created by subclassing Thread, or by implementing the Runnable interface.



119
Q
What is the difference between creating a thread by extending Thread class and by implementing Runnable interface? Which one should prefer?

A
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.

120
Q
What is coupling?


A
Coupling is the dependency between different components of a system


LinkWithin

Related Posts Plugin for WordPress, Blogger...

Labels

Core Java programming core java interview question Core Java Faq's Servlets coding database jsp-servlet spring Java linux unix interview questions java investment bank Web Services Interview investment bank mysql Senior java developer interviews best practices java collection tutorial RMI SQL Eclipse FIX protocol tutorial tibco J2EE groovy java questions SCJP grails java 5 tutorial jdbc beginner error and exception Design Patterns Java Programming Tutorials fundamentals general object oriented programming xml Java Programs Hibernate Examples Flex JAMon Java xml tutorial logging Jsp Struts 2.0 Sybase and SQL Server debugging java interviews performance FIX Protocol interview questions JUnit testing WebSphere date and time tutorial experienced java IO tutorial java concurrency thread Ejb Freshers Papers IT Management Java Exapmle Java Script SQL and database tutorial examples Scwcd ant tutorials concurrency example and tutorial future state homework java changes java threading tricky Agile Business of IT Development JSTL Java JSON tutorial Java multithreading Tutorials PM Scrum data structure and algorithm java puzzles java tips testing tips windows 8 5 way to create Singleton Object Architect Interview Questions and Answers Architecture Architecure Bluetooth server as swing application that searches bluetooth device in 10 meter circle and show all devices. You can send file to any bluetooth device. C Programming CIO Callable Statement in Java Circular dependency of Objects in Java Comparable Example in Collection Custom annotation in Java Developer Interview Divide and rule example in java Drupal Example of Singleton Pattern FIX protocol ForkJoin Example in Java 7 Get data from dynamic table with Java Script Git HTML and JavaScript Health Hello World TCP Client Server Networking Program Hibernate Basics Hibernate Interview Question Answer J2EE Interview Question And Answers J2ME GUI Program JEE Interview QA JMS interview question Java J2EE Hibernate Spring Struts Interview Question Java System Property Java Threads Manager Portlets Provident Fund Read data from any file in same location and give the required result. Reading Properties File in Java Redpoint Rest WebService Client Rest Webservice Test SAL join with ven diagram SCP UNIX COMMAND SSL Singleton Pattern in Java Spring Bean Initialization methods and their order Spring Interview Questions Struts Struts 2.0 Basics Struts 2.0 Design Pattern Submit Html Form With Java Script On The Fly Unix executable For Java Program XOM DOM SAX XP books computers core java; core java; object oriented programming data structure; java investment bank; design pattern dtd duplicate rows in table get browser name with jquery grails podcast inner class java beginners tutorial java cache java networking tutorial java spring java util; java collections; java questions java.java1.5 linked list mailto function with all browser oracle database oracle duplicate rows orm schema social spring mvc questions struts transaction tricks tweet windows xslt