Basic Core Java Interview QUestions With Answers

Q. What is static variable?
Ans. A static variable is one that is not removed from memory after creation, even when it goes out of scope. The concept is very similar to that of a global variable, except that while a global variable is accessible from anywhere, a static variable is only accessible within certain parts of the program code.


Q. How will you pass values from HTML page to the Servlet?
Ans. We can pass values from HTMLpage to servlet using "request.getParameter(string);" method, which is a method in the HttpServletRequest interface.


Q. What is the difference between Hashmap and Hashtable?
Ans. HashMap is not Synchronized where as Hashtable is.
HashMap allows null as both key and value, where as Hashtable does not allow null.
HashMap retrieval is not in order (random) while Hashtable provides ordered retrieval.


Q. Can a lock be acquired on a class?
Ans. Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.


Q. What is the difference between the paint() and repaint() methods?
Ans. The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() tobe invoked by the AWT painting thread.


Q. What is the Collections API?
Ans. The Collections API is a set of classes and interfaces that support operations on collections of objects.


Q. What is the difference between the prefix and postfix forms of the ++ operator?
Ans. The prefix form performs the increment operation and returns the value of the increment operation. The postfix form returns the current value all of the expression and then performs the increment operation on that value.


Q. What is the difference between an Applet and an Application?
Ans. 1. Applets can be embedded in HTML pages and downloaded over the Internet whereas Applications have no special support in HTML for embedding or downloading.
2. Applets can only be executed inside a java compatible container, such as a browser or appletviewer whereas Applications are executed at command line by java.exe orjview.exe.
3. Applets execute under strict security limitations that disallow certain operations(sandbox model security) whereas Applications have no inherent security restrictions.
4. Applets don't have the main() method as in applications. Instead they operate on an entirely different mechanism where they are initialized by init(),started bystart(),stopped by stop() or destroyed by destroy().

 
Q. What is the difference between yielding and sleeping?
Ans. When a task invokes its yield() method, it returns to the ready state. When a task invokesits sleep()method, it returns to the waiting state.


Q. What value does readLine() return when it has reached the end of a file?
Ans. The readLine() method returns null when it has reached the end of a file.


Q. How does multithreading take place on a computer with a single CPU?
Ans. The operating system's task scheduler allocates execution time to multiple threads. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.


Q. What is the differences between script language and programming language?
Ans. Generally scripting languages can be used to validating the client side,it means reducing the burden on the server side and ruducing network traffic in order to facilitating the higher performance for client who will access application.It has some limitations when compared to programming languages.These limitations as follows:1.Scripting languages cannot support File operations.2. It does not support Database connections.3.It is not suited for network environment.

Q. Can we make construtor 'static'?
Ans. A constructor can never be declared as static, because the role of a constructor is to initialize the object variables and static is never involved with the object so constructor cannot be static


Q. Is there any way in java to find of size of an object ?
Ans. There is no particular command to find of size of an object in java (like sizeof() operator of C/C++ ) but you can check Runtime r = Runtime.getRuntime() ;r.freeMemory() ;before and after the creation of the new Object.By subtraction u can get the used memory.


Q. Can u kill thread manually. What is the disadvantage?
Ans. You can stop (kill) a thread by calling the method 'stop()' on the thread object. But it is not preferable to kill a thread, because it may cause system failure when writing to important data structures.


Q. What is casting?
Ans. There are two types of casting, casting between primitive numeric types and casting between objectreferences. Casting between numeric types is used to convert larger values, such asdouble values, tosmaller values, such as byte values. Casting between object references is used to refer toan object by acompatible class, interface, orarray type reference.


Q. Does a class inherit the constructors of its superclass?
Ans. No, A class does not inherit constructors from any of its superclasses.


Q. What is transient variable?
Ans. A transient variable is not stored with its Object; therefore, it is not serialized when the method writeObject( ) is invoked.


Q. Can the abstract class be final?
Ans. No the abstract class cannot be final, coz the main purpose of the creating abstract class is to inherit them and override there methods. If it is made final then the main purpose of the creating the abstract class is violated. i.e we can't inherit those classes.


Q. In How many ways we can request the System for the garbage collection to cleanup the memory?
Ans. There are 2 ways -
1) System.gc();
2) RunTime r = RunTime.getRunTime();r.gc();


Q. What happens when a thread cannot acquire a lock on an object?
Ans. If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object's lock, it enters the waiting state until the lock becomes available


Q. Can a lock be acquired on a class?
Ans. Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.



Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email


Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email