These Java programming interview questions have been designed especially for the beginner. I have listed the basic concept of the subject.
1. What are the significant features of OOP?
The significant features of OOP are
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction.
2. What is Java Virtual Machine?
A Java virtual machine is also known as JVM, which is an abstract computing machine that enables a computer to run Java bytecodes. Each source file of Java is compiled into bytecode files which is executed by the JVM.
3. What does static keyword mean?
The static keyword in Java is mainly used for memory management. Static keyword can be applied with methods, blocks, variables and nested class.
4. What is static variable?
If a variable is declared as static, then it is known as static variables. The static variable can be used to refer the common property of all the objects. It gets memory only once in the class area at the time of class loading.
5. What are the data type supported by java?
The primitive data type supported by java is
- int
- long
- float
- double
- boolean
- char
- byte
- short
6. Does java support multiple inheritance?
No, Java doesn’t support multiple inheritance.
7. What is the difference between public,private and protected?
- Public: Accessible to all classes.
- Private: Accessible only to the class to which they belong.
- Protected: Accessible to the class to which they belong and to any subclasses.
8. Define garbage collection ?
Garbage collection is also called as automatic memory management. As it automatically removes the unused variables and objects. garbage collection is an automatic process and you can request it by calling System.gc().
9. what is the usage of Java package?
Java package helps to organize files when a project consists of multiple modules. It also helps to resolve naming conflict when different packages have classes with same names.
10. Explain the main difference between a vector and an ArrayList?
ArrayList is not synchronized and Java vector class is internally synchronized.
11. What is the output of the below statement?
String s1 ="def" String s2="def" System.out.println("s1== s2 is:" + s1==s2);
Output False, Because in Java operator"+", precedence is more than == operational.
12. Write a program to print prime number in Java?
class primenumbers { public static void main(String[] args) { int num=25; int count=0; for(int i=2;i<=num;i++){ count=0; for(int j=2;j<=i/2;j++){ if(i%j==0){ count++; break; } } if(count==0){ System.out.println(i); } } } }
Output 2 3 5 7 11 13 17 19 23
13. what is the difference between thread and process?
A thread is a single execution sequence within a process while a process is an execution of a program. A thread is sometimes called a lightweight process.
14. What are Wrapper classes?
Wrapper classes are the classes that allow primitive type to be accessed as objects.
15. what is the local variable default value?
It has neither primitives nor object references and it is not initialized to any default value.
16. What is JDBC?
JDBC is defined as Java Database Connectivity. It is a Java API used to interact with different varieties of database from a Java application.
17. What is meant by Encapsulation?
It is defined as a process of wrapping the data and code together into a single unit.
18. Write a program to get a given string in reverse order?
program: class Reverse ( public static void main(String args[]) { String s = "malayalam "; for(int i = 1; i <= s.length(); i++) { System.out.print(s.charAt(s.length()-i)); } } }
Output malayalam
19. What is Ternary operator?
The ternary operator is also known as called as conditional operators are used to decide which value to assign to a variable. Assigning is based on a Boolean value evaluation.
20. What is meant by pivot?
Pivot is an operator used to convert rows into column dynamically.
21.What is the output of the below statements?
String s2 = "Javaprogram"; int start = 1; char end = 5; System.out.println(start + end); System.out.println(s2.substring(start, end));
Output The output will be "avap"
22. What are two types of exception handling in Java?
- checked exceptions
- unchecked exceptions
23. Life cycle of Applet?
- Init
- Start
- Stop
- Destroy
24. Which swing methods are thread safe?
- Repaint,
- Invalidate.
- Revalidate
25. List the layers of RMI Architecture?
- Stub and Skeleton layer
- Remote Reference Layer
- Transport layer