23-12-2009, 06:07 AM | #11 |
Member
Join Date: Dec 2009
Posts: 33
Rep Power: 0 |
What do you understand by numeric promotion?
In the numerical promotion process the byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required. |
23-12-2009, 06:08 AM | #12 |
Member
Join Date: Dec 2009
Posts: 33
Rep Power: 0 |
What do you understand by casting in java language? What are the types of casting?
The process of converting one data type to another is called Casting. There are two types of casting in Java; these are implicit casting and explicit casting.
Implicit casting is the process of simply assigning one entity to another without any transformation guidance to the compiler. This type of casting is not permitted in all kinds of transformations and may not work for all scenarios. Example int i = 1000; long j = i; //Implicit casting Explicit casting in the process in which the complier are specifically informed to about transforming the object. Example long i = 700.20; int j = (int) i; //Explicit casting |
23-12-2009, 06:09 AM | #13 |
Member
Join Date: Dec 2009
Posts: 33
Rep Power: 0 |
How can one prove that the array is not null but empty?
Print array.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 array.length.
|
23-12-2009, 06:11 AM | #14 |
Member
Join Date: Dec 2009
Posts: 33
Rep Power: 0 |
Can I have multiple main methods in the same class?
We can have multiple overloaded main methods but there can be only one main method with the following signature :
Code:
public static void main(String[] args) {} |
23-12-2009, 06:11 AM | #15 |
Member
Join Date: Dec 2009
Posts: 33
Rep Power: 0 |
Explain working of Java Virtual Machine (JVM)?
JVM is an abstract computing machine like any other real computing machine which first converts .java file into .class file by using Compiler (.class is nothing but byte code file.) and Interpreter reads byte codes.
|
23-12-2009, 06:12 AM | #16 |
Member
Join Date: Dec 2009
Posts: 33
Rep Power: 0 |
How can I swap two variables without using a third variable?
Add two variables and assign the value into First variable. Subtract the Second value with the result Value. and assign to Second variable. Subtract the Result of First Variable With Result of Second Variable and Assign to First Variable. Example:
Code:
int a=5,b=10;a=a+b; b=a-b; a=a-b; You use an XOR swap. for example: Code:
int a = 5; int b = 10; a = a ^ b; b = a ^ b; a = a ^ b; |
23-12-2009, 06:13 AM | #17 |
Member
Join Date: Dec 2009
Posts: 33
Rep Power: 0 |
What is data encapsulation?
Encapsulation may be used by creating ‘get’ and ’set’ methods in a class (JAVABEAN) which are used to access the fields of the object. Typically the fields are made private while the get and set methods are public. Encapsulation can be used to validate the data that is to be stored, to do calculations on data that is stored in a field or fields, or for use in introspection (often the case when using javabeans in Struts, for instance). Wrapping of data and function into a single unit is called as data encapsulation. Encapsulation is nothing but wrapping up the data and associated methods into a single unit in such a way that data can be accessed with the help of associated methods. Encapsulation provides data security. It is nothing but data hiding.
|
23-12-2009, 06:14 AM | #18 |
Member
Join Date: Dec 2009
Posts: 33
Rep Power: 0 |
What is reflection API? How are they implemented?
Reflection is the process of introspecting the features and state of a class at runtime and dynamically manipulate at run time. This is supported using Reflection API with built-in classes like Class, Method, Fields, Constructors etc. Example: Using Java Reflection API we can get the class name, by using the getName method.
|
23-12-2009, 06:14 AM | #19 |
Member
Join Date: Dec 2009
Posts: 33
Rep Power: 0 |
Does JVM maintain a cache by itself?
Does JVM maintain a cache by itself? Does the JVM allocate objects in heap? Is this the OS heap or the heap maintained by the JVM? Why
Yes, the JVM maintains a cache by itself. It creates the Objects on the HEAP, but references to those objects are on the STACK. |
23-12-2009, 06:15 AM | #20 |
Member
Join Date: Dec 2009
Posts: 33
Rep Power: 0 |
What is difference between String and StringTokenizer?
A StringTokenizer is utility class used to break up string.
Example: Code:
StringTokenizer str = new StringTokenizer(”Hello World”); while (str.hasMoreTokens()) { System.out.println(str.nextToken()); } Hello World |
Bookmarks |
Tags |
java interview question |
|
|