Java Interview Questions - part 7 of 7

What are the steps involved in Applet development?
Following are the steps involved in Applet development:
Create/Edit a Java source file. This file must contain a class which extends Applet class.
Compile your program using javac
Execute the appletviewer, specifying the name of your applet’s source file or html file. In case the applet information is stored in html file then Applet can be invoked using java enabled web browser.
----------------------------------------------------------------------------------------------------------------

Which method is used to output a string to an applet?
Which function is this method included in?
drawString( ) method is used to output a string to an applet. This method is included in the paint method of the Applet.
----------------------------------------------------------------------------------------------------------------

Why we can not extends two classes in Java?
Trying to extend 2 classes, or multiple inheritence, would result in a few problems. One of it is when you use the super() method. If you use that while extending more then 1 class, which superclass are you referring to then? Java solves this problem by thus using implementations for its multiple inheritence purposes.
----------------------------------------------------------------------------------------------------------------

What gives Java its “write once and run anywhere” nature?
Java is compiled to be a byte code which is the intermediate language between source code and machine code. This byte code is not platorm specific and hence can be fed to any platform. After being fed to the JVM, which is specific to a particular operating system, the code platform specific machine code is generated thus making java platform independent.
----------------------------------------------------------------------------------------------------------------

What are the four corner stones of OOP?
Abstraction, Encapsulation, Polymorphism and Inheritance.
----------------------------------------------------------------------------------------------------------------

Difference between a Class and an Object?
A class is a definition or prototype whereas an object is an instance or living representation of the prototype.
----------------------------------------------------------------------------------------------------------------

What is the difference between method overriding and overloading?
Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments.
----------------------------------------------------------------------------------------------------------------

What is a “stateless” protocol?
Without getting into lengthy debates, it is generally accepted that protocols like HTTP are stateless i.e. there is no retention of state between a transaction which is a single request response combination.
----------------------------------------------------------------------------------------------------------------

What is constructor chaining and how is it achieved in Java?
A child object constructor always first needs to construct its parent (which in turn calls its parent constructor.). In Java it is done via an implicit call to the no-args constructor as the first statement.
----------------------------------------------------------------------------------------------------------------

What is passed by ref and what by value?
All Java method arguments are passed by value. However, Java does manipulate objects by reference, and all object variables themselves are references
----------------------------------------------------------------------------------------------------------------

Can RMI and Corba based applications interact?
Yes they can. RMI is available with IIOP as the transport protocol instead of JRMP.
You can create a String object as String str = “abc"; Why cant a button object be created as Button bt = “abc";? Explain - The main reason you cannot create a button by Button bt1= “abc"; is because “abc” is a literal string (something slightly different than a String object, by the way) and bt1 is a Button object. The only object in Java that can be assigned a literal String is java.lang.String. Important to note that you are NOT calling a java.lang.String constuctor when you type String s = “abc";
----------------------------------------------------------------------------------------------------------------

What does the “abstract” keyword mean in front of a method? A class?
Abstract keyword declares either a method or a class. If a method has a abstract keyword in front of it,it is called abstract method.Abstract method hs no body.It has only arguments and return type.Abstract methods act as placeholder methods that are implemented in the subclasses. Abstract classes can’t be instantiated.If a class is declared as abstract,no objects of that class can be created.If a class contains any abstract method it must be declared as abstract.
----------------------------------------------------------------------------------------------------------------

How many methods do u implement if implement the Serializable Interface?
The Serializable interface is just a “marker” interface, with no methods of its own to implement. Other ‘marker’ interfaces are
java.rmi.Remote
java.util.EventListener
----------------------------------------------------------------------------------------------------------------

What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. import java.net.* versus import java.net.Socket)?
It makes no difference in the generated class files since only the classes that are actually used are referenced by the generated class file. There is another practical benefit to importing single classes, and this arises when two (or more) packages have classes with the same name. Take java.util.Timer and javax.swing.Timer, for example. If I import java.util.* and javax.swing.* and then try to use “Timer", I get an error while compiling (the class name is ambiguous between both packages). Let’s say what you really wanted was the javax.swing.Timer class, and the only classes you plan on using in java.util are Collection and HashMap. In this case, some people will prefer to import java.util.Collection and import java.util.HashMap instead of importing java.util.*. This will now allow them to use Timer, Collection, HashMap, and other javax.swing classes without using fully qualified class names in.
----------------------------------------------------------------------------------------------------------------

What is the difference between logical data independence and physical data independence?
Logical Data Independence - meaning immunity of external schemas to changeds in conceptual schema. Physical Data Independence - meaning immunity of conceptual schema to changes in the internal schema.
----------------------------------------------------------------------------------------------------------------

What is a user-defined exception?
Apart from the exceptions already defined in Java package libraries, user can define his own exception classes by extending Exception class.
----------------------------------------------------------------------------------------------------------------

Describe the visitor design pattern?
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.
----------------------------------------------------------------------------------------------------------------

What methods can be overridden in Java?
In C++ terminology, all public methods in Java are virtual. Therefore, all Java methods can be overwritten in subclasses except those that are declared final, static, and private.
---------------------------------------------------------------------------------------------------------------

Can there be an abstract class with no abstract methods in it?
Yes
----------------------------------------------------------------------------------------------------------------

Can an Interface be final?
No

No comments:

Post a Comment