In the present days, there is an increase in the IT and programming job market and most of the multi national companies are hiring the right students by offering good salary packages. These companies hire the candidate by filtering from thousands of students so it is a tough task to clear interview process. Different questions are collected from various sources by the companies and frame the best questions according to their requirement. So, the questions and answers presented in this article are really helpful for a student who is attending an interview. These are the most frequent core java questions asked to the candidates in an interview. All the questions are given best and appropriate answers which are useful to clear the technical round of an interview.
1. What is the key feature of Java?
The key feature of Java is platform independent.
2. What is platform independence?
Platform independence is writing and compiling the Java code on one platform and executing class in any other platform. For example if a programmer is writing and compiling the code on the windows platform then he can execute class is other platforms such as Solaris, LINUX, etc.
3. Define Java Virtual Machine?
JVM is the run time environment for complied java class files.
4. JVM is platform independent or not?
JVM is not platform dependent and it is a run time implementation in a specific platform which is provided by vendor.
5. Distinguish JVM and JDK?
JVM is completely a run time environment and you cannot compile source files using JVM whereas JDK is Java Development Kit used for development purpose and it has execution an environment.
6. Define transient variable?
A variable that is not serialized is known as transient variable.
7. Define synchronization and its importance?
The ability to control the access of multiple threads to shared resources with respect to multithreading is known as synchronization. One thread can modify shared object whereas other thread is updating object’s value. Often, it leads to errors.
8. Null is a keyword or not?
Null is not a keyword.
9. What is component preferred size?
Component preferred size is minimum component size that allows component to display normally.
10. Define pointer and does java support pointers?
Pointer points to a memory location. If the pointers are not handled properly then it results in reliability issues and memory leaks. Java language does not support pointers.
11. Do you find Multiple Inheritance in Java?
Multiple Inheritance is not supported by Java language.
12. Java is pure object oriented or not?
Primitive data type is used in Java language so it is not a pure object oriented language.
13. What are arrays?
Arrays are considered as objects in Java language.
14. Can you declare a class as static?
You cannot declare a class as static. A variable or method or block of code can be declared as static.
15. When will you declare a method as static?
A method is created as static only when you are interested in gaining access to a method before creating an object for that particular class.
16. What restrictions are imposed on static block of code or method?
A method which is declared as static is not referred to instance variables without creating instance and to refer the instance, you should not use “this” operator.
17. Define static variable?
Static variables are variables within a class where objects of that particular refer to same variable. If you change the value of one object then change can be noticed on all the objects.
18. Define abstract class and its purpose?
An abstract class is a class with do not have complete implementation. Abstraction is enforced by abstract class.
19. Can you declare an abstract class as final?
It is not possible. An abstract with final keyword is useless as inheritance gets stopped and finally, results in compile time error.
20. Define abstract variable?
You cannot declare variables as abstract. You can declare methods and classes as abstract.
21. Is it possible to create an object for an abstract class?
It is not possible to create object for abstract classes. You cannot instantiate abstract classes.
22. Can you create an abstract class without abstract methods?
It is possible. This is to avoid instance creation of class.
23. Can you declare a method inside an interface as final?
It is not possible to do like this. If you declare then it results in compilation error. Methods in an interface are declared only using the access modifiers such as abstract and public.
24. Can an interface implements other interface?
An interface cannot implement other interface as interfaces do not provide implementation.
25. Interface extending other interface is possible or not?
Yes, it is possible because an interface can inherit other interface. Here, interface can extend many interfaces.
26. Can a class extend multiple classes?
It is not possible to like this. Class can implement numerous interfaces but it can extend only one class.
27. Can you declare an interface as final?
No, it is not possible. If you declare an interface as final then it results in compilation error.
28. Can you define an interface inside a class?
Yes, it is possible to declare an interface inside a class.
29. Define marker interface?
A interface without declaration inside but it implements a mechanism is known as marker interface.
30. Can you declare an abstract class without abstract methods?
Yes, this way you can avoid creation of an instance of a class.
31. Define a package?
A collection of related classes and interfaces is known as a package. In a java class, package should be declared first.
32. Default package imported is?
The default package imported is java.lang package. Thus, this package is imported without declaring it.
33. If you declare a class as private access modifier, can you access it outside the package?
No, it is not possible. The class which is declared as private in one package cannot be accessed outside the other package.
34. Can you declare a class as protected?
You cannot declare a class as protected and only you can declare methods as protected.
35. What is protected method access scope?
A protected method is accessed by classes in the package or the subclass of any other package.
36. Why do you declare a variable as final?
If you declare a variable as final then its value cannot be changed. You must initialize variables which are declared as final before using them.
37. Why do you declare a method as final?
You cannot override the method which is declared as final. A subclass should not have a signature of same method with different implementation.
38. What you should do when you do not want to inherit your class?
You can stop inheritance by declaring your class using final keyword. A final class cannot be extended by any class.
39. Can you cast byte object to double value?
No, it is not possible. You cannot cast an object to primitive value.
40. Distinguish non-static and static inner class?
Non-static inner classes have object instances related to instances of class’s outer class whereas a static inner class does not have object instances.
41. Define % operator?
It is referred as remainder or modulo operator. It gives the remainder by dividing first operand by second operand.
42. Which class is extended by other classes?
Any class can extend an object class.
43. Define casting?
In general, there are two different types of castings like the casting between object references and casting between primitive numeric types. In the numeric types of casting, large values are converted to smaller values. Example: large value such as a double can be converted into smaller values like byte. Object reference casting refers to an object by an interface, compatible class or an array type reference.
44. Define down casting?
Casting from a general to specific type is called as down casting.
45. Define native method?
It is a method which is implemented in a language other than Java.
46. Distinguish window and frame?
Window is extended by frame class to define main application window which is having a menu bar.
47. Can a reachable object be garbage collected?
A reachable object can never be garbage collected. The objects which are not used for longer time is removed by the garbage collector.
In the above session, core java questions and answers essential for clearing the technical round for both fresher’s and experienced candidates are discussed in detail. The candidate can improve their technical skills and can revise the concepts quickly by going through these questions. Many candidates who come for the interview give the answer for the questions asked by the employer but the job is given to the candidate who is given the best and appropriate answer.