Sunteți pe pagina 1din 21

http://groups.yahoo.

com/group/jiny JINY
1. What are the differences between the == operator and the equals() method?
Well, first off, == is a fundamental operator in the language. The result type of the expression is a boolean. For
comparing boolean types, it compares the operands for the same truth value. For comparing reference types, it
compares the operands for the same reference value (i.e., refer to the same object or are both null). For
numeric types, it compares the operands for the same integer value or equivalent floating point values.

In contrast, equals() is an instance method which is fundamentally defined by the java.lang.Object class. This
method, by convention, indicates whether the receiver object is "equal to" the passed in object. The base
implementation of this method in the Object class checks for reference equality. Other classes, including those
you write, may override this method to perform more specialized equivalence testing. See the Java Language
Specification, section 20.1.3 for more information.

The typical "gotcha" for most people is in using == to compare two strings when they really should be using the
String class's equals() method. From above, you know that the operator will only return "true" when both of the
references refer to the same actual object. But, with strings, most uses want to know whether or not the value
of the two strings are the same -- since two different String objects may both have the same (or different) values.

2. How can I force garbage collection to take place?

Strictly, you can't force it.

You can, however, call System.gc(), which is a "hint" to the runtime engine that now might be a good time to run
the GC. Some implementations take that hint to heart and some don't.

3. What is object serialization?

Serializing an object involves encoding its state in a structured way within a byte array. Once an object is
serialized, the byte array can be manipulated in various ways; it can be written to a file, sent over a network
using a socket-based connection or RMI, or persisted within a database as a BLOB. The serialization process
encodes enough information about the object type within the byte stream, allowing the original object to be
easily recreated upon deserialization, at a later point in time.

4. What is a JIT compiler?


A Just-In-Time compiler is one way to implement the Java Virtual Machine. Rather than the typical, pure
interpreter, a JIT compiler will, on demand, compile the platform independent Java byte codes into platform
specific executable code, in real-time. The first time through, the byte codes are compiled before being
executed. Future passes will use a cached version of the compiled code. This tends to result in a performance
increase of 10-100 times, depending upon the task at hand, over purely interpreted byte codes.

5. What are the advantages and disadvantags of serialization?

The advantages of serialization are:


Serialization can also be used as a mechanism for exchanging objects between Java and C++ libraries

There are simply too many critical technologies that rely upon serialization, including RMI, JavaBeans and EJB.

It should ideally not be used with large-sized objects, as it offers significant overhead. Large objects also
significantly increase the memory requirements of your application since the object input/output streams cache
live references to all objects written to or read from the stream until the stream is closed or reset. Consequently,
the garbage collection of these objects can be inordinately delayed. The Serializable interface does not offer
fine-grained control over object access - although you can somewhat circumvent this issue by implementing the
complex Externalizable interface, instead. Since serialization does not offer any transaction control mechanisms

6. What's the difference between the ">>" and ">>>" operators?

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
">>" is a signed right shift, while ">>>" is an unsigned right shift.

difference between the operators is that the signed shift fills from the left with the sign bit (0 or 1), and the
unsigned shift zero-fills from the left.

7. What is Enterprise JavaBeans?

The official Sun Definition:


The Enterprise JavaBeans architecture is a component architecture for the development and deployment of
component-based distributed business applications. Applications written using the Enterprise JavaBeans
architecture are scalable, transactional, and multi-user secure. These applications may be written once, and
then deployed on any server platform that supports the Enterprise JavaBeans specification.

8. What is UML?

The Unified Modeling Language (UML®) is a language for specifying, constructing, visualizing, and
documenting the artifacts of a software-intensive system.

UML is a registered trademark of the Object Management Group, Inc.

9. How do I use the goto keyword?

While goto is a reserved word in Java, its usage is not permitted. You should consider using labeled breaks or
throw exceptions instead.

When should I use a "private" constructor?

When you don't want anyone outside the class to invoke that particular constructor.

The most common use that I see for private (and protected) constructors is in implementing singletons and
some types of object factories. Basically, you use a static method to manage the creation of one (or more)
instances of the class.

10. How can I refresh the contents in the JTable?

If you have added or removed something from the table, from the DefaultTableModel or your own TableModel,
the easiest whay to tell that the data in the model has changed is to call JTable.tableChanged (TableModelEvent
e). In the TableModelEvent you specify which rows and/or columns that has been updated

11. How can I use a JFileChooser to select a directory?

You can use the DIRECTORIES_ONLY option for the setFileSelectionModel method of JfileChooser

12. How can I determine the size of a Frame when I resize or maximize it?

To get notified when the frame is resized or maximized you need to register a ComponentListener on the frame.
In the call back componentResized(...) you could ask the frame for its size using frame.getSize()

13. How do I create directories in the local file system?

The File class includes mkdir() and mkdirs() methods that should help you. mkdir() will only make the file as a
directory, at the last level. What mkdirs() does is create all parent directories, too, if they do not exist.

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
14. What is a thread?

A thread is a set of instructions executing apart from other threads (with its own stack) but sharing the same
memory space (with the same heap).

15. What is the main difference between a preemptive scheduler and a non-preemptive scheduler?

A preemptive scheduler interrupts a thread of execution when its timeslice runs out. A non-preemptive (or
"cooperative") scheduler waits for the thread to yield control.

[Java native thread implementations are usually preemptive; the green-threads implementation is cooperative
but priority-preemptive, which means that when a high-priority thread becomes runnable, it immediately
becomes active]

16.What is UDP and how does it work?

UDP stands for User Datagram Protocol. UDP provides an unreliable packet delivery system built on top of the
IP protocol. As with IP, each packet is an individual, and is handled separately

UDP packets can arrive out of order or not at all. No packet has any knowledge of the preceding or following
packet.

17. How can I implement destructors in Java?

Generally, you won't need to - the most common usage of destructors in C++ is to free memory - and java will do
that for you automatically via "garbage collection" (GC). :)

We generally use to free resources like live database connections and other programatically created system
resources which may be live even after the scope of that class program. Also you can request the the system to
execute the Garbage collecter thread by firing System.gc()

18. What is an overloaded method?

Overloaded methods are multiple methods in the same class that share the same name but have different
parameter lists and return type. Overloaded methods cannot have the same parameter lists with different return
types

19. What is a final class?

When you declare a class to be final, it can never be subclassed. This is usually done for security or
performance reasons.

public final class Math {


// ...
}

20. What is a final method?

When you declare a method to be final, it can never be overridden in subclasses. This is usually done for
security or performance reasons, providing additional information to the JIT compiler or HotSpot. One word of
caution -- making methods final restrict later design decisions.

21. Why do I not have to import the classes in the java.lang package?

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
The classes in the java.lang package are so important that the compiler implicitly imports all the classes there.
This ensures classes in the unnamed package are not accidently used instead of the key classes and interfaces.

22. Can I restart a stopped thread?

In short, no. Once a thread is stopped, it cannot be restarted. Keep in mind though that the use of the stop()
method of Thread is deprecated and should be avoided.

23. What is a software design pattern?


A design pattern is a solution to a general software problem within a particular context.
Context :A recurring set of situations where the pattern applies. Problem A system of forces (goals and
constraints) that occur repeatedly in this context.
Design patterns capture solutions that have evolved over time as developers strive for greater flexibility in their
software. Whereas class libraries are reusable source code, and components are reusable packaged objects,
patterns are generic, reusable design descriptions that are customized to solve a specific problem.

24. What is an analysis pattern?

An analysis pattern is a software pattern not related to a language or implementation problem, but to a business
domain, such as accounting or health care. For example, in health care, the patient visit activity would be
subject to a number of patterns.

25. What is Jini?

Jini network technology is an open architecture that enables developers to create network-centric services --
whether implemented in hardware or software -- that are highly adaptive to change. Jini technology can be used
to build adaptive networks that are scalable, evolvable and flexible as typically required in dynamic computing
environments.

26. What are the differences between instance and class variables?

Instance variables have separate values for each instance of a class. Class variables maintain a single shared
value for all instances of the class, even if no instance object of that class exists.You would use the static
keyword to change an instance variable into a class variable.

27. What is a deprecated API?


As classes evolve, their API change. To signal to developers that they are using an antiquated feature, class
designers can flag classes or methods as deprecated. When used, the compiler will warn you of the invalid
usage.

While deprecated classes and methods are still available for usage, at some future time it is possible that they
will be dropped from the libraries.

28. What character escape sequences are available in Java?

Java provides escape sequences for several non-graphical characters. All characters can be specified as a
hexidecimal Unicode character (\uxxxx) with some as an octal character (\ddd where the first d is limited to 0-3,
and the others 0-7 - same as \u0000-\u00ff). The actual character literals are: \b - backspace
\t - tab
\n - linefeed
\f - formfeed
\r - carriage return
\" - double quote
\' - single quote
\\ - backslash

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY

29. What's a .jar file?

A JAR file or Java ARchive is a way of bundling multiple files together as a single file. Like a ZIP file, they
support compression and retain the directory structure of the files. They can be used for delivering things like
JavaBeans and Applets, and usually include support files like image and sound files, in addition to the actual
Java classes. In addition, they can be digitally signed so a user can grant privileges to allow the software to
perform operations not normally permitted from untrusted software.

30. How do you sort the elements of a vector?

Since the Vector class implements the List interface, you can call the Collections.sort() method to sort the
elements in place

31. Growth Of Vectors

The vector constructor can include either an initial capacity or a capacity and growth increment. When not
specified, the initial size of the vector is 10 and growth will double when necessary. Otherwise, initialize size and
growth will grow when needed as specified by the arguments to the constructor. If the argument to the
constructor is a collection, the initial size of the internal structure is 10% larger than the collection. Since there is
no second argument to control growth, the capacity will double when necessary.

32. What is green thread?


Java has two types of threads namely user thread and daemon thread.

Daemon Thread:
It is simply a background thread that is subordinate to the thread that creates it, so when the thread that created
the daemon thread ends, the daemon thread dies with it.You make a thread daemon thread by calling it's
setDaemon() with argument true.When you create a thread its priority will be the same as that of the thread that
created it.

User Thread:
A thread that is not a daemon thread is called a user thread.A user thread has a life of its own that is not
dependent on the thread that creates it.It can continue execution even after the thread that created it has ended.

I am hearing about green thread for the first time.Here is the info that I found on the internet regarding Green
threads.Hope it will be helpful for you

Green threads are the default threads provided by the JDK. Native threads are the threads that are provided by
the native OS:

Native threads can provide several advantages over the default green threads implementation, depending on
your computing situation.

Benefits of using the native threads:

If you run Java code in a multi-processor environment, the Solaris kernel can schedule native threads on the
parallel processors for increased performance. By contrast, green threads exist only at the user-level and are
not mapped to multiple kernel threads by the operating system. Performance enhancement from parallelism
cannot be realized using green threads.

The native threads implementation can call into C libraries that use Solaris native threads. Such libraries cannot
be used with green threads.

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
When using the native threads, the VM can avoid some inefficient remapping of I/O system calls that are
necessary when green threads are used.

33. What is a Linked List ?

Ans: A simple collection of similar nodes that are connected in a chain fashion. So if I have a object node, all i
need is node.data="some data"; and node.next=node; Remember that java will copy the pointer location in
this case..

34. Shallow Copy and Deep Copy


A shallow copy simply creates a new object and inserts in it references to the members of the original
object(new class containsreferences to the same data )
A deep copy constructs a new object and then creates in it copies of each of the members of the original
object(new class contains references to the new data)

35. RMI vs serialization

RMI uses serialization as its basic and only mechanism for sending objects across a network. If an object
implements java.rmi.Remote, then the object's stub is serialized and sent to the client. If the object implements
java.io.Serializable, then the object itself is serialized and sent.

36. What is a Bean? Why isn't a Bean an Applet?

JavaBeans components, or Beans, are reusable software components that can be manipulated visually in a
builder tool. Beans can be combined to create traditional applications, or their smaller web-oriented brethren,
applets. In addition, applets can be designed to work as reusable Beans.

Individual Beans will function quite differently, but typical unifying features that distinguish a Bean are:

• Introspection: enables a builder tool to analyze how a Bean works


• Customization: enables a developer to use an app builder tool to customize the appearance and
behavior of a Bean
• Events: enables Beans to communicate and connect together
• Properties: enable developers to customize and program with Beans
• Persistence: enables developers to customize Beans in an app builder, and then retrieve those Beans,
with customized features intact, for future use

37. Why swings are light weight compare to AWT components.?

When instantiating any of the AWT component classes, e.g. a java.awt.Button, the system actually asks the
native environment to create the component. This ensures the user sees the native look-and-feel and the
component acts like the native control. The native code that provides this look-and-feel is called a peer; each
platform has its own set of peers. A Java button appears and acts as a Windows button when run under
Windows, as a Macintosh button when run under Macintosh, and as a Unix button when run under Unix.

While in practice this sounds great, there are problems because not all native controls respond similarly to the
same events. This can result in a Java program exhibiting different behavior under different Java AWT
environments. To overcome this problem, you must use components written entirely in Java. That is,
components that do not have a native peer. These are called lightweight components. Swing provides a set of
pure Java lightweight components, ensuring better cross-platform compatibility

A lightweight component is one that subclasses java.awt.Component (or java.awt.Container) directly -


http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
implementing the look-and-feel of the component in Java rather than delegating the look-and-feel to a native
peer.

38. Is it possible that in a try-catch block, the code in the finally block do not execute ?

it is possible provided there is system.exit() written after the end of try block and the the code in try block does
not throw an exception , or the program crashes, but the person was not convinced. Is there someother reason,
can someone tell me?

39. What is the difference between these two?

public void synchronized aMethod() { ... }


and :
public void aMethod() {
synchronized (some_other_object) {
...
}
}

Ans:

the first method synchronizes the method and the second one locks an object for synchronization.The effects of
the second option can lead to horrendous runtime errors if not taken care of during coding.

40. What are the 3 important components of JVM?

There few components in JVM,But i am not sure of the which is important,I feel all are important ..
Few components are
Class load component
Runtime Component
Garbage/Memory managemnet component
Library component
Byte code component

Where is Implementation of a Resultset


In java.sql package mostly consists of interface,so where they are implemented?

Implementaion are specified in the JDBC driver

41. Enumeartion is an interface,Where do we implement it?


when we look at the API the implementation will be given StringTokenizer,

42. Difference between ht and hashmap?

Hastable is synchronized,
Hashmap is NOT
Hashtable does not allow NULL key and values
Hashmap allows Both

Default bucket size of Hastable is 101. And load factor is .75. That means once more then 75 element
are inserted into hastable JVM will create a new hastable with more bucket and all the element from
old hastable will be copied to new hastable. Old hastable will be distorted. This process is called
rehashing. You should avoid rehashing if you can to gain performance by calling correct constructor

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
that allows you to specify the bucket size. Some researcher says that bucket size should be a prime
number (like 101) to avoid collision.

43. Singleton class?

Singleton is design pattern to create only one instance of your class in one VM. Most of the time it is used to
control the resources like database connection and socket connection.

The key to prevent making two instances is, Make the constructor private and create public static getInstance
method that returns the object of your singleton class. Two possible implementations are as follows.

44. when finally block would not execute?


1. an exception within the finally block itself
2. the death of a thread
3. turning off the power to the CPU
4. use of system.exit()

45. Why do u decalare a Constructor PRIVATE on what sitution you do this ?What is the use of it?

if you are going for a Singleton

46. Is the main method in java can beoverloaded


Yes

47. can JVM call the overloaded main method "main(string arg)" to start the application ?

no. Because whatever argument you pass, JVM will convert it to Array of string and will call standard "public
void static main(String[] args)" method.

48. Multiple Inheritance vs Multilevel inheritence?

Multiple Inheritance is that you extend from more than one class which is not permitted in java

Multilevel inheritance is that a class extending from another class which itself might extend from another class
and so on.. For instance

class A

Class B

Class C

etc etc

49. why java avoids multiple inheritence?

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
Well One reason for java to avoid Multiple inheritance is to avoid the famous Diamond problem. say for instance

Class A

Field A

--------------------------------

| |

Class B Class C

| |

-----------------------------------------------

Class D

Here Class D has 2 parent classes Class B and Class C . ClassB and ClassC themeselves extend from Class
A. The field A in ClassA is now available as an inherited field in ClassB and ClassC. A copy of the same Field will
be available in ClassD as well. If you access FieldA in ClassD .. It will be a very ambiguous access as it would
have recieved 2 copies of FieldA one from ClassB and other from ClassC. This creates a lot of confusion and in
C++ to avoid this u go for virtual inheritance.. To avoid this whole set of confusion msut be one of the reasons for
Java not supporting multiple inheritance

50. What is cloneable interface?

Clonable interface has only one method “clone”.

You use the clone method to create an object from an existing object. That is to create a clone of it.

When do you need to clone? Depends on you application. For example when want to do some changes in the
state of an object but later want to do rollback to pervious state. The best way is keep original object safe and do
all experiment on clone of it.

Here is some more interesting information on Clonable interface.

To make an object clonable just implement Clonable interfaces, override the clone method defined in
java.lang.Object call and super.clone() in the overridden method. Well!! It is not so simple as it sounds. Calling
super.clone do field-by-field copy. That means if you have an object as member variable rather then primitive
data type, member object is cloned as reference not by value. To clone it’s value you need to call
memberObejct.clone() too. You are lucky if memberObejct is clonable otherwise you need to repeat the same
exercise first for memberObejct class and then come back to original class, It may turn to a recursive exercise
of you.

Sounds confusing?. Here is simple program to do experiment. Run it first it as it is. Then comment the line
“clone.items = (Vector)items.clone(); // clone the vector” and see the difference yourself.

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
import java.util.*;
public class Stack implements Cloneable {
private Vector items;
int num;
public Stack() {
items = new Vector();
items.addElement("Java");
items.addElement("J2EE");
num=10;
}
protected Object clone() {
try {
Stack clone = (Stack)super.clone(); // clone the stack
clone.items = (Vector)items.clone(); // clone the vector
return clone; // return the clone
} catch (CloneNotSupportedException e) {
// this shouldn't happen because Stack is Cloneable
throw new InternalError();
}
}
public static void main(String[] args) {
Stack orignal = new Stack();
Stack cloned = (Stack)orignal .clone();
orignal.items.addElement("JSP");
orignal.num=100;
System.err.println("orignal num = " + orignal.num );
System.err.println("Cloned num = " + cloned.num );
System.err.println("orignal items = " + orignal.items );
System.err.println("Cloned items = " + cloned.items );
}
}

The correct program results are


orignal num = 100
Cloned num = 10
orignal items = [Java, J2EE, JSP]
Cloned items = [Java, J2EE]

Once you comment the line “clone.items = (Vector)items.clone();// clone the vector”
orignal num = 100
Cloned num = 10
orignal items = [Java, J2EE, JSP]
Cloned items = [Java, J2EE, JSP]
Notice that in this version cloned vector’s data is same as original vectors’ data because clone is also referring
to original vector.
Someone on web has given a simple way of cloning. It’s really a simple way to clone a serializable object. Here
is the code.
ByteArrayOutputStream buf=new ByteArrayOutputStream();
ObjectOutputStream o=new ObjectOutputStream(buf);
o.writeObject(table);
ObjectInputStream in=new ObjectInputStream(new ByteArrayInputStream(buf.toByteArray()));
tableClone=(JTable)in.readObject();

51. Is Java Support Mutiple ,Return Types (i.e, more than one value as return type )

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
1. In Java, you do not directly deal with an object like in C++. You always deal with a reference to the Object.
Hence, Whatever Objects you pass to a method or function are passed by reference.

Any change made on these Object also effects change in the calling method. So, eventhough Java do not allow
you to return multiple value, you can always achieve by passing as a parameter to the method and making
changes to it.

2. U can create a spearte class and create object for it and can handle this situationObject can hold multiple
values Delare a class as well as the required parameters create instance of it so that uc an pass the instacnce
to called class

52. what are difference between Vector Vs. LinkList Vs. ArrayList Vs. Collection

A Collection is an interface.

A List is an interface which extends Collection. It may contain duplicate elements.

Vector, LinkedList and ArrayList are all implementations of List. A Vector and an ArrayList are basically the
same, except access to a Vector's elements are synchronized, with corresponding performance penalties. They
are also both dynamically resizable.

A LinkedList is not dynamically resizable.

A Hashtable is an implementation of a Map. A Map is an interface like Collection, except it has key-value pairs. A
Hashtable has synchronized access to its elements, like a Vector.

53. How to Run a Java Application Without main()

Create one class similar to the following, add codes within the static block, and run the application.

For example:
public class A
{
static void displayMe()
{
System.out.println("I'm inside display Me method");
}
static
{
System.out.println("without main i'm visible to u");
// call a static function
displayMe();
}
}

54. What are Checked and Unchecked Exceptions?

An unchecked Exception is either a RuntimeException or an Error; basically, RuntimeExceptions are


Exceptions which are due more to logic errors or design flaws.

55. bWhat are mutable objects & immutable objects


mutable objects are objects which can change their values and immutable objects are objects which cannot
have their values changed.

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
java.lang.String is immutable
java.lang.StringBuffer is mutable

56. What are the differences between System.gc() and Runtime.gc()?

System.gc() and Runtime.gc()are moreover equivalent


System.gc() is static method
Runtime.gc() is a native method

57. What is a weak reference?

A weak reference is one that does not prevent the referenced object from being garbage collected. The GC will
send some sort of "finalize" message to the object and then set any weakly-referencing variables to null
whenever it disposes of the referenced object. This allows "finalization" logic to be run before the object is
disposed of (e.g., close a file if still open, commit any open transaction(s), etc.). Java 1.1 does not support weak
references other than via an undocumented Ref class that is not supported under Netscape. Weak references
arrived officially with JDK 1.2. Java has three kinds of weak references, called soft references, weak references,
and phantom references, in order of increasing weakness.

• Soft references are garbage collected only when memory is low.


• Weak references are garbage collected on a gc even when memory is abundant.
• Phantom references point to objects that are dead and have been finalised.

58. the differences between "JVM" and "JRE"?

Technically, the term "JVM" specifies the Java Virtual Machine. I.e., the "JVM" is the definition of the abstract,
stack-based computational engine used to execute Java bytecodes. The term "JRE" stands for the Java
Runtime Environment (if you follow Sun's nomeclature) or, interchangeably, Java Runtime Engine. I.e., a JRE is
a specific implementation of the the JVM, including the core libaries.

59. Suppose you create an object from a superclass and assign that object's reference to a superclass
variable. Suppose you cast that variable's type from the superclass type to a subclass type before
accessing a subclass field or calling a subclass method. What happens?

during runtime the cast fails because the object is of superclass type and not subclass type.

60. Must a subclass constructor always call a superclass constructor?

Yes..be default it calls superclass's default no arg constructor

61. Explain two uses for the super keyword.

to access super call fields and methods also used foe invoking superclass constructor

62. By default, what does an object's toString() method return?


classname#hashcode

63. What are hash codes?

The code use to speed lookup of objects in collection. you will invoke hashcode() method of an objects to get
hashcode

64. When does method overloading fail?

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
65. Why can't a class signature include both the abstract and final keywords?

Abstract methods are to implemented by a subclass. Final means that a method cannot be overriden, since both
are contradictory, abstract methods annot be final.

66. If a subclass constructor does not include a call to a superclass constructor (via super) or another
subclass constructor (via this), what happens?

if there is a default constructor in the superclass,it gets invoked else subclass fails to compile.

67. Connection Pooling & instance pooling?

Connection pool is nothing but ready to use pool of database connections whereas instance pool is nothing but
a pool of java objects(For e.g. instance pooling of state less session bean ..this means less overhead and time..)

68. Array Length can be Zero ?

array length can be zero. like in this code:


private void showLength() {
int arr[] = new int[0];
System.out.println(arr.length);
}

69.Among Below Which is Thread Safe?and Why ?

ArrayList
Vector
Hashpmap
Hastset
LinkedList
List

Vector is synchronized. So are Stack,Hashtable and


Properties.
But the new Collection classes(older ones are called
Histrical Collection classes)like
ArrayList,HashMap,HashSet are not synchronized

70. What is the differnce between Thread and Process?

A process is a separate group of Threads. Every program generates its own process. If you create a Thread in
your Java program, it runs in the process that was created when the JVM started. You create a Thread to do
something internally in your program, and you create a process to run a separate program.

71. What are the Heavy Weight Component in SWING

In Swing most of the component are Light weight ,but few components are heavy weight ,name some :)
JWindow, JFrame, JDialog, and JApplet are heavy weight components in Swing.

72. What is threadsafe?

An object is called thread safe if can be accessed(modified) simultaneously by multiple threads without the
object being corrupted.

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY

73. XML Schema?

XML schema defines the structure and constraints of a XML document. XML SCHEMA WAS RECENTELY
INTRODUCDED(MAY 01)IT CONTAINS MORE FEATURES THAN DTD..

74. could any of u give me the difference between thin client and thick client.

In thin client ,mainly the process/logic is done in the server side ,Webbrowser is a thin client,since the logic is
done in the server side ,and only the view is done in clientThick client is where the logic/process is done mainly
in client side like VB applications !

75. Why you cannnot create a Object for Interface ?

interface and abstract classes have methods either unimplemented or half implemented so we cannot have their
objects.

76. What are transient variables.

Variables that have access modifier 'transient' will not be read from or written into streams. It gives facility to
avoid writing unnecessary data into streams. In other words, it boosts the performance by avoiding writing
unnecessary data into streams.

77. Daemon threads?

Demoan threads are thread that are intended to do some background work. Garbage collection is an example
for such a thread. Deamoan threads exist only if there are user threads executing. use setDemoan(true) to make
a thread demoan.

78. Why is HTTP port usually kept open in an firewall. Why are others ports closed.

IMO,Since plain HTTP web traffic is normally considered as safe,most of the organisations open this port and its
associate HTTPS port.

79. Why does not any system.out.println prints anything from finalize method.

It is not mandatory for GC to call finalize method.So Any print statements in such a method will not be printed.

80. Private in main methods ?

This is a bug in java implementation. Even though Sun said it would not fix the bug surprisingly this does not
workwith v1.4. Gives an error message "Main method not public". U can try it out.Hope this helps.

81. What happens when u override the hashCode() of object class method?

Its a callback method provided by the EJB specification.Immediately after the bean is created,if you want to
perform any initialisation before the bean is ready for servicing the clients,you can use the ejbPostCreate()
method.

82. HTTP
HyperText Transfer Protocol. Used by Web browsers and HTTP-capable programs.

83. HTTPS
http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
Hypertext Transfer Protocol over Secure Sockets Layer (SSL). Used by Web browsers and HTTPS-capable
client programs.

84. T3
WebLogic T3 protocol for Java-to-Java connections, which multiplexes JNDI, RMI, EJB, JDBC, and other
WebLogic services over a network connection.

85. T3S
WebLogic T3 protocol over Secure Sockets Layer (SSL).

86. RMI
Remote Method Invocation (RMI), the standard Java facility for distributed applications.

87. IIOP
Internet Inter-ORB protocol, used by CORBA-enabled Java clients to execute WebLogic RMI objects over IIOP.
Other CORBA clients connect to WebLogic Server with a CORBA naming context instead of a URI for
WebLogic Server.

88. IIOPS
Internet Inter-ORB protocol over Secure Sockets Layer (SSL).

89. SOAP
WebLogic Web Services use Simple Object Access Protocol (SOAP) 1.1 as the message format and HTTP as a
connection protocol.

90. What is facade?

Fascade Pattern in used to hide the low level implemention from high level implementaion.U can achive this by
writing a intermedaite class between u r application logic and user interface ..It is also used as intermedaite
class between a legacy system and other sys

91. What is Abstract Factory?

It is moroever like your abstarct class and impletion for it

92. what is locale?

It is used for local georaphic or money represtions ,etc

93. How is runtime Polymorphism achieved in java.?

Dyanmic Method Dispatch ...assiging a object refence in runtime ...

94. what is Interface ? if we don’t use the abstract word in an interface method? will it through error.?

Interface is one which have only method body no implemnation ..

No It wont create error .... since all the methods in interface are abstarct

95. Can static method be used in servlets? Is it of any use?

U can have static methods in servlet,but it doesnt make any sense

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
96. What is the load balancing formula in weblogic?

1.Round robin
2.Weight based
3.Random

97.Can we restrict the number of session in servlets?

Regarding limiting number of sessions in a web app it is specific to a server.

98. Difference between private and final?

Final - The values cannot be modified if they are variables, they cannot be overrided or overloaded if they are
methods, they cannot be extended if they are classes.

Private - no access to that variable,method or classwhich are private from outside the class.So having aclass as
private is of no use.

99. which of the Collection implementations r thread safe


a)HashSet
b)TreeSet
c)Vector
d)LinkedList
e)ArrayList

ans: c

100. which of the following r using to store unique elemnts


a)Vector
b)Set
c)SortedSet
d)Map
e)List

b,c
in map key is unique

101. following is the web application web.xml


<listener-class>class1.class</listener-class>
<listener-class>class2.class</listener-class>
<listener-class>class3.class</listener-class>
<listener-class>class4.class</listener-class>

which of the class initialized first and their order of initialization...on application shutdown..which of
these classes notified in order....or the order cant be predicted....

in the order listed above

102. Java Run time environment manages memory for java applications
a)True
b)false

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
103. can 2 JVMs at one m/c?

yes

104. JVM can be installed as hardware also?


True or false

pico java is an example

105. Does a method defined static will automatically become a synchronized method?

No

106. What is the difference between ejb and java bean?

EJB is an distributed enterprise component which supports various builtin services like persistence,transaction,
security,pooling etc.

Javabean is a lightweight component to represent a data along with setters/getters for mutating/accessing data.

107. What is the difference between Aggregation and composition?


Aggregation is an association(relation between 2 instances of classes) in which one class belongs to a
collection.
A composition is a parent-child relation where the child cannot exits without the parent.something like the on
cascade delete of oracle

108. What is the Purpose of Resource Bundale?


Internationalisation:Can easily support multiple locales.Other use may be the ability to configure/customise the
application without changing the src code.

109. What is the difference between localization and Internationalization

l10n is a way of customising an internationalised app to a specific locale.where as i18n is the way of supporting
multiple locales(regions) in a single app.

110. In comparator how you will compare two objects?


Will implement the compareTo method and write my logic

111. What is small-grained application and coarser-grained application ?

Java Bean is small-grained application

EJB is coarser-grained application

112. what is the difference between instance and an object?

Class nObj; **********Instance

nObj = new Class *********Object

113. Object vs. Instance - These are the same thing, although 'instance' suggests an object that you created
using 'new', while 'object' would suggest all objects. Strings and numbers are certainly objects, though in fact
they are also instances, created with an internal string or number constructor. Usually the word instance does
not refer to these types of objects, but again, you can usually tell from the context. There, that should fog things
up nicely for you.

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
114. What is the difference of calling a thread as thread.start()and thread.run()

Calling the start method starts the thread. The start method in turn calls the run method after the thread is
started. Calling the run method does not start the thread at all. It is as good ascalling some method on an object.
When run method is called directly the code in the method gets executed without any thread being started.
Calling run() instead of start() causes the run method to run in the current thread. You need to call start() instead
of run() to actually run code in another thread.

Dont ever call run in place of start. Start is actually a native method.
class Foo extends Thread {
public void run (){
//do some stuff
}
public void main (String [] args){
Foo foo1 = new Foo();
Foo foo2 = new Foo();
Foo foo3 = new Foo();
//the following will cause the thread objects to run sequentially
foo1.run();
foo2.run();
foo3.run();
//the following will start the thread objects executing concurrently
foo1.start();
foo2.start();
foo3.start();}}

115. Can I use my own object as a key to the HashMap or HashTable ? If Yes How?
Yes you can. For eg.

Hashtable hash = new Hashtable();


Vector vec = new Vector();
vec.addElement("String1");
vec.addElement("String2");
hash.put(vec, "Hello");

hash.get(vec) will return "Hello"

116. what is the difference between Strings and Stringbuffer in terms of memory management. Not just
Mutable or Immutable ans enough .?

Strings are static. meaning the values in it cannot be changed dynamically. If you want to use dynamic strings
then use string bufffer.

StingBuffer is a dynamic growing string meaning any values can be appended or inserted or in any part of the
sting.

in terms of performance:-
say
-------------------------------
String s = new String();

for (int i=0; i, i<100; i++)


{
s = s+"a";
}

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
-------------------------------
StringBuffer sb = new StringBuffer();
for(int i=0; i<100; i++)
{
sb.append("a");
}

when u compare in terms of performance, the second one will be more faster infact it will ba almost 50-60%
improvement.

this is because:
StrinBuffer intern manuplates the string concatination. while in the previous case, a new string is created every
time in the loop.

117. Can you give an example where static classes are used? or do you know any class in Java API
which has static classes? what are uses of static/inner classes?

118. What are the different types of XML parsing?


SAX AND DOM

119. What is the difference between application servers and web servers??
Web server perform just request and response .. where as Application server perform additional
features such connection pooling,transaction,loadbalancing ,security etc

A Web Server understands and supports only HTTP protocol whereas an Application Server supports
HTTP,TCP/IP and many more protocols. Also many more features such as Caches,Clusters,Load Balancing are
there in Application Servers which are not available in Web Servers. We can also Configure Application Servers
to work as Web Server. In short, Applicaion Server is a super set of which Web Server is a sub set.

120. How do I make a class that supports cloning?

To be cloneable, your class must at least implement the Cloneable interface.

121. What is conditional compilation in Java ? How can I implement conditional compilation in Java?
There is no conditinal compilation in java. You can implement conditional compilation in java using c
compiler on the top of java.

122. What are the differences between Web site and Portal?

In Portal, contents are from different parties where as in website , contents will belong to single party.

E.g., go to my.yahoo.com

u can see contents like quotes, weather, news from different sources. It is a portal.

123. what is association,aggregation and composition? what is the difference between them?
Association : A formal organization of people or groups of people /The state of being connected
together as in memory or imagination

Aggregation : Several things grouped together(accumulation)

Composition : A mixture of ingredients / The way in which someone or something is composed

123. main method will not return anything,they have void but how does the JVM recognozie it ? without
any return type? whats the problem if you have a retrun typpe in main method?

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
In previous issues we've mentioned that Java(tm) has no sizeof() operator like C/C++. With uniform sizes for
primitive data types, and a different style of memory allocation, the need for sizeof() really isn't there. And it's
hard to define what sizeof() would mean anyway, given that an object may not contain other objects, but only
references to them.

124. Why can there be only one public class in a java file?

When ever a java file contains a reference to a class the complier can compile the refernecd clas just be the
class.java.

For e.g. in A.java


B b = new B();
The compiler will find whether B, just by searching for B.class.
If there were no restrcition then compiler would have to search lots of files. Thas bad, isn't?
This work only for public file but we most of the time we will be using public classes.

125. the methods wait(),notify(),notifyall() are all used in thread programming....but these methods are
available in object class rather than in thread class or runnable interface...why is it so....

Ordinary classes can call wait, notify and notifyAll methods as well as long as they are in synchronized block. By
default, the class that we make extends Object, that is why these methods are defined in Object. Indeed. In fact
you could actually call any one of these methods in main() and they would work fine. Even the sleep() method
(which also derives from class Object) would work when called within main(). These methods are NOTHING
unique to the Thread class.

126. Is there any way which is equivalent to serlizable ? Or How to send objects across networks
without implementing serlizable In doing so what is the advantage of it ?

You can use Externizable interface.

127. What is the diff b/w Serialization and Externalization,At what occasion Externalization can be
useful.As in Serialization ,Serialized object can be deserialized and does the same thing applies to
Externalization ???

Externalization takes serialization one step further. Externalizable is an interface that extends Serializable.
Classes can implement Externalizable interface and gain the fine-grain control over the way the object gets
serialized by overriding readExternal(ObjectInput in) and writeExternal (ObjectOutput out ) methods. During
serialization, if the class implements Externalizable, then the overridden methods are called. On the otherhand,
if the class implements only Serializable, you'll get the plain vanilla object serialization.

128. Externalization vs serialization


Externalization allows you to customize how serialization is done. By implementing externalization you are
controlling what gets serialized ( and what doesnot ) as versus default serialization where all non-transient
attributes get serialized.

For "fat data" classes with a large number of attributes only a few of which needs to persisted, externalization
will help you reduce the size of serialized stream and the time taken to serialize the object.

129. Like in C (sizeof()) is there any method in java to know abt the size of the object
In previous issues we've mentioned that Java(tm) has no sizeof() operator like C/C++. With uniform sizes for
primitive data types, and a different style of memory allocation, the need for sizeof() really isn't there. And it's
hard to define what sizeof() would mean anyway, given that an object may not contain other objects, but only
references to them.

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY

130. What is the difference between Trusted and Untrusted Applet ?

131. List the four polymorphism categories.

132. Class can only extend one superclass. Is an interface subject to the same restriction (that is, can an
interface only extend a single superinterface)?

133. If you do not declare a class to be public, must you declare it in a file whose filename matches the
class name? For example, must you declare class Account {} in Account.java?

134.What is resource bundle?

135. What is development components and deployable components ?

136 How to stop thread? 1) stop(), suspend(), resume() are deprecated.


2) Using a boolean variable. This variable is set to false for stopping thread.

137. Let's say I've a class A which is Serialized. I create another class B extending A, Class C extending
B. Now, I've to make the class B deserialized. However C should remain Serializable.

138. How do you know that two objetcs are instacne of the same class

http://groups.yahoo.com/group/jiny JINY

S-ar putea să vă placă și