SlideShare a Scribd company logo
INTERVIEW QUESTIONS
(Java Interview Questions)
© EME TECHNOLOGIES
Interview Questions
1. What is the most important feature of Java?
Java is a platform independent language.
2. What do you mean by platform independence?
Platform independence means that we can write and compile the java code in one
platform (eg Windows) and can execute the class in any other supported platform
eg (Linux,Solaris,etc).
3. What is a JVM?
JVM is Java Virtual Machine which is a run time environment for the compiled java
class files.
4. Are JVM’s platform independent?
JVM’s are not platform independent. JVM’s are platform specific run time
implementation provided by the vendor.
5. What is the difference between a JDK and a JVM?
JDK is Java Development Kit which is for development purpose and it includes
execution environment also. But JVM is purely a run time environment and hence
you will not be able to compile your source files using a JVM.
2
© EME TECHNOLOGIES
3
© EME TECHNOLOGIES
Interview Questions
6. What is a pointer and does Java support pointers?
Pointer is a reference handle to a memory location. Improper handling of pointers
leads to memory leaks and reliability issues hence Java doesn’t support the usage
of pointers.
7. What is the base class of all classes?
java.lang.Object
8. Does Java support multiple inheritance?
Java doesn’t support multiple inheritance.
9. Is Java a pure object oriented language?
Java uses primitive data types and hence is not a pure object oriented language.
10. Are arrays primitive data types?
In Java, Arrays are objects.
11. What is difference between Path and Classpath?
Path and Classpath are operating system level environment variales. Path is used
define where the system can find the executables(.exe) files and classpath is used
to specify the location .class files.
4
© EME TECHNOLOGIES
Interview Questions
12. What are instance variables?
Instance variables are those which are defined at the class level. Instance
variables need not be initialized before using them as they are automatically
initialized to their default values.
13. How to define a constant variable in Java?
The variable should be declared as static and final. So only one copy of the
variable exists for all instances of the class and the value can’t be changed also.
static final int PI = 2.14; is an example for constant.
14. Should a main() method be compulsorily declared in all java classes?
No not required. main() method should be defined only if the source class is a java
application.
15. What is the return type of the main() method?
Main() method doesn’t return anything hence declared void.
16. Why is the main() method declared static?
main() method is called by the JVM even before the instantiation of the class hence
it is declared as static.
5
© EME TECHNOLOGIES
Interview Questions
17. What is the arguement of main() method?
main() method accepts an array of String object as arguement.
18. Can a main() method be overloaded?
Yes. You can have any number of main() methods with different method signature
and implementation in the class.
19. Can a main() method be declared final?
Yes. Any inheriting class will not be able to have it’s own default main() method.
20. Does the order of public and static declaration matter in main() method?
No. It doesn’t matter but void should always come before main().
21. Can a source file contain more than one class declaration?
Yes a single source file can contain any number of Class declarations but only one
of the class can be declared aspublic.
22. What is a package?
Package is a collection of related classes and interfaces. package declaration
should be first statement in a java class.
23. Which package is imported by default?
java.lang package is imported by default even without a package declaration.
6
© EME TECHNOLOGIES
Interview Questions
24. Can a class be declared as protected?
A class can’t be declared as protected. only methods can be declared
as protected.
25. What is the access scope of a protected method?
A protected method can be accessed by the classes within the same package
or by the subclasses of the class in any package.
26. What is the purpose of declaring a variable as final?
A final variable’s value can’t be changed. final variables should be initialized
before using them.
27. What is the impact of declaring a method as final?
A method declared as final can’t be overridden. A sub-class can’t have the
same method signature with a different implementation.
28. I don’t want my class to be inherited by any other class. What should i
do?
You should declared your class as final. But you can’t define your class
as final, if it is an abstract class. A class declared as final can’t be extended by
any other class.
7
© EME TECHNOLOGIES
Interview Questions
29. Can we declare a static variable inside a method?
Static varaibles are class level variables and they can’t be declared inside a
method. If declared, the class will not compile.
30. What is use of a abstract variable?
Variables can’t be declared as abstract. only classes and methods can be
declared as abstract.
31. Class C implements Interface I containing method m1 and m2
declarations. Class C has provided implementation for method m2. Can i
create an object of Class C?
No not possible. Class C should provide implementation for all the methods in
the Interface I. Since Class Cdidn’t provide implementation for m1 method, it has
to be declared as abstract. Abstract classes can’t be instantiated.
32. What is a Marker Interface?
An Interface which doesn’t have any declaration inside but still enforces a
mechanism.
33. Which object oriented Concept is achieved by using overloading and
overriding?
Polymorphism. 8
© EME TECHNOLOGIES
Interview Questions
34. Why does Java not support operator overloading?
Operator overloading makes the code very difficult to read and maintain. To
maintain code simplicity, Java doesn’t support operator overloading.
35. Can we define private and protected modifiers for variables in interfaces?
No.
36. What is Externalizable?
Externalizable is an Interface that extends Serializable Interface. And sends data
into Streams in Compressed Format. It has two
methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in)
37. What modifiers are allowed for methods in an Interface?
Only public and abstract modifiers are allowed for methods in interfaces.
38. Can a Byte object be cast to a double value?
No, an object cannot be cast to a primitive value.
39. What is the difference between a static and a non-static inner class?
A non-static inner class may have object instances that are associated with
instances of the class’s outer class. A static inner class does not have any object
instances.
9
© EME TECHNOLOGIES
Interview Questions
40. When can an object reference be cast to an interface reference?
An object reference be cast to an interface reference when the object implements
the referenced interface.
41. Which class is extended by all other classes?
The Object class is extended by all other classes.
42. Which non-Unicode letter characters may be used as the first character of
an identifier?
The non-Unicode letter characters $ and _ may appear as the first character of an
identifier
43. What is a native method?
A native method is a method that is implemented in a language other than Java.
44. Can an anonymous class be declared as implementing an interface and
extending a class?
An anonymous class may implement an interface or extend a superclass, but may
not be declared to do both.
45. Does a class inherit the constructors of its superclass?
A class does not inherit constructors from any of its superclasses.
10
© EME TECHNOLOGIES
Interview Questions
46. What modifiers can be used with a local inner class?
A local inner class may be final or abstract.
47. When does the compiler supply a default constructor for a class?
The compiler supplies a default constructor for a class if no other constructors are
provided.
48. If a method is declared as protected, where may the method be accessed?
A protected method may only be accessed by classes or interfaces of the same
package or by subclasses of the class in which it is declared.
49. What are the legal operands of the instanceof operator?
The left operand is an object reference or null value and the right operand is a
class, interface, or array type.
50. To what value is a variable of the boolean type automatically initialized?
The default value of the boolean type is false.
11
© EME TECHNOLOGIES
12
© EME TECHNOLOGIES
Questions and Comments
13

More Related Content

PDF
20 most important java programming interview questions
DOCX
Java Core
DOCX
Core java questions
DOCX
Basic java important interview questions and answers to secure a job
DOCX
DOCX
Java questions for viva
PDF
Java Interview Questions by NageswaraRao
PDF
37 Java Interview Questions
20 most important java programming interview questions
Java Core
Core java questions
Basic java important interview questions and answers to secure a job
Java questions for viva
Java Interview Questions by NageswaraRao
37 Java Interview Questions

What's hot (19)

PPTX
Java interview questions 2
DOCX
Design pattern application
PDF
Java scjp-part1
PDF
Java design pattern tutorial
PDF
Java questions for interview
PPT
8 most expected java interview questions
DOC
Java faq's
PDF
Understanding And Using Reflection
PPTX
Lecture 17
PDF
Java interview questions and answers
PDF
Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007
PPTX
Reflection in Java
PPTX
Lecture 12
DOC
Core java questions
PDF
Professional-core-java-training
PPTX
Java programming(unit 1)
PPTX
Java interview questions 1
PPT
Unit 4 Java
DOCX
Java notes
Java interview questions 2
Design pattern application
Java scjp-part1
Java design pattern tutorial
Java questions for interview
8 most expected java interview questions
Java faq's
Understanding And Using Reflection
Lecture 17
Java interview questions and answers
Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007
Reflection in Java
Lecture 12
Core java questions
Professional-core-java-training
Java programming(unit 1)
Java interview questions 1
Unit 4 Java
Java notes
Ad

Similar to Top 10 Interview Questions For Java (20)

PDF
1669617800196.pdf
PDF
Top 100 Java Interview Questions with Detailed Answers
PDF
Android interview questions
PDF
Android interview questions
PDF
__ Java Technical round questions .pdf soo
PDF
Java interview question
DOCX
Java Core Parctical
DOC
Java interview questions
PDF
Top 100 Java Interview Questions and Answers.pdf
DOCX
Java Interview Questions For Freshers
PDF
Java interview questions
PDF
java basic .pdf
PPTX
Dev labs alliance top 20 basic java interview question for sdet
PPTX
Top 20 basic java interview questions for SDET
PPTX
Dev labs alliance top 20 basic java interview questions for sdet
PDF
50+ java interview questions
PDF
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
DOCX
What are the different java interview questions you need to know?
PPT
PDF
Asked Java Interview Questions for fresher
1669617800196.pdf
Top 100 Java Interview Questions with Detailed Answers
Android interview questions
Android interview questions
__ Java Technical round questions .pdf soo
Java interview question
Java Core Parctical
Java interview questions
Top 100 Java Interview Questions and Answers.pdf
Java Interview Questions For Freshers
Java interview questions
java basic .pdf
Dev labs alliance top 20 basic java interview question for sdet
Top 20 basic java interview questions for SDET
Dev labs alliance top 20 basic java interview questions for sdet
50+ java interview questions
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
What are the different java interview questions you need to know?
Asked Java Interview Questions for fresher
Ad

Recently uploaded (20)

PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Geodesy 1.pptx...............................................
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
web development for engineering and engineering
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Digital Logic Computer Design lecture notes
PPTX
Construction Project Organization Group 2.pptx
PPT
Mechanical Engineering MATERIALS Selection
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
OOP with Java - Java Introduction (Basics)
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Geodesy 1.pptx...............................................
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
web development for engineering and engineering
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
bas. eng. economics group 4 presentation 1.pptx
CH1 Production IntroductoryConcepts.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Digital Logic Computer Design lecture notes
Construction Project Organization Group 2.pptx
Mechanical Engineering MATERIALS Selection

Top 10 Interview Questions For Java

  • 2. © EME TECHNOLOGIES Interview Questions 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (Linux,Solaris,etc). 3. What is a JVM? JVM is Java Virtual Machine which is a run time environment for the compiled java class files. 4. Are JVM’s platform independent? JVM’s are not platform independent. JVM’s are platform specific run time implementation provided by the vendor. 5. What is the difference between a JDK and a JVM? JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM. 2
  • 4. © EME TECHNOLOGIES Interview Questions 6. What is a pointer and does Java support pointers? Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn’t support the usage of pointers. 7. What is the base class of all classes? java.lang.Object 8. Does Java support multiple inheritance? Java doesn’t support multiple inheritance. 9. Is Java a pure object oriented language? Java uses primitive data types and hence is not a pure object oriented language. 10. Are arrays primitive data types? In Java, Arrays are objects. 11. What is difference between Path and Classpath? Path and Classpath are operating system level environment variales. Path is used define where the system can find the executables(.exe) files and classpath is used to specify the location .class files. 4
  • 5. © EME TECHNOLOGIES Interview Questions 12. What are instance variables? Instance variables are those which are defined at the class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values. 13. How to define a constant variable in Java? The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can’t be changed also. static final int PI = 2.14; is an example for constant. 14. Should a main() method be compulsorily declared in all java classes? No not required. main() method should be defined only if the source class is a java application. 15. What is the return type of the main() method? Main() method doesn’t return anything hence declared void. 16. Why is the main() method declared static? main() method is called by the JVM even before the instantiation of the class hence it is declared as static. 5
  • 6. © EME TECHNOLOGIES Interview Questions 17. What is the arguement of main() method? main() method accepts an array of String object as arguement. 18. Can a main() method be overloaded? Yes. You can have any number of main() methods with different method signature and implementation in the class. 19. Can a main() method be declared final? Yes. Any inheriting class will not be able to have it’s own default main() method. 20. Does the order of public and static declaration matter in main() method? No. It doesn’t matter but void should always come before main(). 21. Can a source file contain more than one class declaration? Yes a single source file can contain any number of Class declarations but only one of the class can be declared aspublic. 22. What is a package? Package is a collection of related classes and interfaces. package declaration should be first statement in a java class. 23. Which package is imported by default? java.lang package is imported by default even without a package declaration. 6
  • 7. © EME TECHNOLOGIES Interview Questions 24. Can a class be declared as protected? A class can’t be declared as protected. only methods can be declared as protected. 25. What is the access scope of a protected method? A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package. 26. What is the purpose of declaring a variable as final? A final variable’s value can’t be changed. final variables should be initialized before using them. 27. What is the impact of declaring a method as final? A method declared as final can’t be overridden. A sub-class can’t have the same method signature with a different implementation. 28. I don’t want my class to be inherited by any other class. What should i do? You should declared your class as final. But you can’t define your class as final, if it is an abstract class. A class declared as final can’t be extended by any other class. 7
  • 8. © EME TECHNOLOGIES Interview Questions 29. Can we declare a static variable inside a method? Static varaibles are class level variables and they can’t be declared inside a method. If declared, the class will not compile. 30. What is use of a abstract variable? Variables can’t be declared as abstract. only classes and methods can be declared as abstract. 31. Class C implements Interface I containing method m1 and m2 declarations. Class C has provided implementation for method m2. Can i create an object of Class C? No not possible. Class C should provide implementation for all the methods in the Interface I. Since Class Cdidn’t provide implementation for m1 method, it has to be declared as abstract. Abstract classes can’t be instantiated. 32. What is a Marker Interface? An Interface which doesn’t have any declaration inside but still enforces a mechanism. 33. Which object oriented Concept is achieved by using overloading and overriding? Polymorphism. 8
  • 9. © EME TECHNOLOGIES Interview Questions 34. Why does Java not support operator overloading? Operator overloading makes the code very difficult to read and maintain. To maintain code simplicity, Java doesn’t support operator overloading. 35. Can we define private and protected modifiers for variables in interfaces? No. 36. What is Externalizable? Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in) 37. What modifiers are allowed for methods in an Interface? Only public and abstract modifiers are allowed for methods in interfaces. 38. Can a Byte object be cast to a double value? No, an object cannot be cast to a primitive value. 39. What is the difference between a static and a non-static inner class? A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances. 9
  • 10. © EME TECHNOLOGIES Interview Questions 40. When can an object reference be cast to an interface reference? An object reference be cast to an interface reference when the object implements the referenced interface. 41. Which class is extended by all other classes? The Object class is extended by all other classes. 42. Which non-Unicode letter characters may be used as the first character of an identifier? The non-Unicode letter characters $ and _ may appear as the first character of an identifier 43. What is a native method? A native method is a method that is implemented in a language other than Java. 44. Can an anonymous class be declared as implementing an interface and extending a class? An anonymous class may implement an interface or extend a superclass, but may not be declared to do both. 45. Does a class inherit the constructors of its superclass? A class does not inherit constructors from any of its superclasses. 10
  • 11. © EME TECHNOLOGIES Interview Questions 46. What modifiers can be used with a local inner class? A local inner class may be final or abstract. 47. When does the compiler supply a default constructor for a class? The compiler supplies a default constructor for a class if no other constructors are provided. 48. If a method is declared as protected, where may the method be accessed? A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared. 49. What are the legal operands of the instanceof operator? The left operand is an object reference or null value and the right operand is a class, interface, or array type. 50. To what value is a variable of the boolean type automatically initialized? The default value of the boolean type is false. 11
  • 13. © EME TECHNOLOGIES Questions and Comments 13