Java is a programming language expressly designed for use in the distributed environment of the Internet. It was designed to have the "look and feel" of the C++ language, but it is simpler to use than C++ and enforces an object-oriented programming model. Java can be used to create complete applications that may run on a single computer or be distributed among servers and clients in a network. It can also be used to build a small application module or applet for use as part of a Web page. Applets make it possible for a Web page user to interact with the page.
The major characteristics of Java are:
The programs you create are portable in a networkThe code is robust.Java is object-oriented.In addition to being executed at the client rather than the server, a Java applet has other characteristics designed to make it run fast.
Relative to C++, Java is easier to learn. (However, it is not a language you'll pick up in an evening!)
Java was introduced by Sun Microsystems in 1995 and instantly created a new sense of the interactive possibilities of the Web. Both of the major Web browsers include a Java virtual machine. Almost all major operating system developers (IBM, Microsoft, and others) have added Java compilers as part of their product offerings.
The Java virtual machine includes an optional just-in-time compiler that dynamically compiles bytecode into executable code as an alternative to interpreting one bytecode instruction at a time. In many cases, the dynamic JIT compilation is faster than the virtual machine interpretation.
Core Java Interviews are getting tough these days as the technology grows faster. To get through the Core Java interview one needs to update him/herself in a regular manner. Having said that, just before the interview, it is very important to have a quick glance of the reputed Core Java questions and answers to make yourself comfortable during the interview process. This is where DoAnswers.com helps you in renewing yourself on Core Java and various other technologies interview preparation.
21. Can try statements be nested?
Yes
22. Can we define private and protected modifiers for variables in interfaces?
No
23. Can we Serialize static variable?
Serialization is the process of converting a set of object instances that contain references to each other into a linear stream of bytes, which can then be sent through a socket, stored to a file, or simply manipulated as a stream of data. Serialization is the mechanism used by RMI to pass objects between JVMs, either as arguments in a method invocation from a client to a server or as return values from a method invocation. In the first section of this book, There are three exceptions in which serialization doesnot necessarily read and write to the stream. These are 1. Serialization ignores static fields, because they are not part of any particular object's state. 2. Base class fields are only handled if the base class itself is serializable. 3. Transient fields. There are four basic things you must do when you are making a class serializable. They are: Implement the Serializable interface. Make sure that instance-level, locally defined state is serialized properly. Make sure that superclass state is serialized properly. Override equals( )and hashCode( ). it is possible to have control over serialization process. The class should implement Externalizable interface. This interface contains two methods namely readExternal and writeExternal. You should implement these methods and write the logic for customizing the serialization process .... (Source: http://www.oreilly.com/catalog/javarmi/chapter/ch10.html)
24. Can we use the constructor, instead of init(), to initialize servlet?
Yes , of course you can use the constructor instead of init(). There?s nothing to stop you. But you shouldn?t. The original reason for init() was that ancient versions of Java couldn?t dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won?t have access to a ServletConfig or ServletContext.
25. Can we use the constructor, instead of init(), to initialize servlet? (Servlets)
Yes , of course you can use the constructor instead of init(). There's nothing to stop you. But you shouldn't. The original reason for init() was that ancient versions of Java couldn't dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won't have access to a ServletConfig or ServletContext.
26. Can you call one constructor from another if a class has multiple constructors
Yes. Use this() to call a constructor from an other constructor.
27. Can you instantiate the Math class?
You can't instantiate the math class. All the methods in this class are static. And the constructor is not public.
28. Can you make an instance of an abstract class? For example - java.util.Calender is an abstract class with a method getInstance() which returns an instance of the Calender class.
No! You cannot make an instance of an abstract class. An abstract class has to be sub-classed. If you have an abstract class and you want to use a method which has been implemented, you may need to subclass that abstract class, instantiate your subclass and then call that method.
29. Describe the principles of OOPS.
There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation.
30. Describe the visitor design pattern (General)
Represents an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates. The root of a class hierarchy defines an abstract method to accept a visitor. Subclasses implement this method with visitor.visit(this). The Visitor interface has visit methods for all subclasses of the baseclass in the hierarchy.