Haryana Engineering College , Engineering Institutes in Haryana, Engineering Colleges in Haryana, Haryana Engineering Colleges , Engineering Colleges in Haryana, Haryana Engineering Colleges, Engineering Institutes in Haryana, Haryana Engineering Institutes, List of Engineering Colleges in Haryana, Haryana Engineering Colleges List, List of Engineering Institutes in Haryana, Haryana Engineering Institutes List , Haryana Engineering College Exams in India , Ranking of haryana engineering colleges , Engineering Colleges in Haryana Institutes in India

Monday, August 18, 2008

Java Interview Questions




What is JAVA?
Java is a programming language expressly designed for use in the distributed environment of the Internet.
What happen when the main method is declared as private?
When the main method is private then it compiles but on run time it give Main method not public message.

What is the Java API?

  • Collection of ready made software component
  • Provide many useful capabilities , Like graphical user interface(GUI) widgets

Can you call one constructor from another if a class has multiple constructors

Yes. Use this() syntax.

Difference between notify and notify All methods ?

A call to notify causes at most one thread waiting on the same object to be notified (i.e., the object that calls notify must be the same as the object that called wait). A call to notifyAll causes all threads waiting on the same object to be notified. If more than one thread is waiting on that object, there is no way to control which of them is notified by a call to notify (so it is often better to use notifyAll than notify).

What is the Java Virtual Machine (JVM)?

The Java Virtual Machine, or JVM, is an abstract computer that runs compiled Java programs. All Java programs are compiled for the JVM. Therefore, the JVM must be implemented on a particular platform before compiled Java programs will run on that platform.

What do you understand by downcasting?

Down Casting means : Casting down the hierarchy. It refers to casting from a general to a more specific type.

What is OOPS?
OOPS : Object-Oriented Programming

  • It allows the creation of an object
  • It consider the programming simulated to real world objects.
  • It help in programming approach in order to built robust,user friendly and efficient software's and provide the efficient way to maintain real world software's.

What is Hash Map and Map?

Map is Interface and Hash map is class that implements that.

Difference between Application Server and web server?

Web Server is limited to Web Technology and more over it can't deploy the Enterprise applications. So in order to deploy Enterprise applications(EAR Files), we need Application Server. And More Over Web server supports all kinds of protocols not only http.It can support FTP and any, provided the concern jar files must be placed in the lib folder of the Web Server.

What is Overriding?

Overriding methods:

  • appear in subclasses
  • Same name as in super Class .
  • same parameter list
  • same return type

what is Overloading?

  • appear in the same class or a subclass
  • same name
  • different parameter lists
  • different return types

Explain the different forms of Polymorphism.

Java : polymorphism exists in three distinct forms
Method overloading
Method overriding through inheritance
Method overriding through the Java interface

What is the common usage of serialization?

Whenever an object is to be sent over the network, objects need to be serialized. Moreover if the state of an object is to be saved, objects need to be serialized.

Explain the Polymorphism principle.

Polymorphism in simple terms means one name many forms. Polymorphism enables one entity to be used as a general category for different types of actions. The specific action is determined by the exact nature of the situation.

Different types of access modifiers?

Access specifiers are used to determine type of access to the member of the class .

These are :

  • Public : Used for all classes means all class can accessible .
  • Protected : accessible to the classes within the same package and any subclasses.
  • Private : accessible only to the class to which they belong
  • Default : accessible to the class to which they belong and to subclasses within the same package

Which class is the super class of every class?
Object.

Explain different way of using thread?

The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cause when you are going for multiple inheritance..the only interface can help.

Can I have multiple main methods in the same class?

No the program fails to compile. The compiler says that the main method is already defined in the class.

If you’re overriding the method equals() of an object, which other method you might also consider?
hashCode()

When the method invokeLater() be used?
To ensure that Swing components are updated through the event-dispatching thread.

what is a collection ?

Collection is a group of objects. java.util package is important.

  • Collection types hold a group of objects, Eg. Lists and Sets
  • where as Map types hold group of objects as key, value pairs Eg. HashMap and Hashtable.

What's the difference between constructors and other methods?

  • Constructors must have the same name as the class
  • can not return a value.
  • They are only called once while regular methods could be called many times.

What’s the difference between an interface and an abstract class?

  • An abstract class may contain code in method bodies, which is not allowed in an interface.
  • With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.

What methods java providing for Thread communications ?

Java provides three methods

  • Wait
  • Notify
  • NotifyAll

The idea is that a method called by a thread may need to wait for some condition to be satisfied by another thread; in that case, it can call the wait method, which causes its thread to wait until another thread calls notify or notifyAll.

What is serialization ?

Serialization is the process of writing complete state of java object into output stream, that stream can be file or byte array or stream associated with TCP/IP socket.

Explain the usage of Java packages.

  • Organize file when it contain multiple modules
  • Help in naming conflict when different packages have class with same name.
  • Packages access level also allows you to protect data from being used by the non-authorized classes.

Can I call a abstract method from a non abstract method ?

Yes

In System.out.println(), what is System, out and println?

  • System is a predefined final class
  • out is a PrintStream object
  • and println is a built-in overloaded method in the out object.

What happens to the static fields of a class during serialization?

There are three exceptions in which serialization does not necessarily read and write to the stream.

These are

  • Serialization ignores static fields, because they are not part of any particular state state.
  • Base class fields are only handled if the base class itself is serializable.
  • Transient fields.

Difference between the methods sleep() and wait() ?

The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second.
  • A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.
  • -------------------Updated Jan 28 2007

    What is the difference between an Interface and an Abstract class?

    An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.

    What is the purpose of garbage collection in Java, and when is it used?

    The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.


    Describe synchronization in respect to multithreading.

    With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchonization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.

    Explain different way of using thread?

    The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cause when you are going for multiple inheritance..the only interface can help.

    What are pass by reference and passby value?

    Pass By Reference means the passing the address itself rather than passing the value. Passby Value means passing a copy of the value to be passed.

    What is HashMap and Map?

    Map is Interface and Hashmap is class that implements that

    Difference between HashMap and HashTable?

    The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesnt allow). HashMap does not guarantee that the order of the map will remain constant over time. HashMap is unsynchronized and Hashtable is synchronized.

    Difference between Vector and ArrayList?

    Vector is synchronized whereas arraylist is not.

    Difference between Swing and Awt?

    AWT are heavy-weight componenets. Swings are light-weight components. Hence swing works faster than AWT.


    What is the difference between a constructor and a method?

    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.

    State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers.

    public : Public class is visible in other packages, field is visible everywhere (class must be public too)private : Private variables or methods may be used only by an instance of the same class that declares the variable or method, A private feature may only be accessed by the class that owns the feature.protected : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature.This access is provided even to subclasses that reside in a different package from the class that owns the protected feature.default :What you get by default ie, without any access modifier (ie, public private or protected).It means that it is visible to all within a particular package.


    What is static in java?

    Static means one per class, not one for each object no matter how many instance of a class might exist. This means that you can use them without creating an instance of a class.Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object. A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can't override a static method with a nonstatic method. In other words, you can't change a static method into an instance method in a subclass.

    What is final?

    A final class can't be extended ie., final class may not be subclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant).

    What if the main method is declared as private?

    The program compiles properly but at runtime it will give "Main method not public." message.



    0 comments:

    About This Blog

    Lorem Ipsum

    Back to TOP