Sunday, April 12, 2009

java-18

Q:

What is the Collections API?

A: The Collections API is a set of classes and interfaces that support operations on collections of objects.
[ Received from Prasanna Inamanamelluri]

Q:

What is the List interface?

A: The List interface provides support for ordered collections of objects.
[ Received from SPrasanna Inamanamelluri]

Q:

What is the Vector class?

A: The Vector class provides the capability to implement a growable array of objects.
[ Received from Prasanna Inamanamelluri]

Q:

What is an Iterator interface?

A: The Iterator interface is used to step through the elements of a Collection .
[ Received from Prasanna Inamanamelluri]

Q:

Which java.util classes and interfaces support event handling?

A: The EventObject class and the EventListener interface support event processing.

Q:

What is the GregorianCalendar class?

A: The GregorianCalendar provides support for traditional Western calendars
[ Received from Prasanna Inamanamelluri]

Q:

What is the Locale class?

A: The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region .
[ Received from Prasanna Inamanamelluri]

Q:

What is the SimpleTimeZone class?

A: The SimpleTimeZone class provides support for a Gregorian calendar .
[ Received from Prasanna Inamanamelluri]

Q:

What is the Map interface?

A: The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values.
[ Received from Prasanna Inamanamelluri]

Q:

What is the highest-level event class of the event-delegation model?

A: The java.util.EventObject class is the highest-level class in the event-delegation class hierarchy.
[ Received from Prasanna Inamanamelluri]

Q:

What is the Collection interface?

A: The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates.
[ Received from Prasanna Inamanamelluri]

Q:

What is the Set interface?

A: The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements.
[ Received from Prasanna Inamanamelluri]

Q:

What is the typical use of Hashtable?

A: Whenever a program wants to store a key value pair, one can use Hashtable.
[ Received from Sandesh Sadhale]

Q:

I am trying to store an object using a key in a Hashtable. And some other object already exists in that location, then what will happen? The existing object will be overwritten? Or the new object will be stored elsewhere?

A: The existing object will be overwritten and thus it will be lost.
[ Received from Sandesh Sadhale]

Q:

What is the difference between the size and capacity of a Vector?

A: The size is the number of elements actually stored in the vector, while capacity is the maximum number of elements it can store at a given instance of time.
[ Received from Sandesh Sadhale]

Q:

Can a vector contain heterogenous objects?

A: Yes a Vector can contain heterogenous objects. Because a Vector stores everything in terms of Object.
[ Received from Sandesh Sadhale]

Q:

Can a ArrayList contain heterogenous objects?

A: Yes a ArrayList can contain heterogenous objects. Because a ArrayList stores everything in terms of Object.
[ Received from Sandesh Sadhale]

Q:

What is an enumeration?

A: An enumeration is an interface containing methods for accessing the underlying data structure from which the enumeration is obtained. It is a construct which collection classes return when you request a collection of all the objects stored in the collection. It allows sequential access to all the elements stored in the collection.
[ Received from Sandesh Sadhale]

Q:

Considering the basic properties of Vector and ArrayList, where will you use Vector and where will you use ArrayList?

A: The basic difference between a Vector and an ArrayList is that, vector is synchronized while ArrayList is not. Thus whenever there is a possibility of multiple threads accessing the same instance, one should use Vector. While if not multiple threads are going to access the same instance then use ArrayList. Non synchronized data structure will give better performance than the synchronized one.
[ Received from Sandesh Sadhale]

Q:

Can a vector contain heterogenous objects?

A: Yes a Vector can contain heterogenous objects. Because a Vector stores everything in terms of Object.
[ Received from Sandesh Sadhale]

DBMS-0

Q:

What is SQL?

A: SQL stands for 'Structured Query Language'.

Q:

What is SELECT statement?

A: The SELECT statement lets you select a set of values from a table in a database. The values selected from the database table would depend on the various conditions that are specified in the SQL query.

Q:

How can you compare a part of the name rather than the entire name?

A: SELECT * FROM people WHERE empname LIKE '%ab%'
Would return a recordset with records consisting empname the sequence 'ab' in empname .

Q:

What is the INSERT statement?

A: The INSERT statement lets you insert information into a database.

Q:

How do you delete a record from a database?

A: Use the DELETE statement to remove records or any particular column values from a database.

Q:

How could I get distinct entries from a table?

A: The SELECT statement in conjunction with DISTINCT lets you select a set of distinct values from a table in a database. The values selected from the database table would of course depend on the various conditions that are specified in the SQL query. Example
SELECT DISTINCT empname FROM emptable

Q:

How to get the results of a Query sorted in any order?

A: You can sort the results and return the sorted results to your program by using ORDER BY keyword thus saving you the pain of carrying out the sorting yourself. The ORDER BY keyword is used for sorting.

SELECT empname, age, city FROM emptable ORDER BY empname

Q:

How can I find the total number of records in a table?

A:

You could use the COUNT keyword , example

SELECT COUNT(*) FROM emp WHERE age>40


Q:

What is GROUP BY?

A: The GROUP BY keywords have been added to SQL because aggregate functions (like SUM) return the aggregate of all column values every time they are called. Without the GROUP BY functionality, finding the sum for each individual group of column values was not possible.

Q:

What is the difference among "dropping a table", "truncating a table" and "deleting all records" from a table.

A: Dropping : (Table structure + Data are deleted), Invalidates the dependent objects ,Drops the indexes

Truncating: (Data alone deleted), Performs an automatic commit, Faster than delete

Delete : (Data alone deleted), Doesn’t perform automatic commit


Q:

What are the Large object types suported by Oracle?

A: Blob and Clob.

Q:

Difference between a "where" clause and a "having" clause.

A: Having clause is used only with group functions whereas Where is not used with.

Q:

What's the difference between a primary key and a unique key?

A:

Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn't allow NULLs, but unique key allows one NULL only.


Q:

What are cursors? Explain different types of cursors. What are the disadvantages of cursors? How can you avoid cursors?

A:

Cursors allow row-by-row prcessing of the resultsets.

Types of cursors: Static, Dynamic, Forward-only, Keyset-driven. See books online for more information.

Disadvantages of cursors: Each time you fetch a row from the cursor, it results in a network roundtrip, where as a normal SELECT query makes only one rowundtrip, however large the resultset is. Cursors are also costly because they require more resources and temporary storage (results in more IO operations). Furthere, there are restrictions on the SELECT statements that can be used with some types of cursors.

Most of the times, set based operations can be used instead of cursors.


Q:

What are triggers? How to invoke a trigger on demand?

A: Triggers are special kind of stored procedures that get executed automatically when an INSERT, UPDATE or DELETE operation takes place on a table.

Triggers can't be invoked on demand. They get triggered only when an associated action (INSERT, UPDATE, DELETE) happens on the table on which they are defined.

Triggers are generally used to implement business rules, auditing. Triggers can also be used to extend the referential integrity checks, but wherever possible, use constraints for this purpose, instead of triggers, as constraints are much faster.


Q:

What is a join and explain different types of joins.

A:

Joins are used in queries to explain how different tables are related. Joins also let you select data from a table depending upon data from another table.

Types of joins: INNER JOINs, OUTER JOINs, CROSS JOINs. OUTER JOINs are further classified as LEFT OUTER JOINS, RIGHT OUTER JOINS and FULL OUTER JOINS.


Q:

What is a self join?

A: Self join is just like any other join, except that two instances of the same table will be joined in the query.

java-17

Q:

Is Empty .java file a valid source file?

A: Yes, an empty .java file is a perfectly valid source file.

[Received from Sandesh Sadhale]

Q:

Can a .java file contain more than one java classes?

A: Yes, a .java file contain more than one java classes, provided at the most one of them is a public class.

[ Received from Sandesh Sadhale]

Q:

Is String a primitive data type in Java?

A: No String is not a primitive data type in Java, even though it is one of the most extensively used object. Strings in Java are instances of String class defined in java.lang package.

[ Received from Sandesh Sadhale]

Q:

Is main a keyword in Java?

A: No, main is not a keyword in Java.

[ Received from Sandesh Sadhale]

Q:

Is next a keyword in Java?

A: No, next is not a keyword.

[ Received from Sandesh Sadhale]

Q:

Is delete a keyword in Java?

A: No, delete is not a keyword in Java. Java does not make use of explicit destructors the way C++ does.

[ Received from Sandesh Sadhale]

Q:

Is exit a keyword in Java?

A: No. To exit a program explicitly you use exit method in System object.

[ Received from Sandesh Sadhale]

Q:

What happens if you dont initialize an instance variable of any of the primitive types in Java?

A: Java by default initializes it to the default value for that primitive type. Thus an int will be initialized to 0, a boolean will be initialized to false.

[ Received from Sandesh Sadhale]

Q:

What will be the initial value of an object reference which is defined as an instance variable?

A: The object references are all initialized to null in Java. However in order to do anything useful with these references, you must set them to a valid object, else you will get NullPointerExceptions everywhere you try to use such default initialized references.

[ Received from Sandesh Sadhale]

Q:

What are the different scopes for Java variables?

A: The scope of a Java variable is determined by the context in which the variable is declared. Thus a java variable can have one of the three scopes at any given point in time.
1. Instance : - These are typical object level variables, they are initialized to default values at the time of creation of object, and remain accessible as long as the object accessible.
2. Local : - These are the variables that are defined within a method. They remain accessbile only during the course of method excecution. When the method finishes execution, these variables fall out of scope.
3. Static: - These are the class level variables. They are initialized when the class is loaded in JVM for the first time and remain there as long as the class remains loaded. They are not tied to any particular object instance.

[ Received from Sandesh Sadhale]

Q:

What is the default value of the local variables?

A: The local variables are not initialized to any default value, neither primitives nor object references. If you try to use these variables without initializing them explicitly, the java compiler will not compile the code. It will complain abt the local varaible not being initilized..

[ Received from Sandesh Sadhale]

Q:

How many objects are created in the following piece of code?
MyClass c1, c2, c3;
c1 = new MyClass ();
c3 = new MyClass ();

A: Only 2 objects are created, c1 and c3. The reference c2 is only declared and not initialized.

[ Received from Sandesh Sadhale]

Q:

Can a public class MyClass be defined in a source file named YourClass.java?

A: No the source file name, if it contains a public class, must be the same as the public class name itself with a .java extension.

[ Received from Sandesh Sadhale]

Q:

Can main method be declared final?

A: Yes, the main method can be declared final, in addition to being public static.

[ Received fromSandesh Sadhale]

Q:

What will be the output of the following statement?
System.out.println ("1" + 3);

A: It will print 13.

[ Received from Sandesh Sadhale]

Q:

What will be the default values of all the elements of an array defined as an instance variable?

A: If the array is an array of primitive types, then all the elements of the array will be initialized to the default value corresponding to that primitive type. e.g. All the elements of an array of int will be initialized to 0, while that of boolean type will be initialized to false. Whereas if the array is an array of references (of any type), all the elements will be initialized to null.

[ Received from Sandesh Sadhale]