Monday, August 24, 2009

Core Java Interview Questions -2


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 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

No comments:

Post a Comment