Interview-Java
From DevRandom
See More Interview Questions Interview
Pointer differences in Java & C++
Java do have pointers; but not similar to the one that C has. In Java, Pointers are in the form of Objects/references. Also the pointers in Java are not explicit like C. probably JVM internally uses pointers. Every object is a reference to a location making it a pointer...these pointers cannot be directly manipulated. Differences between the C & Java pointers: 1) A pointer is a variable that holds the memory address of data. In Java there are only references, which do not hold any memory address, but which are indices in a table and this table has then the real pointer to the data. 2) Pointer Arithmetic is not possible with Java pointers.
How we can find the total number of processors available in system?
you find by using java.lang.Runtime.availableProcessors()
Can we serialize the static members?
No
what is the difference between encapsulation & abstraction?
encapsulationIt is process of enclosing or wrapping of data and functions with the help of classes is known as encapsulation. Encapsulation provide security to your code. It protect your data from unauthorised access etcAbstraction:is the process by which you will hide unwanted details from the user. It means the details which are needed for the user are only provided to him.
Why we need to serialize the object?
Serialization means to convert into byte stream ,we need to serialize object so that if many thread calls that function then consistentency should be maintained. If you are working with distributed apps, if we want to pass object over the network, only reference will be passed from client to the server. Then how can it refer object from server to the client memory...so object to be serialized means that all the fields to be converted into bytes and sent. The same to be deserialized as objects in the destination. So we can get the exact object what we have in the client. In case if we want certain fields not to be serialized, just use TRANSIENT when you declare variables.
WHAT IS THE DIFFERENCE BETWEEN MULTI-THREADING AND MULTI-PROCESSING?
Multithreading is the ability to perform different tasks of a process simultaneously.This is achieved by using a seperate thread for each task.Though there are several threads in a process, at a time the processor will handle only a single thread.Though it appears to be concurrent processing to the end user, internally only single thread will be running.Processor is able to multitask by switching between the threads.When it comes to Multiprocessing there will be more than one processor and each thread will be handled by a different processor.Thus leading to concurrent processing of tasks.
what is differents between object and static object?
static object is not there.only static variables,static methods r there.static variables means it will be shared by all the objects.static method means with out creating the object we can acess the method by class name . static method can only able to acess static variables....
why is multiple inheritance not allowed in java?
By not allowing the inheritance of multiple base classes by a single subclass, Java greatly simplifies the inheritance model. Multiple inheritance carries with it several special cases that must be handled. This adds overhead to both the compiler and the run-time system, while providing only marginal benefit for the programmer. Mutiple inheritance is highly complex OOPS concept and in most cases can be avoided.
Give an example of using JDBC access the database.
Answer: try { Class.forName("register the driver"); Connection con = DriverManager.getConnection("url of db", "username","password"); Statement state = con.createStatement(); state.executeUpdate("create table testing(firstname varchar(20), lastname varchar(20))"); state.executeQuery("insert into testing values(’phu’,'huynh’)"); state.close(); con.close(); } catch(Exception e) { System.out.println(e); }






