Documente Academic
Documente Profesional
Documente Cultură
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.
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.
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.
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
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.
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.
While goto is a reserved word in Java, its usage is not permitted. You should consider using labeled breaks or
throw exceptions instead.
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.
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
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()
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]
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.
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()
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
When you declare a class to be final, it can never be subclassed. This is usually done for security or
performance reasons.
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.
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.
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.
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.
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.
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
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.
Since the Vector class implements the List interface, you can call the Collections.sort() method to sort the
elements in place
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.
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.
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.
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..
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.
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:
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
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?
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.
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
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.
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.
45. Why do u decalare a Constructor PRIVATE on what sitution you do this ?What is the use of it?
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.
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
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
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.
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 );
}
}
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.
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 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.
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();
}
}
http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
java.lang.String is immutable
java.lang.StringBuffer is mutable
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.
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.
to access super call fields and methods also used foe invoking superclass constructor
The code use to speed lookup of objects in collection. you will invoke hashcode() method of an objects to get
hashcode
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.
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..)
ArrayList
Vector
Hashpmap
Hastset
LinkedList
List
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.
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.
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
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 !
interface and abstract classes have methods either unimplemented or half implemented so we cannot have their
objects.
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.
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.
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.
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
94. what is Interface ? if we don’t use the abstract word in an interface method? will it through error.?
No It wont create error .... since all the methods in interface are abstarct
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
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.
ans: c
b,c
in map key is unique
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....
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
105. Does a method defined static will automatically become a synchronized method?
No
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.
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.
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.
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();
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?
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.
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
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.
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 ?
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.
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
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?
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