jump to navigation

Constructor June 18, 2007

Posted by Allu in JAVA.

The automatic initialization is performed through the constructor, constructor has same name has class name. Constructor has no return type not even void. We can pass the parameters to the constructor. this() is used to invoke a constructor of the same class. Super() is used to invoke a super class constructor. Constructor is called immediately after the object is created before the new operator completes.

 Constructor can use the access modifiers public, protected, private or have no access modifier

 Constructor can not use the modifiers abstract, static, final, native, synchronized or strictfp

 Constructor can be overloaded, we cannot override.

 You cannot use this() and Super() in the same constructor.

Difference between ArrayList and Vector? February 7, 2007

Posted by Allu in JAVA.
  • Internally, both the ArrayList and Vector hold onto their contents using an Array. A Vector defaults to doubling the size of its array, while the ArrayList increases its array size by 50 percent.
  • ArrayList doesn’t have a constructor for specifying the incremental capacity, where as Vector has a constructor to specify the initial capacity and incremental capacity.
  • Vector is synchronized where as ArrayList is not synchronized

Difference between preemptive scheduling and time slicing January 23, 2007

Posted by Allu in JAVA.

Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.

Difference between SAX and DOM parsers? December 28, 2006

Posted by Allu in JAVA.

SAX Parser:

·        A SAX (Simple API for XML) parser does not create any internal structure. Instead, it takes the occurrences of components of an input document as events, and tells the client what it reads as it reads through the input document.

·        A SAX parser serves the client application always only with pieces of the document at any given time.

·        A SAX parser, however, is much more space efficient in case of a big input document (because it creates no internal structure). What’s more, it runs faster and is easier to learn than DOM parser because its API is really simple. But from the functionality point of view, it provides a fewer functions, which means that the users themselves have to take care of more, such as creating their own data structures.

DOM Parser:

·        A DOM (Document Object Model) parser creates a tree structure in memory from an input document and then waits for requests from client.

·        A DOM parser always serves the client application with the entire document no matter how much is actually needed by the client.

·        A DOM parser is rich in functionality. It creates a DOM tree in memory and allows you to access any part of the document repeatedly and allows you to modify the DOM tree. But it is space inefficient when the document is huge, and it takes a little bit longer to learn how to work with it.

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 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.

What is a daemon thread? October 28, 2006

Posted by Allu in JAVA.

Daemon threads are sometimes called “service” threads. These are threads that normally run at a low priority and provide a basic service to a program or programs when activity on a machine is reduced. An example of a daemon thread that is continuously running is the garbage collector thread. This thread is provided by the JVM.