Important Questions of JAVA Asked in Technical Interview and Online Test





1. Why is java platform independent?

Ans : Java is platform independent because compiler converts the source code to byte code. The byte codes are machine(platform) independent and it can be run in any machine and thus Java code can be executed in any platform like Windows, Linux, Solaris etc. We can say, “compile once and run anywhere". Though we require Java Virtual Machine(JVM) to compile and execute Java in any platform.

2. What is the difference between JDK and JVM?

    Java Development Kit(JDK): JDK is program development kit for Java application and applets
    Java Virtual Machine(JVM): JVM provide runtime environment to execute byte code.


3. What is Static Keyword?

Ans : Static keyword can be used for variable, method, block and nested class. It is used for memory management, as the same data is reserved for all.

4. Difference between Over-Riding and Over-Loading in java?

Ans : Overloading occurs during compile time while overriding occurs during runtime. Overloading has two or more methods in same class but with different arguments whereas overriding has two different methods with same name and argument i.e. one is parent class and other is child class.

5. What is Constructor?

Ans : Constructor are used to initialize Objects. It can invoked when Object of the Class is created. Constructor name should be exactly the same as its class name.Java provides default contractor with no argument

6. Difference between Throw and Throws?

Ans : Throw keyword can throw exception explicitly (in any static block and method) whereas throws keyword declare exception.

7. What is Multi-Threading in java?

Ans : Multithreading in Java is a process in which multiple processes(threads -lightweight sub process) can be executed simultaneously.

8. What is Object?

Ans : An Object is instance of a class. Memory is allocated when it is first created. Object have sub-object while class can have multiple sub-class.

9. What is Class?
Ans :

    Class defines methods(functions) and members(variables) that are included in object.
    Class is the blueprint used to create object. Memory is not allocated, when class is created.
    Class is user-defined which can be used to defined methods & functions and declare objects.


10. Difference between class and object?

Ans :

    ·         Object is instance of class
    ·         Class does not stored any information while object stores it.
    ·         Class can have sub-classes but object cannot.


11 . What are java primitive Data types?

Ans : Variable in java must be declared before using them. There are two types declaring variables : Reference(reference to object) type and Primitive type(directly contains value). Java supports eight primitive types. They are :

    ·         Char 16-bit
    ·         Byte 8-bit
    ·         Short 16-bit
    ·         Int 32-bit
    ·         Long 64-bit
    ·         Float 32-bit
    ·         Double 64-bit
    ·         Boolean 1-bit


12. Does java Supports pointers?

Ans : No, java does not support pointers though java has reference(stores an address). Pointers create lot of confusion for memory allocation and it has lot of bugs, so java creators have decided to remove pointers( which is supported by C/C++).

13. What are local and instance variable?

Ans : Local variables are accessible only in the method or block they are declared whereas instance variable are accessible in all methods. Local variable can be created inside the method and destroy when the local variable exit the method. Instance variables are declared in class but outside the method, block. When object is created by new keyword, instance variable are created and instance variable are destroyed when object is destroyed.

14. What is the difference between path and class path?

Ans :Path is the environmental variable used by the operating system to find executable files(.exe). Classpath is the environmental variable used by the java Compiler(JVM) to find class files(.class).

15. What is autoboxing and unboxing?

Ans : Autoboxing and unboxing was introduced in JDK 5. When primitive data types are converted into it equivalent wrapper type automatically is called autoboxing and reverse operation of autoboxing(i.e. wrapper types to primitive types) is called unboxing.

16. Is constructor overriding possible in java?

Ans : No, constructor cannot be overridden, though we can overload constructor.

17. What are the data types supported by java?

Ans : In Java, there are two types of Data types. They are: primitive data types(short, int, byte, long, float etc.) and non-primitive datatypes(class, interface, arrays).

18. What is Abstract Class?

Ans :Abstract class in Java cannot be initialized i.e. We cannot create instance of abstract class. Abstract class must have abstract method.

19. Difference between Abstraction and Encapsulation?

Ans : Abstraction is the process of hiding implementation whereas encapsulation means hiding data. Abstraction can be achieved by using interface and abstract class, encapsulation by using private.

20. What is inheritance?

Ans : In inheritance, one object(or class) inherits(acquires) all the properties and behavior of another object(or class).
Inheritance is possible by implementing, extends and implement keywords. E.g. SubClass extends ParentClass.

21 . What is Enum in java?

Ans : In Java, enum is a keyword, used to defined fixed number of constants. Enum values are final and cannot be changed once it values is created. E.g. enum WeekDays{ Mon, Tue, Wed, Thur, Fri, Sat, Sun}

22. What is classloaders and what are the different types of class loader?

Ans : In Java, Classloaders loads java Classes into the java Virtual Machine(JVM) at runtime dynamically, There are types of class loaders: Bootstrap class loaders, Extension class loaders and system class loaders

23. What is the use of super keyword?

Ans : Super keyword is used to provide reference to the base class. It is used to access method of base class and also immediate parent class instant variable.

24. What is this keyword?

Ans : This keyword is used to access method if current class. It is used to refer current class instance variable. It is also used as reference variable to current class object.

25. Difference between break and continue?

Ans : Break statement is used for termination of loop(further execution will stops in the loop) whereas continue statement stops current loop and proceeds with next iteration in the loop.

26. What are marker interface?

Ans : Empty interface with no methods and field in java is called as Marker Interface. Example for marker interface are Searilizable interface, Cloneable interface, Remote interface etc.

27. What is the difference between inner class and nested class?

Ans : There are two types of nested class: static nested class and non-static nested class. A nested class declared as static is called as static nested class and non-static nested class are known as inner class.

28. What are access modifier?

Ans : Java access modifiers specify(set access) access for classes, variables, methods and constructors. They are four types of access modifiers in Java: private, protected, public and package(default).

29. Can main() method overload?

Ans : Yes, main0 method can be overload in class by overloading the main method.

30. What is static block and static variable?
·   
     Ans :

         Static variables are declared by static keyword and it can be used common for all objects.
         Static Variable gets memory only once during class loading.
    ·    Static blocks used to initialized static data(static variable) and it is executed before main method during class loading.



31 . What is downcasting?

Ans : When is superclass is casted to subclass, it is called as down casting.

32. Is null a keyword?

Ans : The null value is not a keyword.

33. What is Thread in java?

Ans : Thread is a light weight sub process, it helps to perform different task concurrently. Thread can be implementing by using Runnable lnterface(java.lang.Runnable) and by extending thread class(java.lang.Thread).

34. What are the life cycle of thread?

Ans : The life cycle of thread are: New, Runnable, Blocked, Waiting, Timed_Waiting and Terminated

35. Why Interface cannot be declared as final?

Ans : When we use final, method cannot be overridden, thus if interface in java declared as final, then it can be extended which could defy the point of using interface. So, interface cannot be declared as final.

36. What is package?

Ans : Packages are used to group similar(related) classes and interfaces. They also allow name space management and access of those package. They are two types of packages: build-in package and user-defined package.

37. What is the use of garbage collection?

Ans : Garbage collection are used for memory managements. When an object is stored in heap
memory and no longer used, it will automatically cleaned(memory deallocation) by Garbage collector and thus used by subsequent new objects.

38. What are Applets?

Ans : Applets are small interactive internet-based java programs, which can be run in web browser. Applets are downloaded by the users machine and it can be embed into HTML easily. JVM is required to run Applets.

39. What is Daemon Thread?

Ans :Daemon Threads runs in background even when the thread is finished and does not prevent JVM from exiting.Example for Daemon thread is garbage collection.

40. What is the return type of a main method in java?

Ans : The main() method in java does not have a return type. It has void type though.
- See more at: http://www.allrecentjobs.com/2014/10/important-questions-of-java-asked-in.html#sthash.3TbFcaXC.dpuf
printf("Enter the values for x and y:");
scanf(“%d%d",&x,&y);
z=sumof(x,y)
printf("T he sum of x and y is: %d",z);
{
return(a+b)
Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment