Posts

Showing posts from January, 2011

Cloneable Interface::::Nucleous Software Java Interview Questions: Qu8

clone() and the Cloneable Interface in Java -------------------------------------------------------------------------------  The clone( ) method generates a duplicate copy of the object on which it is called. Only classes that implement the Cloneable interface can be cloned. The Cloneable interface defines no members. It is used to indicate that a class allows a bitwise copy of an object (that is, a clone ) to be made. If you try to call clone( ) on a class that does not implement Cloneable , a CloneNotSupportedException is thrown. When a clone is made, the constructor for the object being cloned is not called. A clone is simply an exact copy of the original. Cloning is a potentially dangerous action, because it can cause unintended side effects.  For example, if the object being cloned contains a reference variable called obRef, then when the clone is made, obRef in the clone will refer to the same object as does obRef in the original. If the clone makes a change to the cont...

wait | notify | notifyAll |Nucleous Software Java Interview Questions: Qu6

wait() | notify() | notifyAll() Multithreading replaces event loop programming by dividing your tasks into discrete and logical units. Threads also provide a secondary benefit: they do away with polling. Polling is usually implemented by a loop that is used to check some condition repeatedly. Once the condition is true, appropriate action is taken. This wastes CPU time. For example, consider the classic queuing problem, where one thread is producing some data and another is consuming it. To make the problem more interesting, suppose that the producer has to wait until the consumer is finished before it generates more data. In a polling system, the consumer would waste many CPU cycles while it waited for the producer to produce. Once the producer was finished, it would start polling, wasting more CPU cycles waiting for the consumer to finish, and so on. Clearly, this situation is undesirable. To avoid polling, Java includes an elegant interrocess communication mechanism via the ...

IBM Interview Questions: Serialization Vs Externalizable

Serialization Vs Externalizable One obvious difference that Serializable is a marker interface and doesn't contain any methods whereas Externalizable interface contains two methods: writeExternal(ObjectOutput) and readExternal(ObjectInput) . But, the main difference between the two is that Externalizable interface provides complete control to the class implementing the interface over the object serialization process whereas Serializable interface normally uses default implementation to handle the object serialization process . While implementing Serializable , you are not forced to define any method as it's a marker interface. However, you can use the writeObject or readObject methods to handle the serilaization process of complex objects. But, while implementing Externalizable interface, you are bound to define the two methods: writeExternal and readExternal and all the object serialization process is solely handled by these two methods only. In case of Serializable ...

Serilization| markup Interface | Nucleous Software Java Interview Questions: Qu6

What is serilization? How we implement it....Also what is the meaning of markup interface???? ------------------------------------------------------------------------------------------------ Answer1 : It's a mechanism in Java to ensure that the objects of classes implementing java.io.Serializable interface will have the capability of storing their states on a persistent storage that can be loaded back into the memory with the same state whenever needed. The Serializable interface is only a marker interface and has no methods or fields in it. It just serves the purpose of notifying the JVM about the Class implementing it that the Class may require to save its state on a persistent medium and subsequently may need to restore the same saved state in the memory when needed. The compiler handles it either by identifying serialVersionUID field in the class or by adding one to the class (the next post talks in detail about serialVersionUID) and presence of this field notifie...

Singleton class:::Nucleous Software Java Interview Questions: Qu7

What is Singleton Class: How will you make a class singloton.... ---------------------------------------------------------------------- Singleton class: This is a class which can be instatiated only once. Eg: Public class Singleton { private static single = new Singleton(); Private Singleton(); {} } For a singleton class, the constructor is made private and a static variable is used for instatiating the class.    

Implicit objects in JSP::Nucleous Software Java Interview Questions: Qu5

Implicit objects in JSP ----------------------------------------------------------------------------------------------------------- Implicit objects in jsp are the objects that are created by the container automatically and the container makes them available to the developers, the developer do not need to create them explicitly. Since these objects are created automatically by the container and are accessed using standard variables; hence, they are called implicit objects. The implicit objects are parsed by the container and inserted into the generated servlet code. They are available only within the jspService method and not in any declaration. Implicit objects are used for different purposes. Our own methods (user defined methods) can't access them as they are local to the service method and are created at the conversion time of a jsp into a servlet. But we can pass them to our own method if we wish to use them locally in those functions. There are nine implicit objects. ...

Stored Procedure and Function::::Nucleous Software Java Interview Questions: Qu4

Difference between Stored Procedure and Function -----------------------------------------------------------------------------------------------------------                                        Answer 1 1) functions are used for computations where as procedures can be used for performing business logic 2) functions MUST return a value, procedures need not be. 3) you can have DML(insert, update, delete) statements in a function. But, you cannot call such a function in a SQL query..eg: suppose, if u have a function that is updating a table.. you can't call that function in any sql query.- select myFunction(field) from sometable; will throw error. 4) function parameters are always IN, no OUT is possible   -------------------------------------------------------------------------------------------------...

Transient and Volatile ::::Nucleous Software Java Interview Questions: Qu3

Transient and Volatile keywords in java Answers 1: Java defines two interesting type modifiers: transient and volatile . These modifiers are used to handle somewhat specialized situations. When an instance variable is declared as transient , then its value need not persist when an object is stored.  For example: class T { transient int a; // will not persist int b; // will persist } Here, if an object of type T is written to a persistent storage area, the contents of a would not be saved, but the contents of b would. The volatile modifier tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of your program. One of these situations involves multithreaded programs.  In a multithreaded program, sometimes, two or more threads share the same instance variable. For efficiency considerations, each thread can keep its own, private copy of such a shared variable. The real (or master ) copy of the variable is updated at various times, such...

What is index ::Nucleous Software Java Interview Questions: Qu2

What is index and why it is used?? Answers:  1. Oracle includes numerous data structures to improve the speed of Oracle SQL queries. Taking advantage of the low cost of disk storage, Oracle includes many new indexing algorithms that dramatically increase the speed with which Oracle queries are serviced. This article explores the internals of Oracle indexing; reviews the standard b-tree index, bitmap indexes, function-based indexes, and index-only tables (IOTs); and demonstrates how these indexes may dramatically increase the speed of Oracle SQL queries. Oracle uses indexes to avoid the need for large-table, full-table scans and disk sorts, which are required when the SQL optimizer cannot find an efficient way to service the SQL query. I begin our look at Oracle indexing with a review of standard Oracle b-tree index methodologies. 2. Oracle ind...

Statement and Prepared Statement:::::Nucleous Software Java Interview Questions: Qu1

Difference between Statement and Prepared Statement in JDBC 1. The PreparedStatement is a slightly more powerful version of a Statement , and should always be at least as quick and easy to handle as a Statement .  The PreparedStatement may be parametrized. 2. In general a PreparedStatement will outperform a Statement, but there are cases in which a Statement is faster, and you may have created this situation. The main advantage to a PreparedStatement is that it does not need to be compiled on the database every time, the database compiles it once and prepares itself as well as it can given that it doesn't know everything about the query. It may be possible to add more performance tweaks, but the database just can't be sure. When it comes to a Statement with no unbound variables, the dtaabae is free to optimise to its full extent. The individual query will be faster, but the down side is that you need ...

Constraints information in the database catalog in DB2

Table 1. Constraints information in the database catalog Catalog view View column Description Query example SYSCAT.CHECKS Contains a row for each table check constraint db2 select constname, tabname, text from syscat.checks SYSCAT.COLCHECKS Contains a row for each column that is referenced by a table check constraint db2 select constname, tabname, colname, usage from syscat.colchecks SYSCAT.COLUMNS NULLS Indicates whether a column is nullable (Y) or not nullable (N) db2 select tabname, colname, nulls from syscat.columns where tabschema = 'DELSVT' and nulls = 'N' SYSCAT.CONSTDEP Contains a row for each dependency of a constraint on some other object db2 select constname, tabname, btype, bname from syscat.constdep SYSCAT.INDEXES Contains a row for each index. db2 select tabname, uniquerule, made_unique, system_requ...

How to see Primary key in a table in DB2

---------See primary key with column name in a table in db2--------------- db2  "select constname,tabname,colname from syscat.keycoluse where tabname='TABLENAME' " It will give you..... Example:::   db2inst1@confonet:~> db2 "select constname,tabname,colname from syscat.keycoluse where tabname='COMPLAINANT_RESPONDENT'" --------------Output-------------------------------- CONSTNAME                                                                                                    ...

IBM Interview Questions: Struts workflow

Image
Qu7: What is struts and how ActionServlet works... Answers: The following events happen when the Client browser issues an HTTP request. The ActionServlet receives the request. The struts-config.xml file contains the details regarding the Actions , ActionForms , ActionMappings and ActionForwards . During the startup the ActionServelet reads the struts-config.xml file and creates a database of configuration objects. Later while processing the request the ActionServlet makes decision by refering to this object. When the ActionServlet receives the request it does the following tasks. Bundles all the request values into a JavaBean class which extends Struts ActionForm class. Decides which action class to invoke to process the request. Validate the data entered by the user. The action class process the request with the help of the model component. The model interacts with the database and process the request. After completing the request processing the Action class returns...

IBM Interview Questions: Make a class Immutable

Qu6: How will you make a class immutable?? Answer: Just make the class final so that it can not be subclassed and then also make final to it's variables and methods so that method can not be override and variables can not be modified... -------------------------------------------------------------------------------------------------------------------------- Making a class immutable   Immutability must be familiar to every one when we talk about String & StringBuffer classes in java. Strings are considered immutable because the values contained in the reference variable cannot be changed. Whereas String Buffer is considered mutable because the value in a string buffer can be changed (i.e. mutable). However I always thought how to make our user defined classes as immutable though I am unaware as to why any one would need this. The reason perhaps might be clear once we have a look at the code. Now in order to make a class immutable we must restrict changing the state ...

enum (in Java)::::Interview Questions

Define enum   ---------------------------------------------------------------------------------------------- Answer: In prior releases, the standard way to represent an enumerated type was the int Enum pattern: // int Enum Pattern - has severe problems! public static final int SEASON_WINTER = 0; public static final int SEASON_SPRING = 1; public static final int SEASON_SUMMER = 2; public static final int SEASON_FALL = 3; This pattern has many problems, such as: Not typesafe - Since a season is just an int you can pass in any other int value where a season is required, or add two seasons together (which makes no sense). No namespace - You must prefix constants of an int enum with a string (in this case SEASON_ ) to avoid collisions with other int enum types. Brittleness - Because int enums are compile-time constants, they are compiled into clients that use them. If a new constant is added between two existing constants or the order is changed, clients must be recompiled. If...

IBM Interview Questions: difference between abstraction and encapsulation

Difference between abstraction and encapsulation --------------------------------------------------------------------------------------------------------- Abstraction lets you focus on what the object does instead of how it does it Encapsulation means hiding the internal details or mechanics of how an object does something.  --------------------------------------------------------------------------------------------------------- Abstraction: The idea of presenting something in a simplified / different way, which is either easier to understand and use or more pertinent to the situation. Consider a class that sends an email... it uses abstraction to show itself to you as some kind of messenger boy, so you can call emailSender.send(mail, recipient). What it actually does - chooses POP3 / SMTP, calling servers, MIME translation, etc, is abstracted away. You only see your messenger boy. Encapsulation: The idea of securing and hiding data and methods that are private to an objec...

IBM Interview Questions: vector implementation

Image
Qu5: Tell in a web based project where we need to implement Vector.. Answer: java.util Class Vector java.lang.Object java.util.AbstractCollection java.util.AbstractList java.util.Vector All Implemented Interfaces: Cloneable, Collection, List, RandomAccess, Serializable Direct Known Subclasses: Stack public class Vector extends AbstractList implements List, RandomAccess, Cloneable, Serializable The Vector class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created. Each vector tries to optimize storage management by maintaining a capacity and a capacityIncrement . The capacity is always at least as large as the vector size; it is usually larger because as components are added to the vector, the vector's storage increases in chunks the size of ...

IBM Interview Questions: Qu3, Qu4

Qu3: Difference between Abstract Class and Interface . Feature Interface Abstract class Multiple inheritance A class may inherit several interface s. A class may inherit only one abstract class . Default implementation An interface cannot provide any code, just the signature. An abstract class can provide complete, default code and/or just the details that have to be overridden. Access Modfiers An interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as public An abstract class can contain access modifiers for the subs, functions, properties Core VS Peripheral Interface s are used to define the peripheral abilities of a class . In other words both Human and Vehicle can inherit from a IMovable interface . An abstract class defines the core identity of a class and there it is used for objects of the same type. Homogeneity If various implementations only share method signatures then ...