eProgrammingLab

Java Interview Questions


Java Interview Questions and Answers


1. What is source code?
Developer written program. It is written according to the programming language syntax. The .java (dot java) code is called source code.
2. What is compiled code?
Compiler generated program that is converted from source code.
3. What is compiler?
It is translation program that coverts source code into machine code language at once.
4. What is interpreter?
It is also a translation program that coverts source code into machine language, but line by line.
5. What is executable code?
OS understandable readily executable program (.files).
6. What is compilation?
It is process of translating source code into compiled code.
7. What is execution?
It is a process of running compiled code to get output.
8. What are the types of java software?
Java software is divided into two types: JDK (java development kit) and JRE (java runtime environment). JRE is included in JDK.
9. How do you create simple java program?
File => New => Java project. Give the project name. => finish. In src folder, right click. New => class => class name => finish.
10. What is different between JDK, JRE, and JVM?
JVM is a subset of JRE, and JRE is the subset of JDK. When we install JDK, JRE is also installed automatically.
• JDK has both compiler and JVM. So, we can compile and execute new java applications.
• JRE has JVM. Hence using JRE, we can only execute already developed applications.
11. What are the basic programming elements?
The basic programming elements are package, class, interface, enum, variables, and method.
12. What is package?
Package is a set of classes. It simply holds multiple classes. It is used to group related class.
13. If you do not create package, what will happen?
It will create default package.
14. What is class?
Class is a blue print of simple java files. All class, interface, and enum are java files used to group java data and logic.
15. What is variable?
Named memory location.
16. What is method?
Method is the sub block of a class. If you want to write any business logic, we will write inside the method.
17. What is enum?
Enum is like a menu.
18. What is token? How many types of token are there?
Java supports five types of tokens: comments, identifiers, keywords, separators, and operators.
19. What is the starting point of java program execution?
Main method is the starting point. Whenever we start the program, JVM will start to execute from main method.
20. What is identifier?
Identifier is simple name e.g. class name, method name, and variable name.
21. What is keyword?
Java has reserved words called keyword.
22. What is separator?
Dot, semicolon, comma etc.
23. What is operator?
Mathematical operators, comparison operators.
24. What is comment? What are the types of comments in java?
Java comments are statements that are not executed by the compiler and interpreter. The comments can be used to provide information or explanation about the variable, method, class or any statement. It can also be used to hide program code for specific time. There are three types of comments: • Single line comments (//), used to comment only one line. • Multiline comments (/* */), used to comment multiple lines of code. • Documentation line comments (/** */), used to create documentation API. To create documentation API, you need to use javadoc tool.
25. What is application programming interface (API)?
API has all predefined classes and predefined methods.
26. What is identifier?
Identifier is the name of basic programming elements e.g. class name, method name, and variable name. If we define any basic programming elements without name, compiler throws compile tome error ().
27. What are the rules in defining identifier?
• Identifier should only contain alphabets [a-z, A-Z], digits [0-9], and special characters [_ or $]. • Identifier should not start with a digit. • Identifier should not contain special characters other than _ and $. • Identifier should not contain space in the middle of words. • Identifier is case sensitive. • Keyword cannot be used as user defined identifier, because they are available throughout JVM directly.
28. For public class can class name and file name be different?
No. class name and file name must be same. If you remove public, class name and file name can be different.
29. How to rename file name?
Right click, re-factor, rename, ok.