Java and Spring Boot Interview Prep
Java and Spring Boot Interview Prep
Question Type
1 Core java
2 Core java
3 Core java
4 Core java
5 Core java
6 Core java
7 Core java
8 Core java
9 Core java
10 Core java
11 Core java
12 Core java
13 Core java
14 Core java
15 Core java
16 Core java
17 Core java
18 Core java
19 Core java
20 Core java
21 Core java
22 OOPS
23 OOPS
24 OOPS
25 OOPS
26 OOPS
27 OOPS
28 OOPS
29 OOPS
30 OOPS
31 OOPS
32 OOPS
33 OOPS
34 OOPS
35 OOPS
36 OOPS
37 OOPS
38 OOPS
39 OOPS
40 OOPS
41 OOPS
42 OOPS
43 OOPS
44 OOPS
45 OOPS
46 OOPS
47 OOPS
48 OOPS
49 OOPS
50 OOPS
51 OOPS
52 OOPS
53 OOPS
54 OOPS
55 OOPS
56 OOPS
57 OOPS
58 OOPS
59 OOPS
60 OOPS
61 OOPS
62 OOPS
63 OOPS
64 OOPS
65 OOPS
66 OOPS
67 OOPS
68 OOPS
69 OOPS
70 OOPS
71 OOPS
72 OOPS
73 OOPS
74 OOPS
75 OOPS
76 OOPS
77 OOPS
78 OOPS
79 OOPS
80 OOPS
81 OOPS
82 OOPS
83 OOPS
84 OOPS
85 OOPS
86 OOPS
87 OOPS
88 OOPS
89 OOPS
90 OOPS
91 OOPS
92 OOPS
93 OOPS
94 OOPS
95 OOPS
96 Exception Handling
97 Exception Handling
98 Exception Handling
99 Exception Handling
100 Exception Handling
101 Exception Handling
105 String
106 String
107 String
108 String
109 String
110 String
111 String
112 String
113 String
114 String
115 String
132 I/O
133 I/O
134 I/O
135 I/O
136 I/O
137 I/O
138 I/O
139 I/O
140 I/O
141 I/O
142 Serialization
143 Serialization
144 Serialization
145 Serialization
146 Serialization
147 Serialization
148 Serialization
149 Miscellaneous
150 Miscellaneous
151 Miscellaneous
152 Miscellaneous
153 Miscellaneous
154 Miscellaneous
155 RMI
156 Multithreading
157 Multithreading
158 Multithreading
159 Multithreading
160 Multithreading
161 Multithreading
162 Multithreading
163 Multithreading
164 Multithreading
165 Multithreading
166 Multithreading
167 Multithreading
168 Multithreading
169 Multithreading
170 Multithreading
171 Multithreading
172 Multithreading
173 Multithreading
174 Multithreading
175 Multithreading
176 Multithreading
177 Multithreading
178 Multithreading
179 Multithreading
180 Multithreading
181 Multithreading
182 Multithreading
183 Multithreading
184 Multithreading
185 Multithreading
186 Multithreading
187 Multithreading
188 Concurrency
189 Concurrency
190 Concurrency
191 Concurrency
192 Concurrency
193 Concurrency
194 Concurrency
195 Concurrency
196 Concurrency
197 Concurrency
198 Concurrency
199 Collection
200 Collection
201 Collection
202 Collection
203 Collection
204 Collection
205 Collection
206 Collection
207 Collection
208 Collection
209 Collection
210 Collection
211 Collection
212 Collection
213 Collection
214 Collection
215 Collection
216 Collection
217 Collection
218 Collection
219 Collection
220 Collection
221 Collection
222 Collection
223 Collection
224 Collection
225 Collection
226 Collection
227 Collection
228 Collection
229 Collection
230 Collection
231 Collection
232 Collection
Question
What is Java?
class Test
{
public static void main (String args[])
{
System.out.println(10 + 20 + "Javatpoint");
System.out.println("Javatpoint" + 10 + 20);
}
}
class Test
{
public static void main (String args[])
{
System.out.println(10 * 20 + "Javatpoint");
System.out.println("Javatpoint" + 10 * 20);
}
}
What is the output of the following Java program?
class Test
{
public static void main (String args[])
{
for(int i=0; 0; i++)
{
System.out.println("Hello Javatpoint");
}
}
}
What is an object?
class Test
{
int i;
}
public class Main
{
public static void main (String args[])
{
Test test = new Test();
System.out.println(test.i);
}
}
class Test
{
int test_a, test_b;
Test(int a, int b)
{
test_a = a;
test_b = b;
}
public static void main (String args[])
{
Test test = new Test();
System.out.println(test.test_a+" "+test.test_b);
}
}
What are the restrictions that are applied to the Java static methods?
What is aggregation?
What is composition?
What is the difference between aggregation and composition?
Why does Java not support pointers?
What is super in java?
Can you use this() and super() both in a constructor?
class OverloadingCalculation3{
void sum(int a,long b){System.out.println("a method invoked");}
void sum(long a,int b){System.out.println("b method invoked");}
What are the types of inner classes (non-static nested class) used in Java?
What is gc()?
What is the difference between the Reader/Writer class hierarchy and the
InputStream/OutputStream class hierarchy?
What are the super most classes for all the streams?
What are the FileInputStream and FileOutputStream?
What is the purpose of using BufferedInputStream and
BufferedOutputStream classes?
How to set the Permissions to a file in Java?
In Java, How many ways you can take input from the console?
What is serialization?
How can you make a class serializable in Java?
How can you avoid serialization in child class if the base class is
implementing the Serializable interface?
What is Deserialization?
What is the transient keyword?
What is Externalizable?
What is multithreading?
Differentiate between the Thread class and Runnable interface for creating a
Thread?
What does join() method?
1. Object Oriented
2. Portable
3. Platform Independent
4. Secured
5. Robust (GC and Exception Handling)
6. High Performance
7. Multithreaded
8. Distributed(RMI and EJB)
9. Dynamic
Empty
No problem.
No value
define access scope
1. public: any
2. private: within class
3. default: within package
4. protected: within package + subclass
1. Part of class and not object
2. Shared across all the objects
3. Can be accessed without creating class
1. Packages avoid the name clashes.
2. The Package provides easier access control.
3. We can also have the hidden classes that are not visible outside and used
by the package.
4. It is easier to locate the related classes.
30Javatpoint
Javatpoint1020
200Javatpoint
Javatpoint200
Compilation error: Expected Boolean but got int
It is programming paradigm based on objects.
Data and methods are defined in a class.
Objects are instance of class
Bottom up approach in program design
Details are hidden from user using abstraction
real time entity, state and behavior, instance of class
Object can be created using new keyword
1.all concepts of OOPS v/s not all (inheritance and polymorphysm)
2. Does not have inbuilt objects v/s has inbuilt objects (window object of
javascript)
3. Java, C++ v/s javascript, vbscript
Null.
Output : 0
Runtime error:NoSuchMethodError
Compilation error : modifier static not allowed here
No
Yes
Refers to current object
No. Reason: final variable
Yes. Not best practice
1. final variable
2. Can be used with synchronized blocks
Advantages:
1. Code reusability
2. Overriding (runtime polymorphism)
Types:
1. Single: A - B
2. Multilevel: A - B - C
3. Multiple (Not supported) : A, B > C
4. Hierarchical: A < B, C
4. Hybrid = Hierachical + Multiple (Not supported) A < B, C > D
Object class
Ambiguity
1. Aggregation class contains the reference to the class it own
2. has-a relationship
3. Person class has Address class
1. If the contained object cannot exist without the existence of container
object, then it is called composition.
2. Particular case of aggregation
weak v/s strong relation
Unsafe/Unsecure and complex to understand
Refers to immediate parent class
No
1. Used to create clone of object
2. Object.clone
3. java.lang.Cloneable : CloneNotSupportedException
1. Polymorphism technique
2. Same method name but different signature
Ambiguity
No
Yes
Datatype can be promoted if no matching found
error: reference to sum is ambiguous
If a subclass provides a specific implementation of a method that is already
provided by its parent class, it is known as Method Overriding. It is used for
runtime polymorphism and to implement the interface methods.
Yes
No
Yes. but only upwards
Yes. All functions are virtual
Different return type while overriding
#VALUE!
Yes
No
No
1. call to method is decided at compile time v/s runtime
2. static binding v/s dynamic binding
3. overloading v/s overriding
4. faster execution v/s slower execution
5. less flexibility v/s more flexibility
type comparison operator
dog instanceof Animal //true
hide the implimentation details and only show functionality to the user.
No
When object implements interface
1. Make all fields private
2. Use getters only. No setters
1. Make all fields private
2. Use setters only. No getters
1. Can make class read or write only
2. Have more control over read and write by controlling behaviour of getters
and setters
1. Group similar type of classes, interfaces and subpackages
2. Access protection/control
3. Remove name collisions
4. Inbuilt packages and user defined packages
No. It is by default loaded internally by the JVM.
Yes. No.
Used to access static members of class
1. Checked : Compile time : SQLException, ClassNotFoundException
2. Unchecked : Runtime : Arithmatic, NullPointer
3. Error : Not recoverable : OutOfMemoryError, AssertionError
Mechanism which is used to decide how handle error
#VALUE!
Throwable class
Executes regaurdless exception is handled or not
yes
1. used to throw exception v/s declare exceptions
2. followed by and instance v/s followed by class
3. Used within method v/s with method signature
4. cannot throw multiple v/s can declare multiple
Yes
^[a-zA-Z][a-zA-Z0-9]{7,19}
1. Inner class can access members of outer class even private
2. Less code needs to be written
1. Increases workload on JVM
2. IDE provides less support
1. Member inner class : Class within class
2. Local inner class : Class within method
3. Anonymous class : Created for implementing the interface or extending
the class
Yes, inner classes are non-static nested classes. In other words, we can say
that inner classes are the part of nested classes.
No
Yes
Yes
1. Process of removing unused objects from memory
2. Performed automatically
1. Used to trigger garbage collection for cleaning process.
2. Found in system and runtime class
3. System.gc();
1. Garbage collection is managed by JVM
2. It is performed when there is not enough space in the memory
3. We can externally call System.gc() method but gc is not guaranteed.
FileInputStream:
1. Used for reading data from file
2. Used for reading byte oriented data such as image, audio, video also
characters
FileInputStream fin=new FileInputStream("D:\\testout.txt");
int i=fin.read();
System.out.print((char)i);
1. BufferedReader class:
BufferedReader reader = new BufferedReader(new
InputStreamReader(System.in));
String name = reader.readLine();
2. Scanner class:
Scanner sc = new Scanner(System.in);
String name = sc.nextLine();
3. Console class:
Console c=System.console();
String name = c.nextLine();
1. Writing state of an object into file/storage
2. Hibernate, JPA, EJB, JMS, RMI (Remote method invocation)
3. Transfer state of object over network (marshaling)
4. Serializable interface is used for serialization
1. Java Thread pool represents a group of worker threads, which are waiting
for the task to be allocated.
2. Threads in the thread pool are supervised by the service provider which
pulls one thread from the pool and assign a job to it.
3. After completion of the given task, thread again came to the thread pool.
4.The size of the thread pool depends on the total number of threads kept at
reserve for execution.
Advantages:
1. Using a thread pool, performance can be enhanced.
2. Using a thread pool, better system stability can occur.
Java Future interface: Java Future interface gives the result of a concurrent
process. The Future interface returns the object of
java.util.concurrent.Future.
1. If you change property in property file then you don't need to recompile
the code
2. Used to store information which is changed frequently
#VALUE!
#VALUE!
Keyword = Object Reference
#VALUE!
1. File
2. ByteArray
3. Filtered -> Data, Buffered, Pushback
4. Piped
5.Object
1. boolean = Boolean
2. char = Character
3. byte = Byte
4. short = Short
5. int = Integer
6. long = Long
7. float = Float
8. double = Double
No. Question Type
1 Introduction
2 Introduction
3 Dependency Injection
4 Dependency Injection
5 Dependency Injection
6 Dependency Injection
7 Basics
8 Basics
9 Basics
10 Basics
11 Basics
12 Basics
13 Basics
14 AOP
15 Dependency Injection
16 Dependency Injection
17 Dependency Injection
18 Dependency Injection
19 Spring Boot
20 Spring Boot
21 Spring Boot
22 Spring Boot
Question
What is Spring Framerwork?
Core features?
What is Component?
What is Bean?
Bean LifeCycle
What is @SpringBootApplication?
What is @RestController?
1. Inversion of Control
2. Dependency Injection
3. Spring Container
4. Spring MVC
5. Spring Data Access (ORM)
6. Simplified Configuration
7. Real Time Capabilities
Advantage:
1. Minimum impact on other classes while modification
2. Easies testing
Using dependency injection
1. Design pattern which is used to implement inversion of control
principle.
2. Dependencies are maintained in Spring IoC container via
AppConfig
1. Contructor Injection (Best)
2. Setter Injection (Optional)
3. Field Injection (Cannot test)
4. Method Injection (Optional/Inject Dynamically/Rarely used)
`@Component annotation is used to indicate that a class is
spring managed component
Component refers to a class or bean that is managed by spring
IoC