Java Interview Questions Flashcards
What is Java?
Let us Java Page 3
https://aws.amazon.com/what-is/java/#:~:text=Java%20is%20a%20widely%2Dused,as%20a%20platform%20in%20itself.
Why is Java a popular choice among modern-day software developers?
https://aws.amazon.com/what-is/java/#:~:text=Java%20is%20a%20widely%2Dused,as%20a%20platform%20in%20itself.
Why is Java Platform Independent?
Let us Java Page 4
What is the difference between compiler and interpreter?
https://www.simplilearn.com/difference-between-compiler-and-interpreter-article#:~:text=A%20compiler%20translates%20the%20entire,potentially%20slowing%20down%20the%20program.
Why is Java not a pure object-oriented programming language?
https://medium.com/codex/why-is-java-not-a-pure-object-oriented-programming-language-b5ef9b2b291c#:~:text=well%2Ddefined%20interfaces.-,Java%20is%20not%20considered%20a%20pure%20object%2Doriented%20programming%20language,pure%20object%2Doriented%20programming%20language.
What are the features of Java?
https://www.javatpoint.com/features-of-java
Hat do you get in Java Download file?
https://www.quora.com/What-do-you-get-in-the-Java-download-file#:~:text=It%20includes%20the%20Java%20Virtual,debugger%2C%20and%20other%20development%20utilities.
What is classLoader?
https://www.geeksforgeeks.org/classloader-in-java/
What are the memory allocations available in Java?
https://www.educba.com/types-of-memory-in-java/#:~:text=The%20Java%20virtual%20machine%20memory,area%20and%20Native%20method%20area
What is the default value stored in local variables?
https://www.tutorialspoint.com/what-is-the-default-value-of-a-local-variable-in-java#:~:text=The%20local%20variables%20do%20not,the%20compiler%20throws%20an%20error.
What is association in Java?
https://medium.com/edureka/association-in-java-3d0facf63d56#:~:text=What%20is%20the%20Association%3F,and%20many%2Dto%2Dmany.
What is Copy Constructor in Java?
https://www.javatpoint.com/java-copy-constructor-example
What are Marker Interfaces? Can we create own marker interfaces?
https://www.baeldung.com/java-marker-interfaces#:~:text=A%20marker%20interface%20is%20an,also%20called%20a%20tagging%20interface.
What is Object Cloning?
https://www.javatpoint.com/object-cloning
What are wrapper classes in Java?
https://www.javatpoint.com/wrapper-class-in-java
What is singleton class in Java and how to implement it?
https://www.geeksforgeeks.org/singleton-class-java/
https://www.javatpoint.com/singleton-design-pattern-in-java
What is Package in Java?
https://www.javatpoint.com/package
Can we implement pointers in Java?
https://stackoverflow.com/questions/1750106/how-can-i-use-pointers-in-java
https://www.simplilearn.com/tutorials/java-tutorial/java-interview-questions#GoTop
Difference between instance and local variable
https://pediaa.com/what-is-the-difference-between-instance-variable-and-local-variable/#:~:text=An%20instance%20variable%20is%20a%20variable%20that%20is%20bound%20to,instance%20variable%20and%20local%20variable.
String pool in Java
https://www.linkedin.com/pulse/java-strings-string-pool-muhammad-noman?utm_source=share&utm_medium=member_ios&utm_campaign=share_via
https://www.digitalocean.com/community/tutorials/what-is-java-string-pool
https://www.simplilearn.com/tutorials/java-tutorial/java-interview-questions#GoTop
What is an Exception?
https://docs.oracle.com/javase/tutorial/essential/exceptions/definition.html#:~:text=Definition%3A%20An%20exception%20is%20an,off%20to%20the%20runtime%20system.
Page 453 in Let us Java
Final keyword in Java
https://www.javatpoint.com/final-keyword
Can we declare main[] as Non-static in Java?
https://www.tutorialspoint.com/can-we-declare-main-method-as-non-static-in-java
Why is main method static in Java?
https://www.javatpoint.com/why-main-method-is-always-static-in-java
https://www.scaler.com/topics/why-main-method-is-static-in-java/
Garbage collection process
https://www.geeksforgeeks.org/garbage-collection-java/
Difference between process and program
https://www.almabetter.com/bytes/articles/difference-between-process-and-program#:~:text=A%20program%20is%20a%20set%20of%20instructions%20written%20in%20a,%2C%20data%2C%20and%20system%20resources.
Difference between constructor and method of a class
https://www.geeksforgeeks.org/difference-between-the-constructors-and-methods/
Difference between String, StringBuffer and StringBuilder
https://www.digitalocean.com/community/tutorials/string-vs-stringbuffer-vs-stringbuilder#:~:text=String%20is%20immutable%20whereas%20StringBuffer,uses%20StringBuffer%20or%20StringBuilder%20class.
Daemon thread in Java?
https://www.geeksforgeeks.org/daemon-thread-java/#:~:text=By%20default%2C%20the%20main%20thread,is%20also%20a%20non%2Ddaemon.
https://www.scaler.com/topics/daemon-thread-in-java/#:~:text=What%20is%20Daemon%20Thread%20in,that%20helps%20the%20user%20thread.
What happens if there are multiple main() methods in a class
https://stackoverflow.com/questions/13399836/can-there-exist-two-main-methods-in-a-java-program
How does exception propagate in code in Java?
https://www.javatpoint.com/exception-propagation#:~:text=An%20exception%20is%20first%20thrown,bottom%20of%20the%20call%20stack.
How do exceptions affect the program if it doesn’t handle them?
If you don’t deal with an exception once it occurs, the programme will end abruptly and the code after the line where the exception occurred won’t run.
Exceptions are runtime errors. Suppose we are making an android application with java. And it all works fine but there is an exceptional case when the application tries to get the file from storage and the file doesn’t exist (This is the case of exception in java). And if this case is not handled properly then the application will crash. This will be a bad experience for users. This is the type of error that cannot be controlled by the programmer. But programmers can take some steps to avoid this so that the application won’t crash. The proper action can be taken at this step.
Is it mandatory for a catch block to be followed after a try block?
https://stackoverflow.com/questions/6703085/is-it-necessary-to-put-catch-statements-after-a-try-block
Can you call a constructor of a class inside another constructor?
https://www.javatpoint.com/what-is-constructor-chaining-in-java
Contiguous memory locations are usually used for storing actual values in an array but not in ArrayList. Explain.
Primitive data types like int, float, and others are typically present in an array. In such circumstances, the array immediately saves these elements at contiguous memory regions. While an ArrayList does not contain primitive data types. Instead of the actual object, an ArrayList includes the references to the objects’ many locations in memory. The objects are not kept in consecutive memory regions because of this.
Why does the java array index start with 0?
https://stackoverflow.com/questions/24841172/why-does-array-indexing-in-java-start-with-0#:~:text=The%20index%20in%20an%20array,Therefore%20the%20offset%20is%200.
Why is the remove method faster in the linked list than in an array?
https://www.baeldung.com/java-arraylist-vs-linkedlist-vs-hashmap#:~:text=The%20insertion%2C%20addition%2C%20and%20removal,surrounding%20elements%20need%20to%20change.
Difference between LinkedList, ArrayList and HashMap
https://www.baeldung.com/java-arraylist-vs-linkedlist-vs-hashmap#:~:text=The%20insertion%2C%20addition%2C%20and%20removal,surrounding%20elements%20need%20to%20change.
How many overloaded add() and addAll() methods are available in the List interface?
https://www.digitalocean.com/community/tutorials/java-list-add-addall-methods
How does the size of ArrayList grow dynamically?
https://www.javaguides.net/2018/08/how-size-of-arraylist-increases-dynamically.html#google_vignette
Although inheritance is a popular OOPs concept, it is less advantageous than composition. Explain.
https://www.thoughtworks.com/insights/blog/composition-vs-inheritance-how-choose
What are Composition and Aggregation? State the difference.
https://www.geeksforgeeks.org/difference-between-aggregation-and-composition-in-java/#:~:text=Aggregation%20can%20be%20described%20as,is%20contained%20in%20another%20object.
How is string literal different from string object
https://www.geeksforgeeks.org/string-initialization-java-string-literal-vs-string-object/
new Operator vs newInstance() Method in Java
https://www.geeksforgeeks.org/new-operator-vs-newinstance-method-java/#:~:text=In%20Java%2C%20new%20is%20an,newInstance()%20method%20is%20used.
Is exceeding the memory limit possible in a program despite having a garbage collector?
Yes, even with a garbage collector in place, the programme could still run out of memory. Garbage collection aids in identifying and removing programme objects that are no longer needed in order to release the resources they use. When an object in a programme cannot be reached, trash collection is executed with respect to that object. If there is not enough memory available to create new objects, a garbage collector is used to free up memory for things that have been removed from the scope. When the amount of memory released is insufficient for the creation of new objects, the program’s memory limit is exceeded.
What is Multithreading in Java
https://www.scaler.com/topics/multithreading-in-java/
https://www.digitalocean.com/community/tutorials/multithreading-in-java
Why is synchronization necessary?
https://www.javatpoint.com/synchronization-in-java
Define System.out.println().
https://www.tutorialspoint.com/system-out-println-in-java#:~:text=Introduction,the%20execution%20of%20a%20program.
Life cycle of a Thread (Thread States)
https://www.javatpoint.com/life-cycle-of-a-thread
What could be the tradeoff between the usage of an unordered array versus the usage of an ordered array?
https://stackoverflow.com/questions/54027951/difference-between-sorted-and-unsorted-array-time-complexity
Is it possible to import the same class or package twice in Java and what happens to it during runtime?
The same package or class may be imported more than once. Neither the JVM nor the compiler raise an objection. Even if you import the same class several times, the JVM will only internally load it once.
In case a package has sub packages, will it suffice to import only the main package? e.g. Does importing of com.myMainPackage.* also import com.myMainPackage.mySubPackage.*?
Sub-packages won’t be imported when a package is imported. When you import a package, all of its classes and interfaces—with the exception of those from its sub-packages—are imported.
This is a big NO. We need to understand that the importing of the sub-packages of a package needs to be done explicitly. Importing the parent package only results in the import of the classes within it and not the contents of its child/sub-packages.
Will the final block be executed if the code System.exit(0) is written at the end of the try block?
The system is established as the last line to be run, after which nothing will happen, therefore both the catch and finally blocks are essentially ignored.
Explain the term “Double Brace Initialisation” in Java?
https://www.javatpoint.com/double-brace-initialization-in-java#:~:text=Double%20brace%20initialization%20is%20a,within%20the%20instantiation%20code%20block.
Why is it said that the length() method of String class doesn’t return accurate results?
https://arc.dev/developer-blog/java-interview-questions/#:~:text=length()%20accurate%3F,of%20U%2B10000%20or%20greater.
Experienced Question 18
https://www.interviewbit.com/java-interview-questions/
How to make object eligible for garbage collection in Java?
https://www.geeksforgeeks.org/how-to-make-object-eligible-for-garbage-collection/
What is the best way to inject dependency? Also, state the reason.
https://www.geeksforgeeks.org/what-is-the-best-way-to-inject-dependency-in-java/
Bean scopes in JSF
https://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope
Bean scopes in Spring
https://www.digitalocean.com/community/tutorials/spring-bean-scopes
Design patterns in Java
https://www.geeksforgeeks.org/java-design-patterns/
Experienced Question 24
https://www.interviewbit.com/java-interview-questions/
What is a Memory Leak? Discuss some common causes of it
https://www.baeldung.com/java-memory-leaks#:~:text=A%20Memory%20Leak%20is%20a,degrades%20system%20performance%20over%20time.
Assume a thread has a lock on it, calling the sleep() method on that thread will release the lock?
No, the thread might release the locks using notify, notifyAll(), and wait() methods.
Java Programming simple
Refer 65 to 74 from
https://www.simplilearn.com/tutorials/java-tutorial/java-interview-questions#GoTop
What is the difference between JDK, JRE, and JVM?
JVM has a Just in Time (JIT) compiler tool that converts all the Java source code into the low-level compatible machine language. Therefore, it runs faster than the regular application.
JRE has class libraries and other JVM supporting files. But it doesn’t have any tool for java development such as compiler or debugger.
JDK has tools that are required to write Java Programs and uses JRE to execute them. It has a compiler, Java application launcher, and an applet viewer.
What is a JIT compiler?
https://www.javatpoint.com/jit-in-java
Question No 10 from
https://www.interviewbit.com/java-interview-questions/
What are Brief Access Specifiers and Types of Access Specifiers?
Access Specifiers are predefined keywords used to help JVM understand the scope of a variable, method, and class. We have four access specifiers.
Public Access Specifier
Private Access Specifier
Protected Access Specifier
Default Access Specifier
https://www.javatpoint.com/access-modifiers
Types of Constructors in Java
https://www.digitalocean.com/community/tutorials/constructor-in-java
Can a constructor return a value?
Yes, A constructor can return a value. It replaces the class’s current instance implicitly; you cannot make a constructor return a value explicitly.
https://www.javatpoint.com/java-constructor-returns-a-value-but-what
Explain ‘this’ keyword in Java.
https://www.javatpoint.com/this-keyword
OOPs principles
https://www.linkedin.com/pulse/7-oops-principles-every-programmer-should-know-harsh-sakhiya?utm_source=share&utm_medium=member_ios&utm_campaign=share_via
And
Let us Java page 250
Super Keyword in Java
https://www.geeksforgeeks.org/super-keyword/
Explain Method Overloading in Java.
The process of creating multiple method signatures using one method name is called Method Overloading in Java. Two ways to achieve method overloading are:
Varying the number of arguments
Changing the return type of the Method
https://www.javatpoint.com/method-overloading-in-java
Can we overload a static method?
No, Java does not support the Overloading of a static method. The process would throw an error reading “static method cannot be referenced.”
Late binding in Java
https://www.linkedin.com/pulse/early-late-binding-java-pramod-yadav?utm_source=share&utm_medium=member_ios&utm_campaign=share_via
Overriding in Java
https://www.geeksforgeeks.org/overriding-in-java/
Polymorphism in Java
https://www.geeksforgeeks.org/polymorphism-in-java/
Define Dynamic Method Dispatch.
The Dynamic method dispatch is a process where the method call is executed during the runtime. A reference variable is used to call the super-class. This process is also known as Run-Time Polymorphism.
Why is the delete function faster in the linked list than an array?
https://www.quora.com/Computer-Programming-Why-is-the-delete-function-faster-in-the-linked-list-than-an-array
https://www.baeldung.com/java-arraylist-vs-linkedlist-vs-hashmap#:~:text=The%20insertion%2C%20addition%2C%20and%20removal,surrounding%20elements%20need%20to%20change.
Difference between Array and Arraylists
https://www.javatpoint.com/difference-between-array-and-arraylist
Lifecycle and States of a Thread in Java
https://www.geeksforgeeks.org/lifecycle-and-states-of-a-thread-in-java/
difference between»_space; and»_space;> operators
https://www.geeksforgeeks.org/what-is-javascript-operator-and-how-to-use-it/#:~:text=Difference%20between%20%3E%3E%3E%20and%20%3E,the%20integer%20value%20when%20shifted.
Applets and their lifecycle
https://www.geeksforgeeks.org/java-applet-basics/
Why are generics used in Java Programming?
Compile-time type safety is provided by using generics. Compile-time type safety allows users to catch unnecessary invalid types at compile time. Generic methods and classes help programmers specify a single method declaration, a set of related methods, or related types with an available class declaration.
https://www.oracle.com/technical-resources/articles/java/juneau-generics.html
Serializable and Externalizable interfaces in Java
https://www.geeksforgeeks.org/externalizable-interface-java/
Enum in Java
https://www.freecodecamp.org/news/java-enum-enumeration-in-java-example/#:~:text=An%20enumeration%20(enum%20for%20short,%2C%20colors%2C%20and%20so%20on.
https://www.geeksforgeeks.org/enum-in-java/
Why is Java Dynamic
https://www.cesarsotovalero.net/blog/the-dynamic-features-of-java.html
Can you run a code before executing the main method?
Yes, we can execute any code, even before the main method. We will be using a static block of code when creating the objects at the class’s load time. Any statements within this static block of code will get executed at once while loading the class, even before creating objects in the main method.
How many times is the finalize method called?
https://www.tutorialspoint.com/how-many-times-finalize-method-will-be-invoked-who-invokes-finalize-method-in-java#:~:text=It%20is%20invoked%20only%20once,override%20it%20from%20any%20class.
Can “this” and “super” keywords be used together?
https://stackoverflow.com/questions/10381244/why-cant-this-and-super-both-be-used-together-in-a-constructor
https://www.quora.com/Can-you-use-this-and-super-both-in-a-constructor#:~:text=NO.,()%20but%20not%20the%20both.
Why does this() and super() have to be the first statement in a constructor?
https://www.quora.com/Why-does-this-and-super-have-to-be-the-first-statement-in-a-constructor
What is a JSP page?
https://www.geeksforgeeks.org/introduction-to-jsp/
What is JDBC?
https://www.javatpoint.com/java-jdbc
Explain the various directives in JSP
https://www.geeksforgeeks.org/introduction-to-jsp/
What are the observer and observable classes?
https://stackoverflow.com/questions/13744450/when-should-we-use-observer-and-observable
https://stackoverflow.com/questions/70949886/observer-and-observable-got-deprecated-and-the-reason-stated-is-they-convey-som
https://www.oreilly.com/library/view/learning-java-4th/9781449372477/ch11s08.html
What is Session Management in Java?
https://www.educba.com/servlet-session-management/#:~:text=Servlet%20Session%20Management%20is%20a,Cookies%2C%20URL%20rewriting%2C%20etc.
Briefly explain the term Spring Framework.
https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/overview.html#:~:text=Spring%20Framework%20is%20a%20Java,can%20focus%20on%20your%20application.
How to handle exceptions in Spring MVC Framework?
https://medium.com/@AlexanderObregon/the-art-of-handling-exceptions-with-exceptionhandler-in-spring-mvc-dfb956d84aef#:~:text=Instead%20of%20defining%20the%20same,ControllerAdvice%20to%20handle%20exceptions%20globally.&text=With%20%40ControllerAdvice%20%2C%20any%20exception%20thrown,will%20be%20caught%20and%20handled.
What is JCA in Java?
https://www.educative.io/answers/what-is-java-cryptography-architecture-jca
Explain JPA in Java.
https://www.javatpoint.com/jpa-introduction
https://www.ibm.com/docs/en/was-liberty/nd?topic=liberty-java-persistence-api-jpa
The Java Persistence API enables us to create the persistence layer for desktop and web applications. Java Persistence deals in the following:
Java Persistence API
Query Language
Java Persistence Criteria API
Object Mapping Metadata
Explain the different authentications in Java Servlets.
https://www.careerride.com/j18.aspx
Explain FailFast iterator and FailSafe iterator along with examples for each.
https://anmolsehgal.medium.com/fail-fast-and-fail-safe-iterations-in-java-collections-11ce8ca4180e#:~:text=Fail%2Dsafe%20iterators%20means%20they,modified%20while%20iterating%20over%20it.&text=As%20arrayLists%20are%20fail%2Dfast%20above%20code%20will%20throw%20an%20exception.
Programming questions 111 to 118 from the link below
https://www.simplilearn.com/tutorials/java-tutorial/java-interview-questions#GoTop
What do you understand by an instance variable and a local variable?
https://www.geeksforgeeks.org/difference-between-instance-variable-and-local-variable/
Can the main method be overloaded?
https://www.geeksforgeeks.org/how-to-overload-and-override-main-method-in-java/#:~:text=Yes%2C%20We%20can%20overload%20the,call%20our%20overloaded%20main%20method.
Difference Between Method Overloading and Method Overriding in Java
https://www.geeksforgeeks.org/difference-between-method-overloading-and-method-overriding-in-java/