What will be the default values of all the elements of an array defined as an instance variable?
Can main method be declared final?
Can a public class MyClass be defined in a source file named YourClass.java?
How many objects are created in the following piece of code? MyClass c1, c2, c3; c1 = new MyClass (); c3 = new MyClass ();
What is the default value of the local variables?
What are the different scopes for Java variables?
1. Instance : - These are typical object level variables, they are initialized to default values at the time of creation of object, and remain accessible as long as the object accessible.
2. Local : - These are the variables that are defined within a method. They remain accessbile only during the course of method excecution. When the method finishes execution, these variables fall out of scope.
3. Static: - These are the class level variables. They are initialized when the class is loaded in JVM for the first time and remain there as long as the class remains loaded. They are not tied to any particular object instance.
What will be the initial value of an object reference which is defined as an instance variable?
What happens if you dont initialize an instance variable of any of the primitive types in Java?
Is delete a keyword in Java?
Is String a primitive data type in Java?
Can a .java file contain more than one java classes?
What is the catch or declare rule for method declarations?
What is the difference between preemptive scheduling and time slicing?
What does it mean that a method or field is "static"?
Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That's how library methods like System.out.println() work out is a static field in the java.lang.System class.
What are some alternatives to inheritance?
What modifiers are allowed for methods in an Interface?
What is Externalizable?
What are synchronized methods and synchronized statements?
What method must be implemented by all threads?
Can an unreachable object become reachable again?
How does a try statement determine which catch clause should be used to handle an exception?
When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exceptionis executed. The remaining catch clauses are ignored.
What are the steps in the JDBC connection?
Step 1 : Register the database driver by using :
Class.forName(\" driver classs for that specific database\" );
Step 2 : Now create a database connection using :
Connection con = DriverManager.getConnection(url,username,password);
Step 3: Now Create a query using :
Statement stmt = Connection.Statement(\"select * from TABLE NAME\");
Step 4 : Exceute the query :
stmt.exceuteUpdate();
Can applets communicate with each other?
An applet can also get references to all other applets on the same page using the getApplets() method of java.applet.AppletContext. Once you get the reference to an applet, you can communicate with it by using its public members.
It is conceivable to have applets in different virtual machines that talk to a server somewhere on the Internet and store any data that needs to be serialized there. Then, when another applet needs this data, it could connect to this same server. Implementing this is non-trivial.
What is daemon thread and which method is used to create the daemon thread?
What are synchronized methods and synchronized statements?
How are this() and super() used with constructors?
What is the difference between static and non-static variables?
What is the difference between a while statement and a do statement?
What is the Locale class?
What is the purpose of finalization?
When a thread is created and started, what is its initial state?
What is the difference between preemptive scheduling and time slicing?
Does garbage collection guarantee that a program will not run out of memory?
How does Java handle integer overflows and underflows?
What is synchronization and why is it important?
the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often leads to significant errors.
How are Observer and Observable used?
If I write System.exit (0); at the end of the try block, will the finally block still execute?
If I write return at the end of the try block, will the finally block still execute?
Is it necessary that each try block must be followed by a catch block?
What is the basic difference between the 2 approaches to exception handling. 1> try catch block and 2> specifying the candidate exceptions in the thr
What are the different 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 the method and let the caller of the method hadle those exceptions.
How does an exception permeate through the code?
If my class already extends from some other class what should I do if I want an instance of my class to be thrown as an exception object?
If I want an object of my class to be thrown as an exception object, what should I do?
How to create custom exceptions?
What is the difference between error and an exception?
What are runtime exceptions?
What are checked exceptions?
Why do we need wrapper classes?
What are wrapper classes?
Give a simplest way to find out the time a method takes for execution without using any profiling tool?
To put it in code...
long start = System.currentTimeMillis ();
method ();
long end = System.currentTimeMillis ();
System.out.println ("Time taken for execution is " + (end - start));
Remember that if the time taken for execution is too small, it might show that it is taking zero milliseconds for execution. Try it on a method which is big enough, in the sense the one which is doing considerable amout of processing.
Does Java provide any construct to find out the size of an object?
What happens to the static fields of a class during serialization?
There are three exceptions in which serialization doesnot necessarily read and write to the stream. These are
1. Serialization ignores static fields, because they are not part of ay particular state state.
2. Base class fields are only hendled if the base class itself is serializable.
3. Transient fields.
What one should take care of while serializing the object?
When you serialize an object, what happens to the object references included in the object?
What is Externalizable interface?
What is the common usage of serialization?
How can I customize the seralization process? i.e. how can one have a control over the serialization process?
Which methods of Serializable interface should I implement?
How do I serialize an object to a file?
What is serialization?
Objects are passed by value or by reference?
Primitive data types are passed by reference or pass by value?
What type of parameter passing does Java support?
Can a top level class be private or protected?
Can a top level class be private or protected?
What is the default value of an object reference declared as an instance variable?
What is the difference between declaring a variable and defining a variable?
e.g String s; is just a declaration while String s = new String ("abcd"); Or String s = "abcd"; are both definitions.
Does importing a package imports the subpackages as well? e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*?
Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile?
import java.io.ABCD;
What are different types of inner classes?
Nested top-level classes- If you declare a class within a class and specify the static modifier, the compiler treats the class just like any other top-level class.
Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. eg, outer.inner. Top-level inner classes implicitly have access only to static variables.There can also be inner interfaces. All of these are of the nested top-level variety.
Member classes - Member inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables. This means a public member class acts similarly to a nested top-level class. The primary difference between member classes and nested top-level classes is that member classes have access to the specific instance of the enclosing class.
Local classes - Local classes are like local variables, specific to a block of code. Their visibility is only within the block of their declaration. In order for the class to be useful beyond the declaration block, it would need to implement a
more publicly available interface.Because local classes are not members, the modifiers public, protected, private, and static are not usable.
Anonymous classes - Anonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor.
What is Overriding?
What are Checked and UnChecked Exception?
exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method· Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.
Can I import same package/class twice? Will the JVM load the package twice at runtime?
Do I need to import java.lang package any time? Why ?
Can I have multiple main methods in the same class?
Can an application have multiple classes having main method?
What environment variables do I need to set on my machine in order to be able to run Java programs?
How can one prove that the array is not null but empty using one line of code?
What is the first argument of the String array in main method?
What if I do not provide the String array as the argument to the method?
What if I write static public void instead of public static void?
What if the static modifier is removed from the signature of the main method?
What if the main method is declared as private?
What is final?
What is static in java?
What is an abstract class?
A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.
State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships o
private : Private variables or methods may be used only by an instance of the same class that declares the variable or method, A private feature may only be accessed by the class that owns the feature.
protected : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature.This access is provided even to subclasses that reside in a different package from the class that owns the protected feature.
default :What you get by default ie, without any access modifier (ie, public private or protected).It means that it is visible to all within a particular package.
What is an Iterator?
What is the difference between a constructor and a method?
A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.
Difference between Swing and Awt?
Difference between HashMap and HashTable?
What are pass by reference and passby value?
Explain different way of using thread?
Describe synchronization in respect to multithreading.
What is the purpose of garbage collection in Java, and when is it used?
What is the difference between an Interface and an Abstract class?
| A: | 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 implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods. |