| Terms |
Definitions |
|
What is OOPS?
|
Object Oriented Programming
|
|
If you’re overriding the method equals() of an object, which other method you might also consider?
|
hashCode()
|
|
18. How could Java classes direct program messages to the system console, but error messages, say to a file?
|
standard.error
standard.out
|
|
What is serialization?
|
Quite simply, object serialization provides a program the ability to read or write a whole object to and from a raw byte stream. It allows Java objects and primitives to be encoded into a byte stream suitable for streaming to some type of network or to a file-system, or more generally, to a transmission medium or storage facility. A seralizable object must implement the Serilizable interface. We use ObjectOutputStream to write this object to a stream and ObjectInputStream to read it from the stream.
|
|
You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use:ArrayList or LinkedList?
|
Arraylist
|
|
10. What is the base class for Error and Exception?
|
Throwable
|
|
What is polymorphism?
|
Polymorphism allows methods to be written that needn't be concerned about the specifics of the objects they will be applied to. That is, the method can be specified at a higher level of abstraction and can be counted on to work even on objects of yet unconceived classes.
|
|
Explain Java class loaders?
|
Class loaders are hierarchical. Classes are introduced into the JVM as they are referenced by name in a class that
is already running in the JVM. So, how is the very first class loaded? The very first class is especially loaded with
the help of static main( ) method declared in your class. All the subsequently loaded classes are loaded by the
classes, which are already loaded and running. A class loader creates a namespace. All JVMs include at least one
class loader that is embedded within the JVM called the primordial (or bootstrap) class loader. Now let’s look at
non-primordial class loaders. The JVM has hooks in it to allow user defined class loaders to be used in place of
primordial class loader. Let us look at the class loaders created by the JVM.
|
|
What is the base class for Error and Exception?
|
Throwable
|
|
29. What is composition?
|
Holding the reference of the other class within some other class is known as composition.
|
|
Difference between Vector and ArrayList?
|
Vector is synchronized whereas arraylist is not.
|
|
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, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.
|
|
Define a java servlet?
|
Java Servlets are small, platform, independent Java programs that can be used to extend the functionality of a Web Server in a variety of ways.
ex. Servlets are to the server what applets are to the client (small Java programs compiled to bytecode that can be loaded dynamically and that extend the capabilities of the host.
|
|
Is synchronised a modifier?indentifier??what is it??
|
It's a modifier. 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 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.
|
|
What is aggregation?
|
It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite method through its reference, then it is called aggregation.
A Composition that refences another object, or multiple objects. Has a relation ship and sometimes a one to many relationship.
Ex. Airplane Class
Aggregates Wing, Fuselage, Engine, and Tail classes. All Airplane interactions with those classes go through the Airplane class.
Not Parent Child classes though.
|
|
Explain the Encapsulation principle.
|
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.
|
|
How to create custom exceptions?
|
Your class should extend class Exception, or some more specific type thereof.
|
|
31. What are the methods in Object?
|
clone, equals, wait, finalize, getClass, hashCode, notify, notifyAll, toString
|
|
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 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 Serialization and deserialization?
|
Serialization is the process of writing the state of an object to a byte stream.
Deserialization is the process of restoring these objects.
|
|
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 are checked exceptions?
|
Checked exception are those which the Java compiler forces you to catch. e.g. IOException are checked Exceptions.
|
|
What is the List interface?
|
The List interface provides support for ordered collections of objects.
|
|
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.
|
|
If a class is located in a package, what do you need to change in the OS environment to be able to use it?
|
set in classpath
|
|
Can you instantiate the Math class?
|
You can’t instantiate the math class. All the methods in this class are static. And the constructor is not public.
|
|
What's the difference between the methods sleep() and wait()
|
The code sleep(1000); puts thread aside for exactly one second.
he code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call.
|
|
30. What is aggregation
|
- It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite method through its reference, then it is called aggregation
|
|
Q: What are different types of inner classes?
|
Nested top-level classes, Member classes, Local classes, Anonymous 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.
|
|
When you serialize an object, 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 will be the output of the following statement?
System.out.println ("1" + 3);
|
It will print 13.
|
|
What is a transient variable?
|
A transient variable is a variable that may not be serialized. If you don't want some field not to be serialized, you can mark that field transient or static.
|
|
What is the package?
|
The package is a Java namespace or part of Java libraries. The Java API is grouped into libraries of related classes and interfaces; these libraries are known as packages.
|
|
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 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 the Set interface?
|
The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements.
|
|
What’s the difference between the methods sleep() and wait()
|
The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.
|
|
What is the finalize method do?
|
Before the invalid objects get garbage collected, the JVM give the user a chance to clean up some resources before it got garbage collected.
|
|
What is the difference between declaring a variable and defining a variable?
|
In declaration we just mention the type of the variable and it's name. We do not initialize it. But defining means declaration + initialization.
e.g String s; is just a declaration while String s = new String ("abcd"); Or String s = "abcd"; are both definitions.
|
|
3. What is a daemon thread?
|
These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly.
|
|
32. Can you instantiate the Math class
|
- You can’t instantiate the math class. All the methods in this class are static. And the constructor is not public.
|
|
2. What kind of thread is the Garbage collector thread
|
It is a daemon thread.
|
|
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 shared object while another thread is in the process of using or updating that object's value. This often causes dirty data and leads to significant errors.
|
|
What is a protected method?
|
A protected method is a method that can be accessed by any method in its package and inherited by any subclass of its class.
|
|
What is J2EE Connector?
|
The J2EE Connector API is used by J2EE tools vendors and system integrators to create resource adapters that support access to enterprise information systems that can be plugged into any J2EE product. Each type of database or EIS has a different resource adapter. Note: A resource adapter is a software component that allows J2EE application components to access and interact with the underlying resource manager. Because a resource adapter is specific to its resource manager, there is typically a different resource adapter for each type of database or enterprise information system.
|
|
What if I write static public void instead of public static void?
|
Program compiles and runs properly.
|
|
When is a method said to be overloaded?
|
Overloading deals with multiple methods in the same class
with the same name but different method signatures.
class MyClass {
public void getInvestAmount(int rate) {…}
public void getInvestAmount(int rate, long principal)
{ … }
}
Both the above methods have the same method names
but different method signatures, which mean the methods
are overloaded.
Overloading lets you define the same operation in
different ways for different dat
|
|
Name the eight primitive Java types?
|
The eight primitive types are byte, char, short, int, long, float, double, and boolean.
|
|
Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?
|
Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first.
|
|
What is the purpose of Void class?
|
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void.
It is used primarily in reflection. To determine the return type of a method.
|
|
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.
|
|
What modifiers are allowed for methods in an Interface?
|
Only public and abstract modifiers are allowed for methods in interfaces.
|
|
Is main a keyword in Java?
|
No, main is not a keyword in Java.
|
|
24. What is the final keyword denotes
|
final keyword denotes that it is the final implementation for that method or variable or class. You can’t override that method/variable/class
|
|
What is the EAR file?
|
An EAR file is a standard JAR file with an .ear extension, named from Enterprise ARchive file. A J2EE application with all of its modules is delivered in EAR file.
|
|
What type of parameter passing does Java support?
|
In Java the arguments are always passed by value .
|
|
What if the static modifier is removed from the signature of the main method?
|
Program compiles. But at runtime throws an error "NoSuchMethodError".
|
|
When to use an abstract class?
|
In case where you want to use implementation inheritance then it is usually provided by an abstract base class. Abstract classes are excellent candidates inside of application frameworks. Abstract classes let you define some default behavior and force subclasses to provide any specific behavior.
|
|
What invokes a thread's run() method?
|
After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.
|
|
How many times may an object's finalize() method be invoked by the garbage collector?
|
An object's finalize() method may only be invoked once by the garbage collector.
|
|
Why would you use a synchronized block vs. synchronized method?
|
Synchronized blocks place locks for shorter periods than synchronized methods.
|
|
When should the method invokeLater()be used?
|
This method is used to ensure that Swing components are updated through the event-dispatching thread.
|
|
Can you call one constructor from another if a class has multiple constructors
|
Yes. Use this() to call a constructor from an other constructor.
|
|
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 everywhere you try to use such default initialized references.
|
|
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.
|
|
What is the difference between a while statement and a do statement?
|
A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.
|
|
What happens when a thread cannot acquire a lock on an object?
|
If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object's lock, it enters the waiting state until the lock becomes available.
|
|
What are the Object and Class classes used for?
|
The Object class is the highest-level class in the Java class hierarchy. The Class class is used to represent the classes and interfaces that are loaded by a Java program.
|
|
What classes of exceptions may be caught by a catch clause?
|
A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.
|
|
What is the argument type of a program's main() method?
|
A program's main() method takes an argument of the String[] type.
|
|
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.
|
|
How can a subclass call a method or a constructor defined in a superclass?
|
Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass’s constructor.
|
|
What are the benifits of using an interface.
|
Allows you to use a method from another class without knowing the true classs. Example database calls. Different db classes implement the same interface
|
|
Is Empty .java file a valid source file?
|
Yes, an empty .java file is a perfectly valid source file.
|
|
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();
|
|
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?
|
One can not do anytihng in this scenarion. Because Java does not allow multiple inheritance and does not provide any exception interface as well.
|
|
Q: 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 args.length.
|
|
If a class is declared without any access modifiers, where may the class be accessed?
|
A class that is declared without any access modifiers is said to have package or friendly access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.
|
|
How is it possible for two String objects with identical values not to be equal under the == operator?
|
he == operator compares two objects to determine if they are the same object in memory. It is possible for two String objects to have the same value, but located indifferent areas of memory.
|
|
Is Java pass by value or pass by reference?
|
In Java, Objects are passed by reference, and primitives are passed by value.
This is half incorrect. Everyone can easily agree that primitives are passed by value; there's no such thing in Java as a pointer/reference to a primitive.
However, Objects are not passed by reference. A correct statement would be Object references are passed by value.
|
|
What is an object's lock and which object's have locks?
|
An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock. All objects and classes have locks. A class's lock is acquired on the class's Class object.
|
|
You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces?
|
Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.
|
|
What can go wrong if you replace && with & in the following code:String a=null; if (a!=null && a.length()>10) {...}
|
A single ampersand here would lead to a NullPointerException. It's a bitwise operator
|
|
Can a .java file contain more than one java classes?
|
Yes, a .java file contain more than one java classes, provided at the most one of them is a public class.
|
|
What are three ways in which a thread can enter the waiting state?
|
A thread can enter the 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. It can also enter the waiting state by invoking its (deprecated) suspend() method.
|
|
an 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..
|
|
How do you know if an explicit object casting is needed?
|
If you assign a superclass object to a variable of a subclass's data type, you need to do explicit casting. For example:Object a; Customer b; b = (Customer) a;
|
|
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.
|
|
If you're overriding the method equals() of an object, which other method you might also consider?
|
hashCode()
|
|
What is the byte range?
|
-128 to 127
|
|
How will you invoke any external process in Java?
|
Runtime.getRuntime().exec(….)
|
|
Immutable Oject
|
Immutable objects have no fields that can be changed after the object is created. Ex. String Class
|
|
What is a DatabaseMetaData?
|
Comprehensive information about the database as a whole.
|
|
20. When you think about optimization, what is the best way to findout the time/memory consuming process? -
|
- Using profiler
|
|
What are wrapper classes?
|
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.
|
|
What is Struts?
|
A Web page development framework. Struts combines Java Servlets, Java Server Pages, custom tags, and message resources into a unified framework. It is a cooperative, synergistic platform, suitable for development teams, independent developers, and everyone between.
|
|
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 time.
|
|
What is composition?
|
A class that references another class. This is different from inheritance where where each class is a subclass of the parent class.
|
|
22. How will you get the platform dependent values like line separator, path separator, etc., ? -
|
Using Sytem.getProperty(…) (line.separator, path.separator, …)
|
|
Difference between Swing and Awt?
|
AWT are heavy-weight componenets. Swings are light-weight components. Hence swing works faster than AWT.
|
|
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 are some advantages and disadvantages of Java Sockets?
|
Some advantages of Java Sockets: Sockets are flexible and sufficient.
Some disadvantages of Java Sockets:Security restrictions are sometimes overbearing because a Java applet running in a Web browser is only able to establish connections to the machine where it came from, and to nowhere else on the network, and can only send raw data.
|
|
What's the difference between an interface and an abstract class? Also discuss the similarities.
|
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.
|
|
12. What is the implementation of destroy method in java.. is it native or java code?
|
This method is not implemented.
|
|
34. What is DriverManager?
|
The basic service to manage set of JDBC drivers.
|
|
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 unsynchronized and Hashtable issynchronized.
|
|
What is the serialization?
|
The serialization is a kind of mechanism that makes a class or a bean persistence by having its properties or fields and state information saved and restored to and from storage.
|
|
What is singleton?
|
It is one of the design pattern. This falls in the creational pattern of the design pattern. There will be only one instance for that entire JVM. You can achieve this by having the private constructor in the class. For eg., public class Singleton { private static final Singleton s = new Singleton(); private Singleton() { } public static Singleton getInstance() { return s; } // all non static methods … }
|
|
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 has changed state. The Observer interface is implemented by objects that observe Observable objects.
|
|
7. What is the basic difference between string and stringbuffer object?
|
String is an immutable object. StringBuffer is a mutable object.
|
|
How to call the superclass constructor?
|
If a class called “SpecialPet” extends your “Pet” class then you can
use the keyword “super” to invoke the superclass’s constructor.
|
|
What are the high-level thread states?
|
The high-level thread states are ready, running, waiting, and dead.
|
|
What is the difference between the String and StringBuffer classes?
|
String objects are constants. StringBuffer objects are not.
|
|
What interface must an object implement before it can be written to a stream as an object?
|
An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.
|
|
Which methods of Serializable interface should I implement?
|
The serializable interface is an empty interface, it does not contain any methods. So we do not implement any methods.
|
|
What’s the difference between constructors and other methods?
|
Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.
|
|
What is the basic difference between string and stringbuffer object?
|
String is an immutable object. StringBuffer is a mutable object.
|
|
35. What is Class.forName() does and how it is useful? -
|
It loads the class into the ClassLoader. It returns the Class. Using that you can get the instance ( “class-instance”.newInstance() ).
|
|
What is HashMap and Map?
|
Map is Interface and Hashmap is class that implements that.
|
|
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 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 native code?
|
The native code is code that after you compile it, the compiled code runs on a specific hardware platform.
|
|
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.
|
|
What is a servlet lifecycle?
|
It defines how the servlet is loaded and initialized. How it receives and responds to requests, and how it is taken out of service. It is defined by the javax.servlet.Servlet interface.
|
|
What are checked and unchecked exceptions?
|
Java defines two kinds of exceptions :
* Checked exceptions : Exceptions that inherit from the Exception class are checked exceptions. Client code has to handle the checked exceptions thrown by the API, either in a catch clause or by forwarding it outward with the throws clause. Examples - SQLException, IOxception.
* Unchecked exceptions : RuntimeException also extends from Exception. However, all of the exceptions that inherit from RuntimeException get special treatment. There is no requirement for the client code to deal with them, and hence they are called unchecked exceptions. Example Unchecked exceptions are NullPointerException, OutOfMemoryError, DivideByZeroException typically, programming errors.
|
|
What is an Iterator interface?
|
The Iterator interface is used to step through the elements of a Collection.
|
|
What do you mean by polymorphism?
|
Polymorphism – means the ability of a single variable of a given type to be used to reference objects of
different types, and automatically call the method that is specific to the type of object the variable references. In a
nutshell, polymorphism is a bottom-up method call.
|
|
What’s the main difference between a Vector and an ArrayList
|
Java Vector class is internally synchronized and ArrayList is not.
|
|
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.
|
|
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 applets are of different classes, then each will need a reference to the same class with static variables. In any case the basic idea is to pass the information back and forth through a static variable.
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.
|
|
27. What is nested class?
|
- If all the methods of a inner class is static then it is a nested class.
|
|
1. What is garbage collection? What is the process that is responsible for doing that in java? -
|
Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process
|
|
6. What is mutable object and immutable object?
|
If a object value is changeable then we can call it as Mutable object. (Ex., StringBuffer, …) If you are not allowed to change the value of an object, it is immutable object. (Ex., String, Integer, Float, …)
|
|
Is exit a keyword in Java?
|
No. To exit a program explicitly you use exit method in System object.
|
|
What is the difference between static and non-static variables?
|
A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.
|
|
Primitive data types are passed by reference or pass by value?
|
Primitive data types are passed by value.
|
|
Why there are some null interface in java ? What does it mean ? Give me some null interfaces in JAVA?
|
Null interfaces act as markers..they just tell the compiler that the objects of this class need to be treated differently..some marker interfaces are : Serializable, Remote, Cloneable
|
|
Is string a wrapper class?
|
String is a class, but not a wrapper class. Wrapper classes like (Integer) exist for each primitive type. They can be used to convert a primitive data value into an object, and vice-versa.
|
|
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 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 the difference between the >> and >>> operators?
|
The >> operator carries the sign bit when shifting right. The >>> zero-fills bits that have been shifted out.
|
|
What’s the difference between an interface and an abstract class?
|
An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.
|
|
How can you minimize the need of garbage collection and make the memory use more effective?
|
Use object pooling and weak object references.
|
|
When you think about optimization, what is the best way to findout the time/memory consuming process?
|
Use a profiler, which can be used to determine a number of different metrics to analyze the performance of the code.
|
|
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 not compile the code. It will complain abt the local varaible not being initilized..
|
|
Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile?
|
Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying,can not resolve symbol
symbol : class ABCD
location: package io
import java.io.ABCD;
|
|
What is the default value of an object reference declared as an instance
|
null unless we define it explicitly.
|
|
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 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.
|
|
How do servlets differ from applets?
|
Servlets do not run in a web browser with a Graphical User Interface. Instead they interact with the servlet engine running on the Web Server through requests and responses. The request-response paradigm is modeled on the behavior of HTTP.
|
|
What modifiers may be used with an inner class that is a member of an outer class?
|
A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.
|
|
What state does a thread enter when it terminates its processing?
|
When a thread terminates its processing, it enters the dead state.
|
|
When is a method said to be overridden?
|
Overriding deals with two methods, one in the parent class and
the other one in the child class and has the same name and
signatures.
Overriding lets you define the same operation in different
ways for different object types.
class BaseClass{
public void getInvestAmount(int rate) {…}
}
class MyClass extends BaseClass {
public void getInvestAmount(int rate) { …}
}
Both the above methods have the same method names and
the signatures but the method in the subclass MyClass
overrides the method in the superclass BaseClass.
|
|
What would you use to compare two String variables - the operator == or the method equals()?
|
I’d use the method equals() to compare the values of the Strings and the = = to check if two variables point at the same instance of a String object.
|
|
How can you minimize the need of garbage collection and make the memory use more effective?
|
Use object pooling and weak object references.
|
|
What is skeleton and stub? what is the purpose of those?
|
Stub is a client side representation of the server, which takes care of communicating with the remote server. Skeleton is the server side representation. But that is no more in use… it is deprecated long before in JDK.
Client creates a stub...delivered to the server where it is a skeleton, and it then does the action on the server.
|
|
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.
|
|
What happens if you dont initialize an instance variable of any of the primitive types in Java?
|
Java by default initializes it to the default value for that primitive type. Thus an int will be initialized to 0, a boolean will be initialized to false.
|
|
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 handled if the base class itself is serializable.
3. Transient fields.
|
|
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.
|
|
How is the MVC design pattern used in Struts framework?
|
In the MVC design pattern, application flow is mediated by a central Controller. The Controller delegates requests to an appropriate handler. The handlers are tied to a Model, and each handler acts as an adapter between the request and the Model. The Model represents, or encapsulates, an applications business logic or state. Control is usually then forwarded back through the Controller to the appropriate View. The forwarding can be determined by consulting a set of mappings, usually loaded from a database or configuration file. This provides a loose coupling between the View and Model, which can make an application significantly easier to create and maintain. Controller: Servlet controller which supplied by Struts itself; View: what you can see on the screen, a JSP page and presentation components; Model: System state and a business logic JavaBeans.
|
|
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.
|
|
What value does read() return when it has reached the end of a file?
|
The read() method returns -1 when it has reached the end of a file.
|
|
What if the main method is declared as private?
|
he program compiles properly but at runtime it will give "Main method not public." message.
|
|
There are two classes: A and B. The class B need to inform a class A when some important event has happened. What Java technique would you use to implement it?
|
If these classes are threads I’d consider notify() or notifyAll(). For regular classes you can use the Observer interface.
|
|
What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it?
|
You do not need to specify any access level, and Java will use a default package access level.
|
|
How many objects are created in the following piece of code?
MyClass c1, c2, c3;
c1 = new MyClass ();
c3 = new MyClass ();
|
Only 2 objects are created, c1 and c3. The reference c2 is only declared and not initialized.
|
|
Is the ternary operator written x : y ? z or x ? y : z ?
|
It is written x ? y : z.
|
|
What is the difference between a field variable and a local variable?
|
A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.
|
|
What must a class do to implement an interface?
|
It must provide all of the methods in the interface and identify the interface in its implements clause.
|
|
What are the primitive types and their sizes?
|
I EIGHT a BYTE but was SHORTed 16 bits INT-to 32 of those LONG 64's that FLOATed 32 bits while DOUBLE-ing 64 of them.
They just didn't have the CHAR-acter of the 16's.
|