In this post, we will try to cover some of the important Java interview questions and answers that are required for aspirants facing hadoop developer interviews. We will touch base only the concepts that are needed for an hadoop developer or administrator.
Java Interview Questions and Answers for Experienced:
1. What is a JVM ?
JVM is Java Virtual Machine which is a run time environment for the compiled java class files.
2. What is Platform Independence ? Are JVM’s Platform Independent ?
The ability to write and compile programs in one platform (eg Windows) and can execute the same compiled object in any other supported platform (eg Linux) is called as Platform independence. Java is Platform Independent. I.e. We can write and compile java programs on windows machine and execute the classes on Linux machine. But JVM is not platform independent as it is specific to each platform run time environment.
3. What is the difference between a break statement and a continue
A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.
4. Does Java support pointers?
No. Because of their complexity and reliability issues Java doesn’t support Pointers.
5. Does Java support Multiple Inheritance? If not, How can we achieve Multiple Inheritance in Java?
No. But a class can implement multiple interfaces to overcome the lack of multiple inheritance.
6. How to compile all the files in a Folder ?
Use “javac *.java” command from the directory location of the java files to compile all the files at a time.
7. How to place compiled Java class files in a different directory ?
Use “javac -d <directory location> <SourceProgram>.java" command to place the compiled class files into a separate directory location. We need to give our required destination directory location in -d option.
8. What is the base class of all classes ?
9. What is difference between Path and Classpath ?
Path and Classpath are operating system level environment variables. Path is
used to define where the system can find the executable files and classpath is used to specify the location of .class files.
10. What are local variables ?
Variables declared within a block of code, like methods are called Local variables. Local variables should be initialized before accessing them.
11. What are instance variables ?
Variables that are defined at the class level are known as Instance variables. Instance
variables need not be initialized before using them as they are automatically initialized to their default values.
12. What are constant variable in Java ?
The variables declared as static and final are constant variables. So only one copy of the variable exists for all instances of the class and the value can’t be changed also.
Example: static final int PI = 2.14;
13. What is a Constructor ?
Constructors are used to initialize an object. Constructor’s are called when a method is initialized. Constructors cannot be inherited.
- Constructor has the same name as the class.
- Class can have more than one constructor.
- Constructor can take zero, one, or more parameters.
- Constructor has no return value.
- Constructor is always called with the new operator.
14. What is a Java package ?
Java Packages are used to group related classes. Packages should be defined at the start of source file. A class can have only one package. If packages are not declared it belongs to default package. Packages are hierarchical separated by columns. An example package definition is given below
15. What is the restriction for a package statement within a java source code file ?
A package statement must appear as the first line in a source code file (excluding blank lines and comments).
16. Which package is imported by default ?
java.lang package is imported by default. It is imported even without a package declaration.
17. What are private, protected and public access specifiers ?
Private is the most restrictive, while public is the least restrictive. There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package.
18. What is the return type of the main() method ?
main() method doesn’t return anything. Hence it is declared as void.
19. Is it mandatory to define a main() method in all java classes ?
No not required. main() method should be defined only if the source class is
a java application.
20. When will we define a method as static ?
When a method needs to be accessed even before the creation of the object
of the class then we should declare the method as static.