JAVA - J2EE Training Guide

Are You Looking For JAVA/J2EE Online Training ?

Fill in your details in below form, we will get back to you

Powered by Blogger.

Thursday, 13 November 2014

Hard Questions on Core Java
  • 1. What is the main difference between a JDK and a JVM ?
JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.
  • 2. What is a pointer and how does Java support Pointers ?
Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn\'t support the usage of pointers.
  • 3. What is the main difference between private, protected, and public ?
These keywords are for allowing privileges to components such as java methods and variables.
Public: accessible to all classes.
Private: accessible only to the class to which they belong.
Protected: accessible to the class to which they belong and any subclasses.
Access specifiers are keywords that determines the type of access to the member of a class. These are:
                       * Public
                       * Protected
                       * Private
                        * Default
  • 4. What\'s the difference between a Vector and an Array List ?
Java Vector class is internally synchronized and Array List is not synchronized.
  • 5. Is Iterator a Class or Interface? What is its use ?
Iterator is an interface which is used to step through the elements of a Collection.
  • 6. What are Java transient variables ?
Transient variables are variable that cannot be serialized.
  • 7. Define Synchronization ?
Synchronization is the ability to control the access of multiple threads to shared resources. Synchronization stops Multithreading. With synchronization , at  a time only one thread will be able to access a shared resource.
  • 8. How can you force garbage collection in java ?
You cannot force Garbage Collection, but you can request for it by calling the method System.gc().  But it doesn't mean that Garbage Collection will start immediately. The garbage collection is a low priority thread of JVM.
  • 9. 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 also possible for programs to create objects that are not subject to garbage collection. And there is no guarantee that Garbage Collection thread will be executed.
  • 10. What must a class do to implement an interface ?
It must identify the interface in its implements clause. Also it must provide definition for all the methods in the interface otherwise it must be declared abstract.
  • 11. Why java is said as pass-by-value ?
When assigning an object to a variable, we are actually assigning the memory address of that object to the variable. So the value passed is actually the memory location of the object. This results in object aliasing, meaning you can have many variables referring to the same object on the heap.
  • 12. What is a object cloning ?
It is the process of duplicating an object so that two identical objects will exist in the memory at the same time.
  • 13. Define object pooling ?
Creating a large number of identical short lived objects is called object pooling. This helps to minimize the need of garbage collection and makes the memory use more effective.
  • 14. What are the disadvantage of garbage collection ?
It adds an overhead that can affect performance. Additionally there is no guarantee that the object will be garbage collected.
  • 15. Why Java is not fully objective oriented ?
Due to the use of primitives in java, which are not objects.
  • 16. What is marker interface ?
An interface that contains no methods. Eg: Serializable, Cloneable, SingleThreadModel etc. It is used to just mark java classes that support certain capability.
  • 17. What are tag interfaces ?
Tag interface is an alternate name for marker interface.
  • 18. What are the restrictions placed on static method ?
We cannot override static methods. We cannot access any object variables inside static method. Also the this reference also not available in static methods.
  • 19. Can we declare a static variable inside a method ?
Static Variables are class level variables and they can't be declared inside a method. If declared, the class will not compile.
  • 20. Can any Interface implement another Interface ?
Interfaces doesn't provide implementation hence a interface cannot implement another interface.
  • 21. Can any Interface extend another Interface ?
Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface.
  • 22. Can Class extend more than one Class ?
Not possible. A Class can extend only one class but can implement any number of Interfaces.
  • 23. What is the main difference between Iterator and Enumeration ?
Iterator differ from enumeration in two ways Iterator allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics. And , method names have been improved.
  • 24. What is internationalization ?
Internationalization is the process of designing an application so that it can be adapted to various languages and regions without changes.
  • 25. What is the difference between URL and URL Connection ?
A URL represents the location of a resource, and a URL Connection represents a link for accessing or communicating with the resource at the location.

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.