Thursday, October 13, 2005

Q. DriverManager is a Class or an Interface
Ans. Driver Manager is a class

What is the output of the following code?

public class StringExample{

public static void main(String []args){
String s="New";
String s1=s;
String s2="D";
String s3="New";

System.out.println(s==s1);
System.out.println(s3==s2);
System.out.println(s3==s1);

System.out.println(s1.equals(s1));
System.out.println(s3.equals(s2));
System.out.println(s3.equals(s1));

}
}

Ans :

true
false
true

true
false
true

Tuesday, October 11, 2005

What is JDO?

JDO provides for the transparent persistence of data in a data store agnostic manner, supporting object, hierarchical, as well as relational stores.

Sunday, October 09, 2005

Ways to connect to a Database

A Java application can have multiple connections to multiple data sources at the same time using multiple Connection objects. A Connection object can be obtained by a Java application in two ways: through a DriverManager class or through an implementation of the DataSource interface.

Question No:
Given:
1. public class test (
2. public static void main (String args[]) {
3. int i = 0xFFFFFFF1;
4. int j = ~i;
5.
6. }
7. )
What is the decimal value of j at line 5?
A. 0
B. 1
C. 14
D. –15
E. An error at line 3 causes compilation to fail.
F. An error at line 4 causes compilation to fail.

Answer: C

Saturday, October 08, 2005

Web Servers vs. App Servers

These are two quite different pieces of software.
There are few Web servers in common use: Apache takes the lion's share, while Microsoft Internet Information Server (IIS) and iPlanet Web Server are among the others. Application servers jumped into the limelight only about two years ago and there is a proliferation of products from companies such as BEA, iPlanet, Oracle, SilverStream, HP (Bluestone), and IBM.

Speaking of functionality, in differentiating the two servers we have to say "in general" because there are customized versions of both Web and application servers that have crossover functionality. The Web server, in general, sends Web pages to browsers as its primary function. Most Web servers also process input from users, format data, provide security, and perform other tasks. The majority of a Web server's work is to execute HTML or scripting such as Perl, JavaScript, or VBScript.

In general, an application server prepares material for the Web server -- for example, gathering data from databases, applying business rules, processing security clearances, or storing the state of a user's session. In some respects the term application server is misleading since the functionality isn't limited to applications. Its role is more as an aggregator and manager for data and processes used by anything running on a Web server.

Thursday, October 06, 2005

Interfaces vs Abstact Classes

1. multiple inheritance :
A class may implement several interfaces whereas a class may extend only one abstract class.

2. default implementation :
An interface cannot provide any code at all, much less default code.
An abstract class can provide complete code, default code, and/or just stubs that have to be overridden.

3. constants:
Static final constants only, can use them without qualification in classes that implement the interface. On the other paw, these unqualified names pollute the namespace. You can use them and it is not obvious where they are coming from since the qualification is optional.

Both instance and static constants are possible. Both static and instance intialiser code are also possible to compute the constants.

4. Third party convenience :
An interface implementation may be added to any existing third party class.
A third party class must be rewritten to extend only from the abstract class.

5. plug-in :
You can write a new replacement module for an interface that contains not one stick of code in common with the existing implementations. When you implement the inteface, you start from scratch without any default implementation. You have to obtain your tools from other classes; nothing comes with the interface other than a few constants. This gives you freedom to implement a radically different internal design.
You must use the abstract class as-is for the code base, with all its attendant baggage, good or bad. The abstract class author has imposed structure on you. Depending on the cleverness of the author of the abstract class, this may be good or bad.

6. homogeneity :
If all the various implementaions share is the method signatures, then an interface works best.
If the various implementations are all of a kind and share a common status and behaviour, usually an abstract class works best. Another issue that's important is what I call "heterogeneous vs. homogeneous." If implementors/subclasses are homogeneous, tend towards an abstract base class. If they are heterogeneous, use an interface. (Now all I have to do is come up with a good definition of hetero/homo-geneous in this context.) If the various objects are all of-a-kind, and share a common state and behavior, then tend towards a common base class. If all they share is a set of method signatures, then tend towards an interface.

7. speed :
Slow, requires extra indirection to find the corresponding method in the actual class. Modern JVMs are discovering ways to reduce this speed penalty.
abstract classes are fast

Saturday, October 01, 2005

Java Basics

1.The Java interpreter is used for the execution of the source code.
True
False

Ans: a.

2) On successful compilation a file with the class extension is created.
a) True
b) False

Ans: a.


3) The Java source code can be created in a Notepad editor.
a) True
b) False

Ans: a.

4) The Java Program is enclosed in a class definition.
a) True
b) False

Ans: a.

5) What declarations are required for every Java application?

Ans: A class and the main( ) method declarations.


6) What are the two parts in executing a Java program and their purposes?

Ans: Two parts in executing a Java program are:
Java Compiler and Java Interpreter.
The Java Compiler is used for compilation and the Java Interpreter is used for execution of the application.

7) What are the three OOPs principles and define them?

Ans : Encapsulation, Inheritance and Polymorphism are the three OOPs
Principles.
Encapsulation:
Is the Mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse.
Inheritance:
Is the process by which one object acquires the properties of another object.
Polymorphism:
Is a feature that allows one interface to be used for a general class of actions.


8) What is a compilation unit?

Ans : Java source code file.
9) What output is displayed as the result of executing the following statement?
System.out.println("// Looks like a comment.");
// Looks like a comment
The statement results in a compilation error
Looks like a comment
No output is displayed

Ans : a.

10) In order for a source code file, containing the public class Test, to successfully compile, which of the following must be true?
It must have a package statement
It must be named Test.java
It must import java.lang
It must declare a public class named Test

Ans : b

11) What are identifiers and what is naming convention?

Ans : Identifiers are used for class names, method names and variable names. An identifier may be any descriptive sequence of upper case & lower case letters,numbers or underscore or dollar sign and must not begin with numbers.


12) What is the return type of program’s main( ) method?
Ans : void

13) What is the argument type of program’s main( ) method?
Ans : string array.

14) Which characters are as first characters of an identifier?
Ans : A – Z, a – z, _ ,$


15) What are different comments?
Ans :
1) // -- single line comment
2) /* --
*/ multiple line comment
3) /** -- */ documentation


16) What is the difference between constructor method and method?

Ans : Constructor will be automatically invoked when an object is created. Whereas method has to be call explicitly.

17) What is the use of bin and lib in JDK?
Ans : Bin contains all tools such as javac, applet viewer, awt tool etc., whereas Lib
contains all packages and variables.