Consultancy Services jobs Etisalat CEO ZANTEL
etisalat

Custom Search
Share/Save/Bookmark Subscribe

Core Java FAQ - 1

Posted by Anonymous | 4:02 PM | | 0 comments »

CORE JAVA faqs - part 1

Etisalat

DEVELOPER

bangalore

india

BLOGGER

SEX






1. What is the difference between an Interface and Abstract class ?
• A class may implement several interfaces where as it can extend only one abstract class.

• An interface cannot provide any code at all, much less default code where as an abstract class can provide complete code, default code, and/or just stubs that has to be overridden.

• Static final constants can use the interfaces without qualification in classes that implement the interface where as both static constants and instance variables can use the abstract classes.

• Interface implementation can be added to any existing third part classes where as third party classes must be rewritten to extend from the abstract classes.

• Interfaces are used to often represent peripheral ability of a class, not central identity where as abstract class defines core identity of its descendants.

• If various implementations share is method signature then Interface works best where as If the various implementations are all of a kind and share a common status and behavior, usually an abstract class works best.

• Interface is slow where as abstract class is fast in performance.

• If you add a new method to an interface, you must track down all implementations of that interface in the universe and provide them with a concrete implementation of that method
where as in case of an abstract class if you add a new method to an abstract class, you have the option of providing a default implementation of it. Then all existing code will continue to work without change.

• You can put shared code into an abstract class, where you cannot into an interface.

2. How do you write user-defined exceptions in Java?

• To write user-defined exception in java, you exception class should extend Exception base class have call the super class methods in your own methods.

3. What is multiple inheritance? Is it supported in java?

• This means one object having multiple parents, which is not truly supported in java but supported in C++. But overall design of java suggests that we can implement multiple inheritances in java using interfaces.

4. What is difference between an inner class and static inner class?

• A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.

5. What is an inner class and what is its advantage?

• Inner class is class, which is defined inside a class as private class and always bears a reference to the outer class.

o Inner classes can be nested within the body of a method.

• Scope of inner class is the entire enclosing class in which the inner class is nested.

• Inner classes can access attributes and methods in nesting class.

• Each inner class is compiled into a separate. class file labeled:NestingClass$InnerClass.

• Inner classes can contain methods that return handles to inner class instances.

• Major advantage of inner classes is the ability to create adaptor classes that implement an interface.

o Make all inner classes private to ensure hidden implementation.

o Rather than handle classes returning inner classes, they return interfaces.

• Inner classes frequently used with event handling in applets.
6. What is a transient variable?

o The variable, which cannot be serialized, is known as transient variable.

7. What are wrapped classes?

o Wrapped classes are classes that allow primitive types to be accessed as objects.

8. What is an immutable object and what are its advantages?

• An immutable object is an object and any object it references that does not change after construction. The object is, therefore, immutable for its lifetime.

• Immutable classes are commonly used to represent strings, colors, and numeric values.
Advantage:

• They guarantee that their state cannot change after construction, they are inherently thread-safe.

9. What are basic rules, which govern creation of immutable classes?

• Declare the class final.

• Declare all data private.

• Provide only getter methods and no setter methods.

• Set all instance data in the constructor.

• Clone mutable objects for which a reference to them is returned.

• Clone mutable objects for which a reference to them is received.

• Implement a deep clone if the default shallow clone is not correct for a properly behaved immutable object.

10. What is a Java package and how is it used?

• A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces. Packages are also used to organize related classes and interfaces into a single API unit and to control accessibility to these classes and interfaces.

11.What restrictions are placed on method overriding?

• Overridden methods must have the same name, argument list, and return type.

• The overriding method may not limit the access of the method it overrides.

• The overriding method may not throw any exceptions that may not be thrown by the overridden method.

12. What is use of this and super key words?

• ‘this’ is used for referring to current instance of the object where as ‘super’ is used to refer to variables and methods of its super class.

• Incase of constructors, this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.


13. What is the difference between a static and non-static variable?

• A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.

14. What is polymorphism and what are different types of polymorphism?

• One name, different form and there are three forms.

1. Method overloading

2. Method overriding through Interfaces

3. Method overriding through java interfaces.

15. What is the essence of run-time polymorphism behavior?

With runtime polymorphism based on method overriding, the decision as to which version of a method will be executed is based on the actual type of object whose reference is stored in the reference variable, and not on the type of the reference variable on which the method is invoked.
The decisions as to which version of the method to invoke cannot be made at compile time. That decision must be deferred and made at runtime. This is sometimes referred to as late binding.

16. What is a singleton class and how to implement it? What are the advantages of Singleton class?

Singleton classes are created to have only one instance.
A singleton may be used to represent some unique system.
It is generally implemented by keeping the constructor private.
It should have static members and methods.
The main advantage of singleton class is memory management( Garbage collection)

17. Why java prohibits use of ‘synchronized’ inside a constructor ?

Because other threads cannot get a reference to the object until construction of the object completes. This has got a performance overhead.

18. What do you mean by Garbage collection and what are its advantages and disadvantages?

The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources may be reclaimed.

An object is eligible for garbage collection when its reference is set to null. Method variables or local variables are eligible for Garbage collection when they go out of scope.

Garbage Collection cannot be forced explicitly. JVM may do garbage collection if it is running short of memory.The call System.gc() does NOT force the garbage collection but only suggests that the JVM may make an effort to do garbage collection.

It frees up the heap space and takes care of heap fragmentation.

It also helps to ensure program integrity as programmers are unable to crash the JVM by incorrectly freeing the memory accidentally or purposefully.

The only disadvantage is garbage-collected heap is a performance overhead.

19.What do you mean by conservative garbage collector?

The garbage collectors that cannot distinguish between genuine object references and look-alikes.

20. Can an object's finalize () method be invoked while it is reachable?

An object's finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object's finalize() method may be invoked by other objects.

21. How many times may an object's finalize() method be invoked by the garbage collector and when it is invoked ?

An object's finalize() method may only be invoked once by the garbage collector when the object is unreachable.

22. Does garbage collection guarantee that a program will not run out of memory?

Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection.

23. How does the distributed garbage collection work in java?

• The RMI subsystem implements a reference counting-based distributed garbage collection (DGC) algorithm to provide automatic memory management facilities for remote server objects.

• Basically, DGC works by having the remote server keep track of all external client references to it at any given time. When a client obtains a remote reference, it is addded to the remote object's referenced set. The DGC then marks the remote object as dirty and increases its reference count by one. When a client drops a reference, the DGC decreases its reference count by one, and marks the object as clean.

When the reference count reaches zero, the remote object is free of any live client references. It is then placed on the weak reference list and subject to periodic garbage collection.

24.What is the priority of Garbage collection thread in java ?

This is a low-priority thread in java.

25. How many applications can be run by one run-time instance of JVM ?

One run-time instance of java application can run only one instance.
26.When the JVM terminates ?

The Java Virtual machine terminates when all the non-daemon threads of java application terminates.
If permitted by the security manager it can also call System.runtime.ext () for terminating the JVM.

27. Is it possible to know from the content of a class file whether it is a java class file or not?

The first four bytes of every java class file is a magic number “0xCAFEBABE”. So it is very easy to identify whether it is a java class file or not.

28.Name the process thru which JVM makes the types available to the running program?

The Java Virtual Machine makes types available to the running program through a process of loading, linking, and initialization.

29. Define loading, linking and initialization of java class ?

Loading : Loading is the process of bringing a binary form for a type into the Java Virtual Machine.

Linking : Linking is the process of incorporating the binary type data into the runtime state of the virtual machine. Linking is divided into three sub-steps: verification, preparation, and resolution.

Initialization: During initialization the class variables are their proper initial values.

30. What do you mean by first active use of a class in JVM?

• The invocation of a constructor on a new instance of the class.

• The creation of an array that has the class as its an element type.

• The invocation of a method declared by the class (not inherited from a super class) .

• The use or assignment of a field declared by the class (not inherited from a superclass or super interface), except for fields that are both static and final, and are initialized by a compile-time constant expression.

31. What are steps involved in loading of a class file into JVM?

• Produce a stream of binary data that represents the type.

• Parse the stream of binary data into internal data structures in the method area.

• Create an instance of class java.lang.Class that represents the type.

32.Is it possible to detect a malformed class file during early loading by the class loader?

No it is not possible. If a class loader encounters a missing or malformed class file during early loading, it must wait to report that error until the class is first active use by the program.

33.What are the different stages of linking after the class is loaded?

Verification, prepare and resolve are the three phases of linking.

34. What is verification stage and what are steps involved during verification?

It ensures that the types obey the semantics of java language and doesn’t violate the integrity of JVM.

The entire process of detecting any kind of problem with loaded types is placed under the category of verification.

Verification of symbolic references and converting them to direct references.

• checking that final classes are not sub classed

• checking that final methods are not overridden

• if the type being checked is a non-abstract class, checking that all the methods declared in any
interfaces implemented by the class are indeed implemented by the class

• Making sure no incompatible method declarations (such as two methods that have the same name, the same number, order, and types of parameters, but different return types) appear between the type and its supertypes.

35. What is done during Preparation Stage?

The Java Virtual Machine allocates memory for the class variables and sets them to default initial values. The class variables are not initialized to their proper initial values until the initialization phase.

Java Virtual Machine implementations may also allocate memory for data structures that are intended to improve the performance of the running program.
36. What happens during Resolution Phase?

Resolution is the process of locating classes, interfaces, fields, and methods referenced symbolically from a types constant pool, and replacing those symbolic references with direct references.

37. How the initialization of class is is different from initialization of interface?

Initialization of class requires initialization of its super classes but initialization of interfaces doesn’t require initialization of it super interfaces.

0 comments

free counters
Your Ad Here

Cross Rates Powered by Forex Pros - The Forex Trading Portal.
java.sun.com jobs etisalat actress hot sex
Bangalore, 04 March 2008, UAE Telecoms Gaint founds ‘technologia’ in Bangalore to create continuous stream of new innovations. Affordable Website Design
Free Search Engine Submission
Free Search Engine Submission
Submit Your Site To The Web's Top 50 Search Engines for Free! BigDirectory.org - free url submission, online website directory National Directory Free Web Directory Submission - Dotster Directory Link Popularity Building
We offers advanced Link Popularity Services for small to large static, dynamic and eCommerce websites.
http://www.links-builder.com
India Search Engine and Web Directory Superblog Directory
HOT SEX,NUDE TECHNOLOGIAWORLD SQL JAVA SUN BEA IBM HCL SATYAM TCS CHIRANJEEVI CHIRU PAWAN HANSIKA SANGAVI SNEHA TAMIL SEX MALLU MASALA