• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/147

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

147 Cards in this Set

  • Front
  • Back
What is the Collections API?
The Collections API is a set of classes and interfaces that support operations on collections of objects.
What is the List interface?
The List interface provides support for ordered collections of objects
What is the Vector class?
The Vector class provides the capability to implement a growable array of objects.
What is an Iterator interface?
The Iterator interface is used to step through the elements of a Collection .
Which java.util classes and interfaces support event handling?
The EventObject class and the EventListener interface support event processing.
What is the GregorianCalendar class?
The GregorianCalendar provides support for traditional Western calendars
What is the Map interface?
The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values.
What is the Collection interface?
The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates.
What is the Set interface?
The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements.
What is the typical use of Hashtable?
Whenever a program wants to store a key value pair, one can use Hashtable.
I am trying to store an object using a key in a Hashtable. And some other object already exists in that location, then what will happen? The existing object will be overwritten? Or the new object will be stored elsewhere?
The existing object will be overwritten and thus it will be lost.
What is the difference between the size and capacity of a Vector?
he size is the number of elements actually stored in the vector, while capacity is the maximum number of elements it can store at a given instance of time.
Can a vector contain heterogenous objects?
Yes a Vector can contain heterogenous objects. Because a Vector stores everything in terms of Object.
an a ArrayList contain heterogenous objects?
Yes a ArrayList can contain heterogenous objects. Because a ArrayList stores everything in terms of Object.
What is an enumeration?
An enumeration is an interface containing methods for accessing the underlying data structure from which the enumeration is obtained. It is a construct which collection classes return when you request a collection of all the objects stored in the collection. It allows sequential access to all the elements stored in the collection.
Considering the basic properties of Vector and ArrayList, where will you use Vector and where will you use ArrayList?
he basic difference between a Vector and an ArrayList is that, vector is synchronized while ArrayList is not. Thus whenever there is a possibility of multiple threads accessing the same instance, one should use Vector. While if not multiple threads are going to access the same instance then use ArrayList. Non synchronized data structure will give better performance than the synchronized one.
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 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.
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 collection when it becomes unreachable to the program in which it is used.
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 shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.
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 interface can help.
What are pass by reference and passby value?
Pass By Reference means the passing the address itself rather than passing the value. Passby Value means passing a copy of the value to be passed.
What is HashMap and Map?
Map is Interface and Hashmap is class that implements that.
Difference between HashMap and HashTable?
The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesnt allow). HashMap does not guarantee that the order of the map will remain constant over time. HashMap is non synchronized and Hashtable is synchronized.
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 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.
What is an Iterators?
Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk a collection of objects, operating on each object in turn. Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained; generally it is not advisable to modify the collection itself while traversing an Iterator.
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.
A: 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 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 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 static data. Any class with an abstract method is automatically abstract itself, and must be declared as such.
A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.
What is static in java?
tatic 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 implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object. A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can't override a static method with a nonstatic method. In other words, you can't change a static method into an instance method in a subclass.
What is final?
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 constant).
What if the main method is declared as private?
The program compiles properly but at runtime it will give "Main method not public." message.
What if the static modifier is removed from the signature of the main method?
Program compiles. But at runtime throws an error "NoSuchMethodError".
What if I write static public void instead of public static void?
Program compiles and runs properly.
What if I do not provide the String array as the argument to the method?
Program compiles but throws a runtime error "NoSuchMethodError".
What is the first argument of the String array in main method?
The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name.
If I do not provide any arguments on the command line, then the String array of Main method will be empty of null?
It is empty. But not null.
How can one prove that the array is not null but empty?
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 args.length.
Can I have multiple main methods in the same class?
No the program fails to compile. The compiler says that the main method is already defined in the class.
Can an application have multiple classes having main method?
Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.
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 possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream's read() method•
Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn't force client programmers either to catch the
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.
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 invoked for an object of the class, it is the new definition of the method that is called, and not the method definition from superclass. Methods may be overridden to be more public, not more private.
What are different types of inner classes?
Nested top-level classes, Member classes, Local classes, Anonymous classes
Member Classes?
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 - 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 classes - Anonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor.
Nested top-level 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.
Can a top level class be private or protected?
No. A top level class can not 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 declared as private the compiler will complain that the "modifier private is not allowed here". This means that a top level class can not be private. Same is the case with protected.
What type of parameter passing does Java support?
In Java the arguments are always passed by value .
Primitive data types are passed by reference or pass by value?
Primitive data types are passed by value.
Objects are passed by value or by reference?
Java only supports pass by value. With objects, the object reference itself is passed by value and so both the original reference and parameter copy both refer to the same object .
What is serialization?
Serialization is a mechanism by which you can save the state of an object by converting it to a byte stream.
How do I serialize an object to a file?
The class whose instances are to be serialized should implement an interface Serializable. Then you pass the instance to the ObjectOutputStream which is connected to a fileoutputstream. This will save the object to a file.
Which methods of Serializable interface should I implement?
he serializable interface is an empty interface, it does not contain any methods. So we do not implement any methods.
How can I customize the seralization process? i.e. how can one have a control over the serialization process?
Yes it is possible to have control over serialization process. The class should implement Externalizable interface. This interface contains two methods namely readExternal and writeExternal. You should implement these methods and write the logic for customizing the serialization process.
What is the common usage of serialization?
Whenever an object is to be sent over the network, objects need to be serialized. Moreover if the state of an object is to be saved, objects need to be serilazed.
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 interface, you can customize the serialization process by implementing these methods.
What happens to the object references included in the object?
The serialization mechanism generates an object graph for serialization. Thus it determines whether the included object references are serializable or not. This is a recursive process. Thus when an object is serialized, all the included objects are also serialized alongwith the original obect.
What one should take care of while serializing the object?
One should make sure that all the included objects are also serializable. If any of the objects is not serializable then it throws a NotSerializableException.
What happens to the static fields of a class during serialization?
A: 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 are wrapper classes?
A: Java provides specialized classes corresponding to each of the primitive data types. These are called wrapper classes. They are e.g. Integer, Character, Double etc.
Why do we need wrapper classes?
A: 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 methods also. Because of these resons we need wrapper classes. And since we create instances of these classes we can store them in any of the collection classes and pass them around as a collection. Also we can pass them around as method parameters where a method expects an object.
What are runtime exceptions?
A: 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 time.
What is the difference between error and an exception?
A: 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 bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist. Or a NullPointerException will take place if you try using a null reference. In most of the cases it is possible to recover from an exception (probably by giving user a feedback for entering proper values etc.).
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?
A: One can not do anytihng in this scenarion. Because Java does not allow multiple inheritance and does not provide any exception interface as well.
What happens to an unhandled exception?
One can not do anytihng in this scenarion. Because Java does not allow multiple inheritance and does not provide any exception interface as well.
How does an exception permeate through the code?
n 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 for matching catch block. If a matching type is found then that block will be invoked. If a matching type is not found then the exception moves up the method stack and reaches the caller method. Same procedure is repeated if the caller method is included in a try catch block. This process continues until a catch block handling the appropriate type of exception is found. If it does not find such a block then finally the program terminates.
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 the method and let the caller of the method hadle those exceptions.
What is the basic difference between the 2 approaches to exception handling...1> try catch block and 2> specifying the candidate exceptions in the throws clause?
When should you use which approach?
A: In the first approach as a programmer of the method, you urself are dealing with the exception. This is fine if you are in a best position to decide should be done in case of an exception. Whereas if it is not the responsibility of the method to deal with it's own exceptions, then do not use this approach. In this case use the second approach. In the second approach we are forcing the caller of the method to catch the exceptions, that the method is likely to throw. This is often the approach library creators use. They list the exception in the throws clause and we must catch them. You will find the same approach throughout the java libraries we use.
Is it necessary that each try block must be followed by a catch block?
t 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 declared in the throws clause of the method.
If I write return at the end of the try block, will the finally block still execute?
A: Yes even if you write return as the last statement in the try block and no exception occurs, the finally block will execute. The finally block will execute and then the control return.
If I write System.exit (0); at the end of the try block, will the finally block still execute?
A: 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 executes.
How are Observer and Observable used?
A: 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 has changed state. The Observer interface is implemented by objects that observe Observable objects.
What is synchronization and why is it important?
A: 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 shared object while another thread is in the process of using or updating that object's value. This often leads to significant errors.
Does garbage collection guarantee that a program will not run out of memory?
Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection
What is the difference between preemptive scheduling and time slicing?
A: 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 predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.
When a thread is created and started, what is its initial state?
A: A thread is in the ready state after it has been created and started.
What is the purpose of finalization?
A: The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
How are this() and super() used with constructors?
A: Othis() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.
What are synchronized methods and synchronized statements?
A: 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 class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.
What is daemon thread and which method is used to create the daemon thread?
A: Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation for the java runtime system. setDaemon method is used to create a daemon thread.
What are the steps in the JDBC connection?
A: 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 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();
How does a try statement determine which catch clause should be used to handle an exception?
A: 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.
Can an unreachable object become reachable again?
A: An unreachable object may become reachable again. This can happen when the object's finalize() method is invoked and the object performs an operation which causes it to become accessible to reachable objects.
What modifiers are allowed for methods in an Interface?
Only public and abstract modifiers are allowed for methods in interfaces.
What are some alternatives to inheritance?
A: 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 inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn't force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).
What does it mean that a method or field is "static"?
A: 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 object, the value of that variable changes for
all instances of that class.
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 is the difference between preemptive scheduling and time slicing?
A: 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 predefined slice of time and then
reenters the pool of ready tasks. The scheduler then determines which task should
execute next, based on priority and other factors.
What is the catch or declare rule for method declarations?
A: If a checked exception may be thrown within the body of a method, the
method must either catch the exception or declare it in its throws clause.
What is transient variable?
Answer: Transient variable can't be serialize. For example if a variable is
declared as transient in a Serializable class and the class is written to an
ObjectStream, the value of the variable can't be written to the stream instead when
the class is retrieved from the ObjectStream the value of the variable becomes
null.
Is Iterator a Class or Interface? What is its use?
Iterator is an interface which is used to step through the elements of a
Collection.
Question: What is similarities/difference between an Abstract class and
Interface?
Differences are as follows:
• Interfaces provide a form of multiple inheritance. A class can extend only
one other class.
• Interfaces are limited to public methods and constants with no
implementation. Abstract classes can have a partial implementation, protected
parts, static methods, etc.
• A Class may implement several interfaces. But in case of abstract class, a
class may extend only one abstract class.
• Interfaces are slow as it requires extra indirection to to find
corresponding method in in the actual class. Abstract classes are fast.
Similarities:
• Neither Abstract classes or Interface can be instantiated.
Explain the Encapsulation principle.
Answer: Encapsulation is a process of binding or wrapping the data and the codes
that operates on the data into a single entity. This keeps the data safe from
outside interface and misuse. One way to think about encapsulation is as a
protective wrapper that prevents code and data from being arbitrarily accessed by
other code defined outside the wrapper.
Question: Explain the Inheritance principle.
Answer: Inheritance is the process by which one object acquires the properties of
another object.
Explain the Polymorphism principle.
Answer: The meaning of Polymorphism is something like one name many forms.
Polymorphism enables one entity to be used as as general category for different
types of actions. The specific action is determined by the exact nature of the
situation. The concept of polymorphism can be explained as "one interface, multiple
methods".
Question: Explain the different forms of Polymorphism.
From a practical programming viewpoint, polymorphism exists in three
distinct forms in Java:
• Method overloading
• Method overriding through inheritance
• Method overriding through the Java interface
Can a private method of a superclass be declared within a
subclass?
Sure. A private field or method or inner class belongs to its declared
class and hides from its subclasses. There is no way for private stuff to have a
runtime overloading or overriding (polymorphism) features.
What is the difference between final, finally and finalize?
o final - declare constant
o finally - handles exception
o finalize - helps in garbage collection
Where and how can you use a private constructor.
Private constructor can be used if you do not want any other class to
instanstiate the object , the instantiation is done from a static public method,
this method is used when dealing with the factory method pattern when the designer
wants only one controller (fatory method ) to create the object.
In System.out.println(),what is System,out and println,pls
explain?
System is a predefined final class,out is a PrintStream object and println
is a built-in overloaded method in the out object.
What is meant by "Abstract Interface"?
First, an interface is abstract. That means you cannot have any
implementation in an interface. All the methods declared in an interface are
abstract methods or signatures of the methods.
arsers? DOM vs SAX parser
parsers are fundamental xml components, a bridge between XML documents and
applications that process that XML. The parser is responsible for handling xml
syntax, checking the contents of the document against constraints established in a
DTD or Schema.
What are three ways in which a thread can enter the waiting
state?
A thread can enter the waiting state byinvoking 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. It can also enter the waiting state by invoking
its (deprecated) suspend() method.
Can a lock be acquired on a class?
Yes, a lock can be acquired on a class. This lock is acquired on the
class's Class object.
What is thread?
A thread is an independent path of execution in a system.
What is multithreading?
Multithreading means various threads that run in a system.
How does multithreading take place on a computer with a single
CPU?
The operating system's task scheduler allocates execution time to multiple
tasks. By quickly switching between executing tasks, it creates the impression that
tasks execute sequentially.
How to create multithread in a program?
You have two ways to do so. First, making your class "extends" Thread
class. Second, making your class "implements" Runnable interface. Put jobs in a
run() method and call start() method to start the thread.
Can Java object be locked down for exclusive use by a given
thread?
Yes. You can lock an object by putting it in a "synchronized" block. The
locked object is inaccessible to any thread other than the one that explicitly
claimed it
What invokes a thread's run() method?
After a thread is started, via its start() method of the Thread class, the
JVM invokes the thread's run() method when the thread is initially executed.
What is the purpose of the wait(), notify(), and notifyAll() methods?
The wait(),notify(), and notifyAll() methods are used to provide an
efficient way for threads to communicate each other.
What are the high-level thread states?
The high-level thread states are ready, running, waiting, and dead.
What is the difference between yielding and sleeping?
hen a task invokes its yield() method, it returns to the ready state. When
a task invokes its sleep() method, it returns to the waiting state.
What is an Object and how do you allocate memory to it?
Object is an instance of a class and it is a software unit that combines a
structured set of data with a set of operations for inspecting and manipulating
that data. When an object is created using new operator, memory is allocated to it.
What is the difference between constructor and method?
Constructor will be automatically invoked when an object is created whereas
method has to be called explicitly.
What are methods and how are they defined?
Methods are functions that operate on instances of classes in which they are
defined. Objects can communicate with each other using methods and can call methods
in other classes. Method definition has four parts. They are name of the method,
type of object or primitive type the method returns, a list of parameters and the
body of the method. A method’s signature is a combination of the first three parts
mentioned above.
What are Transient and Volatile Modifiers?
ransient: The transient modifier applies to variables only and it is not
stored as part of its object’s Persistent state. Transient variables are not
serialized. Volatile: Volatile modifier applies to variables only and it tells the
compiler that the variable modified by volatile can be changed unexpectedly by
other parts of the program.
What is method overloading and method overriding?
Method overloading: When a method in a class having the same method name with
different arguments is said to be method overloading. Method overriding : When a
method in a class having the same method name with same arguments is said to be
method overriding.
What is difference between overloading and overriding?
a) In overloading, there is a relationship between methods available in the
same class whereas in overriding, there is relationship between a superclass method
and subclass method. b) Overloading does not block inheritance from the superclass
whereas overriding blocks inheritance from the superclass. c) In overloading,
separate methods share the same name whereas in overriding, subclass method
replaces the superclass. d) Overloading must have different method signatures
whereas overriding must have same signature.
What modifiers may be used with top-level class?
public, abstract and final can be used for top-level class.
What are inner class and anonymous class?
nner class : classes defined in other classes, including those defined in
methods are called inner classes. An inner class can have any accessibility including private.

Anonymous class : Anonymous class is a class defined inside a
method without a name and is instantiated and declared in the same place and cannot
have explicit constructors.
What is interface and its use?
Interface is similar to a class which may
contain method’s signature only but not bodies and it is a formal set of method and
constant declarations that must be defined by the class that implements it.
Interfaces are useful for: a)Declaring methods that one or more classes are
expected to implement b)Capturing similarities between unrelated classes without
forcing a class relationship. c)Determining an object’s programming interface
without revealing the actual body of the class.
What is a cloneable interface and how many methods does it contain?
It is not having any method because it is a TAGGED or MARKER interface.
What is the difference between abstract class and interface?
a) All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract.
b) In abstract class, key word abstract must be used for the methods whereas interface we need not use that keyword for the methods.
c) Abstract class must have subclasses whereas interface can’t have subclasses.
Can you have an inner class inside a method and what variables can you
access?
Yes, we can have an inner class inside a method and final variables can be accessed.
What is the difference between String and String Buffer?
a) String objects are constants and immutable whereas StringBuffer objects are not.
b) String class supports constant strings whereas StringBuffer class supports growable and modifiable strings.
What is the difference between Array and vector?
Array is a set of related data type and static whereas vector is a growable array of objects and dynamic.
What is the difference between exception and error?
The exception class
defines mild error conditions that your program encounters. Exceptions can occur
when trying to open the file, which does not exist, the network connection is
disrupted, operands being manipulated are out of prescribed ranges, the class file
you are interested in loading is missing. The error class defines serious error
conditions that you should not attempt to recover from. In most cases it is
advisable to let the program terminate when such an error is encountered.
What is the difference between process and thread?-
Process is a program in
execution whereas thread is a separate path of execution in a program.
What is multithreading and what are the methods for inter-thread
communication and what is the class in which these methods are defined?-
Multithreading is the mechanism in which more than one thread run independent of
each other within the process. wait (), notify () and notifyAll() methods can be
used for inter-thread communication and these methods are in Object class. wait() :
When a thread executes a call to wait() method, it surrenders the object lock and
enters into a waiting state. notify() or notifyAll() : To remove a thread from the
waiting state, some other thread must make a call to notify() or notifyAll() method
on the same object.
What is the class and interface in java to create thread and which is the
most advantageous method?
hread class and Runnable interface can be used to
create threads and using Runnable interface is the most advantageous method to
create threads because we need not extend thread class here.
When you will synchronize a piece of your code?-
When you expect your code
will be accessed by different threads and these threads may change a particular
data causing data corruption.
What is deadlock?-
When two threads are waiting each other and can’t
precede the program is said to be deadlock.
What is daemon thread and which method is used to create the daemon
thread?-
Daemon thread is a low priority thread which runs intermittently in the
back ground doing the garbage collection operation for the java runtime system.
setDaemon method is used to create a daemon thread.
What are Vector, Hashtable, LinkedList and Enumeration?-
Vector : The
Vector class provides the capability to implement a growable array of objects.
Hashtable : The Hashtable class implements a Hashtable data structure. A Hashtable
indexes and stores objects in a dictionary using hash codes as the object’s keys.
Hash codes are integer values that identify objects. LinkedList: Removing or
inserting elements in the middle of an array can be done using LinkedList. A
LinkedList stores each object in a separate link whereas an array stores object
references in consecutive locations. Enumeration: An object that implements the
Enumeration interface generates a series of elements, one at a time. It has two
methods, namely hasMoreElements() and nextElement(). HasMoreElemnts() tests if this
enumeration has more elements and nextElement method returns successive elements of
the series.
What is the difference between set and list?
Set stores elements in an
unordered way but does not contain duplicate elements, whereas list stores elements
in an ordered way but may contain duplicate elements.
What is a stream and what are the types of Streams and classes of the
Streams?-
A Stream is an abstraction that either produces or consumes information.
There are two types of Streams and they are: Byte Streams: Provide a convenient
means for handling input and output of bytes. Character Streams: Provide a
convenient means for handling input & output of characters. Byte Streams classes:
Are defined by using two abstract classes, namely InputStream and OutputStream.
Character Streams classes: Are defined by using two abstract classes, namely Reader
and Writer.
What JDBC drivers are available?-
) JDBC-ODBC Bridge driver b) Native API
Partly-Java driver c) JDBC-Net Pure Java driver d) Native-Protocol Pure Java driver
What is the difference between JDBC and ODBC
a) OBDC is for Microsoft and
JDBC is for Java applications. b) ODBC can’t be directly used with Java because it
uses a C interface. c) ODBC makes use of pointers which have been removed totally
from Java. d) ODBC mixes simple and advanced features together and has complex
options for simple queries. But JDBC is designed to keep things simple while
allowing advanced capabilities when required. e) ODBC requires manual installation
of the ODBC driver manager and driver on all client machines. JDBC drivers are
written in Java and JDBC code is automatically installable, secure, and portable on
all platforms. f) JDBC API is a natural Java interface and is built on ODBC. JDBC
retains some of the basic features of ODBC.
What are the types of statements in JDBC?
Statement: to be used
createStatement() method for executing single SQL statement PreparedStatement — To
be used preparedStatement() method for executing same SQL statement over and over.
CallableStatement — To be used prepareCall() method for multiple SQL statements
over and over.
What is stored procedure?
Stored procedure is a group of SQL statements
that forms a logical unit and performs a particular task. Stored Procedures are
used to encapsulate a set of operations or queries to execute on database. Stored
procedures can be compiled and executed with different parameters and results and
may have any combination of input/output parameters.
How to create and call stored procedures?
To create stored procedures:
Create procedure procedurename (specify in, out and in out parameters) BEGIN Any
multiple SQL statement; END; To call stored procedures: CallableStatement csmt =
con. prepareCall(”{call procedure name(?,?)}”); csmt. registerOutParameter(column
no. , data type); csmt. setInt(column no. , column name) csmt. execute();
What is servlet?
Servlets are modules that extend
request/response-oriented servers, such as java-enabled web servers. For example, a
servlet might be responsible for taking data in an HTML order-entry form and
applying the business logic used to update a company’s order database.
What are the classes and interfaces for servlets?
There are two packages
in servlets and they are javax. servlet and
What is the difference between doPost and doGet methods?-
a) doGet() method is used to get information, while doPost() method is used for posting information.
b) doGet() requests can’t send large amount of information and is limited to
240-255 characters. However, doPost()requests passes all of its data, of unlimited
length.
c) A doGet() request is appended to the request URL in a query string and
this allows the exchange is visible to the client, whereas a doPost() request
passes directly over the socket connection as part of its HTTP request body and the
exchange are invisible to the client.
What is the life cycle of a servlet?-
Each Servlet has the same life cycle:
a) A server loads and initializes the servlet by init () method. b) The servlet
handles zero or more client’s requests through service() method. c) The server
removes the servlet through destroy() method.
What are implicit objects? List them?
ertain objects that are available for the use in JSP documents without

being declared first. These objects are parsed by the JSP engine and inserted into

the generated servlet. The implicit objects re listed below
• request
• response
• pageContext
• session
• application
• out
• config
• page
• exception
Difference between forward and sendRedirect?
When you invoke a forward request, the request is sent to another resource
on the server, without the client being informed that a different resource is going
to process the request. This process occurs completly with in the web container.
When a sendRedirtect method is invoked, it causes the web container to return to
the browser indicating that a new URL should be requested. Because the browser
issues a completly new request any object that are stored as request attributes
before the redirect occurs will be lost. This extra round trip a redirect is slower
than forward.
What are the different scope valiues for the <jsp:useBean>?
A: The different scope values for <jsp:useBean> are
1. page
2. request
3.session
4.application