jump to navigation

Alternatives to inheritance November 28, 2006

Posted by Allu in JAVA.

Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass)

What does it mean that a method or field is “static”? November 28, 2006

Posted by Allu in JAVA.

Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class.
 Static methods can be referenced with the name of the class rather than the name of a particular object of the class.

Difference between throw and throws November 21, 2006

Posted by Allu in JAVA.

The throw keyword denotes a statement that causes an exception to be initiated. It takes the Exception object to be thrown as argument. The exception will be caught by an immediately encompassing try-catch construction or propagated further up the calling hierarchy.
 The throws keyword is a modifier of a method that designates that exceptions may come out of the method, either by virtue of the method throwing the exception itself or because it fails to catch such exceptions that a method it calls may throw.

Difference between a constructor and a method November 19, 2006

Posted by Allu in JAVA.

A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator.
 A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.

Difference between variable declared inside a declaration part and variable declared in scriplet part of JSP? November 11, 2006

Posted by Allu in J2EE, JSP.
1 comment so far

Variable declared inside declaration part is treated as a global variable. that means after convertion of a jsp file into servlet that variable will be in outside of service method or it will be declared as instance variable. And the scope is available to complete jsp and to complete in the converted servlet class. where as if u declare a variable inside a scriplet that variable will be declared inside a service method and the scope is with in the service method.

Difference between final, finally and finalize() November 8, 2006

Posted by Allu in JAVA.
  • final – constant declaration.
  • finally – The finally block always executes when the try block exits, except System.exit(0) call. This ensures that the finally block is executed even if an unexpected exception occurs. But finally is useful for more than just exception handling — it allows the programmer to avoid having cleanup code accidentally bypassed by a return, continue, or break. Putting cleanup code in a finally block is always a good practice, even when no exceptions are anticipated.
  • finalize() – method helps in garbage collection. A method that is invoked before an object is discarded by the garbage collector, allowing it to clean up its state. Should not be used to release non-memory resources like file handles, sockets, database connections etc because Java has only a finite number of these resources and you do not know when the garbage collection is going to kick in to release these non-memory resources through the finalize() method.

Difference between a Web server and an application server November 2, 2006

Posted by Allu in J2EE.

In general, an application server prepares data for a Web server — for example, gathering data from databases, applying relevant business rules, processing security checks, and/or storing the state of a user’s session. The term application server may be misleading since the functionality isn’t limited to applications. Its role is more as retriever and manager of data and processes used by anything running on a Web server. In the coming age of Web services, application servers will probably have an even more important role in managing service oriented components. One of the reasons for using an application server is to improve performance by off-loading tasks from a Web server. When heavy traffic has more users, more transactions, more data, and more security checks then more likely a Web server becomes a bottleneck.