-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
3348 lines (3285 loc) · 329 KB
/
index.html
File metadata and controls
3348 lines (3285 loc) · 329 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ultimate Java Interview Cracker</title>
<style>
:root {
--primary: #6366f1;
--primary-dark: #4f46e5;
--bg-dark: #0f172a;
--bg-card: #1e293b;
--text-main: #f8fafc;
--text-muted: #94a3b8;
--accent: #22d3ee;
--success: #10b981;
}
* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
body {
background-color: var(--bg-dark);
color: var(--text-main);
height: 100vh;
overflow: hidden;
display: flex;
flex-direction: column;
}
/* --- Welcome Overlay --- */
#welcome-screen {
position: fixed;
top: 0; left: 0; width: 100%; height: 100%;
background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
z-index: 1000;
transition: opacity 0.8s ease;
}
.welcome-content h1 { font-size: 3rem; margin-bottom: 20px; background: linear-gradient(to right, #818cf8, #22d3ee); -webkit-background-clip: text; color: transparent; }
.welcome-btn {
padding: 15px 40px;
font-size: 1.2rem;
background: var(--primary);
color: white;
border: none;
border-radius: 50px;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
box-shadow: 0 0 20px rgba(99, 102, 241, 0.5);
}
.welcome-btn:hover { transform: scale(1.05); box-shadow: 0 0 30px rgba(99, 102, 241, 0.8); }
/* --- Main Layout --- */
header {
height: 70px;
background: var(--bg-card);
border-bottom: 1px solid #334155;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 2rem;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}
.logo { font-weight: bold; font-size: 1.5rem; color: var(--accent); }
/* Controls Area */
.controls { display: flex; align-items: center; gap: 20px; }
/* Toggle Switch */
.toggle-container { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; }
.switch { position: relative; display: inline-block; width: 50px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #334155; transition: .4s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--success); }
input:checked + .slider:before { transform: translateX(24px); }
/* --- Workspace --- */
.container { display: flex; height: calc(100vh - 70px); }
/* Sidebar */
.sidebar {
width: 350px;
background: #162032;
border-right: 1px solid #334155;
overflow-y: auto;
display: flex;
flex-direction: column;
}
.search-box {
padding: 15px;
position: sticky;
top: 0;
background: #162032;
z-index: 10;
}
.search-box input {
width: 100%;
padding: 10px;
border-radius: 8px;
border: 1px solid #334155;
background: #0f172a;
color: white;
outline: none;
}
.question-list { list-style: none; }
.question-item {
padding: 15px 20px;
border-bottom: 1px solid #1e293b;
cursor: pointer;
transition: background 0.2s;
font-size: 0.95rem;
display: flex;
justify-content: space-between;
align-items: center;
}
.question-item:hover { background: #1e293b; }
.question-item.active { background: rgba(99, 102, 241, 0.1); border-left: 4px solid var(--primary); }
.question-item .status { width: 10px; height: 10px; border-radius: 50%; background: #334155; }
.question-item.completed .status { background: var(--success); box-shadow: 0 0 5px var(--success); }
/* Main Content */
.content-area {
flex: 1;
padding: 40px;
overflow-y: auto;
background: radial-gradient(circle at top right, #1e293b 0%, #0f172a 40%);
}
#empty-state {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
color: var(--text-muted);
}
.answer-card {
background: rgba(30, 41, 59, 0.7);
backdrop-filter: blur(10px);
border: 1px solid #334155;
border-radius: 16px;
padding: 30px;
max-width: 900px;
margin: 0 auto;
display: none; /* Hidden by default */
animation: slideIn 0.3s ease-out;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.answer-card h2 { color: var(--accent); margin-bottom: 20px; font-size: 2rem; }
.section-title {
text-transform: uppercase;
font-size: 0.75rem;
letter-spacing: 1px;
color: var(--text-muted);
margin-top: 20px;
margin-bottom: 10px;
font-weight: bold;
}
.explanation { font-size: 1.1rem; line-height: 1.7; color: #cbd5e1; margin-bottom: 20px; }
.strategy-box {
background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(6, 78, 59, 0.1) 100%);
border: 1px solid rgba(16, 185, 129, 0.2);
border-radius: 10px;
padding: 20px;
margin-top: 30px;
}
.strategy-box h3 { color: var(--success); font-size: 1rem; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.code-block {
background: #000;
padding: 15px;
border-radius: 8px;
font-family: 'Courier New', Courier, monospace;
color: #a5f3fc;
margin: 15px 0;
border-left: 4px solid var(--accent);
}
/* --- Progress Bar --- */
.progress-container {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 4px;
background: #1e293b;
}
.progress-bar {
height: 100%;
background: linear-gradient(90deg, var(--primary), var(--accent));
width: 0%;
transition: width 0.3s ease;
}
.progress-text {
position: absolute;
right: 20px;
top: 25px;
font-size: 0.8rem;
color: var(--text-muted);
}
/* --- Paste this at the bottom of your CSS --- */
/* Mobile "App-Like" View */
@media (max-width: 768px) {
.container {
position: relative;
overflow: hidden;
}
/* Sidebar takes full screen on mobile */
.sidebar {
width: 100%;
height: calc(100vh - 70px);
position: absolute;
z-index: 10;
transition: transform 0.3s ease-in-out;
transform: translateX(0); /* Visible by default */
border-right: none;
}
/* Content Area takes full screen on mobile but is hidden initially */
.content-area {
width: 100%;
height: calc(100vh - 70px);
position: absolute;
z-index: 20;
top: 0;
left: 0;
transform: translateX(100%); /* Hidden to the right by default */
transition: transform 0.3s ease-in-out;
padding: 20px;
background: var(--bg-dark); /* Solid background to cover list */
}
/* Active State: When reading an answer */
body.reading-mode .sidebar {
transform: translateX(-100%); /* Move list to left */
}
body.reading-mode .content-area {
transform: translateX(0); /* Bring answer to center */
}
/* Back Button Styling */
.back-btn {
display: flex !important; /* Visible only on mobile */
align-items: center;
gap: 8px;
margin-bottom: 20px;
background: #334155;
border: none;
padding: 10px 20px;
border-radius: 8px;
color: white;
font-weight: bold;
cursor: pointer;
}
/* Adjust fonts for phone */
.welcome-content h1 { font-size: 2rem; }
.answer-card h2 { font-size: 1.5rem; }
header { padding: 0 1rem; }
.logo { font-size: 1.2rem; }
.toggle-container span { font-size: 0.8rem; }
}
/* Hide back button on desktop */
.back-btn {
display: none;
}
</style>
</head>
<body>
<div id="welcome-screen">
<div class="welcome-content" style="text-align: center;">
<h1>Java Interview Mastery</h1>
<p style="color: #94a3b8; font-size: 1.2rem; margin-bottom: 40px; max-width: 600px;">
Master the easy questions, control the flow, and guide the interviewer exactly where you want them to go.
</p>
<button class="welcome-btn" onclick="startApp()">Let's Crack It</button>
</div>
</div>
<header>
<div class="logo">DevPrep <span style="font-size:0.8rem; color:#64748b">v1.0</span></div>
<div class="progress-text">Progress: <span id="progress-val">0</span>%</div>
<div class="controls">
<div class="toggle-container">
<span>English</span>
<label class="switch">
<input type="checkbox" id="langToggle">
<span class="slider"></span>
</label>
<span style="color: var(--success); font-weight: bold;">Hinglish</span>
</div>
</div>
<div class="progress-container">
<div class="progress-bar" id="progressBar"></div>
</div>
</header>
<div class="container">
<div class="sidebar">
<div class="search-box">
<input type="text" placeholder="Search questions..." id="searchInput" onkeyup="filterQuestions()">
</div>
<ul class="question-list" id="questionList">
</ul>
</div>
<div class="content-area">
<button class="back-btn" onclick="goBack()">
← Back to Questions
</button>
<div id="empty-state">
<div style="font-size: 4rem; margin-bottom: 20px;">🚀</div>
<h2>Select a question</h2>
<p>Tap a question to reveal the answer.</p>
</div>
<div id="answer-display" class="answer-card">
</div>
</div>
</div>
<script>
// --- Data Source ---
// Note: I have fully written out the first 10.
// The architecture handles the rest—you just need to add the strings.
const questionsDB = [
{
id: 1,
title: "What is Functional Interface?",
eng: `A Functional Interface is an interface that contains exactly one abstract method. It can have any number of default or static methods, but only one abstract method. <br><br>Examples include <code>Runnable</code>, <code>Callable</code>, and <code>Comparator</code>. We use the <code>@FunctionalInterface</code> annotation to ensure this rule is followed.`,
hinglish: `Functional Interface wo interface hai jisme sirf <strong>ek hi abstract method</strong> hota hai. Isme default ya static methods kitne bhi ho sakte hain, par abstract method bas ek hi allowed hai.<br><br>Simple example: <code>Runnable</code> ya <code>Callable</code>. Hum <code>@FunctionalInterface</code> annotation use karte hain taaki galti se koi dusra method add na kar de.`,
strategy: `Use this to lead into **Streams**. Say: "The main reason these are so popular now is because they are the foundation of **Lambda Expressions** and the **Streams API** introduced in Java 8."`
},
{
id: 2,
title: "Whether Java is Interpreted or Compiled language?",
eng: `Java is a hybrid language; it is <strong>both</strong> compiled and interpreted. <br><br>First, the source code (.java) is **compiled** by javac into Bytecode (.class). Then, the JVM (Java Virtual Machine) **interprets** this bytecode and executes it on the specific hardware. JIT (Just In Time) compilers are used to optimize this interpretation speed.`,
hinglish: `Java actually <strong>dono</strong> hai. Pehle hum code ko **compile** karte hain (.class file banati hai jo bytecode hoti hai). <br><br>Fir jab hum run karte hain, to JVM us bytecode ko **interpret** karta hai machine code mein. Isliye hum kehte hain: "Write Once, Run Anywhere".`,
strategy: `End with: "The component responsible for executing this is the JVM, which relies on the **Classloader** to load these files." (This prompts the Classloader question).`
},
{
id: 3,
title: "What is Singleton class?",
eng: `A Singleton class is a class that allows only <strong>one instance</strong> to be created throughout the application's lifecycle. <br><br>We achieve this by making the constructor <code>private</code> and providing a static method (usually <code>getInstance()</code>) to return the single instance. It's often used for database connections or configuration settings.`,
hinglish: `Singleton class ka matlab hai ki pure application mein us class ka bas <strong>ek hi object</strong> ban sakta hai. <br><br>Iske liye hum constructor ko <code>private</code> bana dete hain taaki koi <code>new</code> keyword use na kar sake, aur ek static method dete hain jo wahi purana object return karta hai.`,
strategy: `Mention: "However, creating a perfect Singleton is tricky because of **Multithreading** and **Serialization** issues." (This baits the interviewer to ask about breaking Singletons).`
},
{
id: 4,
title: "What is the difference between throw vs throws?",
eng: `<code>throw</code> is used to explicitly throw an exception within a method body. <br><code>throws</code> is used in the method signature to declare that this method <em>might</em> throw an exception, so the caller must handle it.<br><br>Think of <code>throw</code> as an action (I am throwing this now) and <code>throws</code> as a warning (Watch out, this might happen).`,
hinglish: `<code>throw</code> hum tab use karte hain jab humein manually code ke andar se exception fekna ho. <br><code>throws</code> hum method ke naam ke aage likhte hain ye batane ke liye ki "Bhai, ye method exception de sakta hai, ise handle kar lena".`,
strategy: `Connect to Checked/Unchecked: "We usually use 'throws' for **Checked Exceptions** to enforce handling at compile time."`
},
{
id: 5,
title: "What is Object class?",
eng: `The Object class is the **root** or parent of all classes in Java. Every class directly or indirectly inherits from the Object class. <br><br>It provides common methods like <code>toString()</code>, <code>equals()</code>, <code>hashCode()</code>, and <code>wait()/notify()</code> that are available to every Java object.`,
hinglish: `Object class Java mein sabhi classes ka **Baap (Parent)** hai. Har class automatically Object class ko extend karti hai. <br><br>Isliye har object ke paas kuch common methods hote hain jaise <code>toString()</code> aur <code>equals()</code>.`,
strategy: `Pivot to Hashcode: "The most critical contract we override from the Object class is between **equals() and hashCode()**."`
},
{
id: 6,
title: "What is the difference between Mutable vs Immutable?",
eng: `<strong>Mutable</strong> objects can be changed after creation (like <code>StringBuilder</code> or standard getters/setters). <br><strong>Immutable</strong> objects cannot be modified once created. If you try to change them, a new object is created (like <code>String</code>). Immutable objects are great for thread safety.`,
hinglish: `<strong>Mutable</strong> wo objects hain jinki value banne ke baad change ho sakti hai. <br><strong>Immutable</strong> wo hain jo ek baar ban gaye to change nahi ho sakte (jaise <code>String</code>). Agar change karoge to naya object ban jayega.`,
strategy: `Lead to String: "The most famous example of immutability in Java is the **String class**, but there is a specific reason why it was made immutable."`
},
{
id: 7,
title: "What is HQL (Hibernate Query Language)?",
eng: `HQL is an object-oriented query language, similar to SQL, but instead of operating on tables and columns, it operates on **Classes and Properties**. <br><br>It is database independent. You write the query once using class names, and Hibernate translates it to the specific SQL for Oracle, MySQL, etc.`,
hinglish: `HQL SQL jaisa hi hai, bas fark ye hai ki SQL database ke tables pe chalta hai, aur HQL humari Java **Classes aur objects** pe chalta hai. <br><br>Fayda ye hai ki agar database change bhi ho jaye, to HQL query change nahi karni padti.`,
strategy: `Contrast: "While HQL is powerful, for complex performance tuning, we sometimes still need native SQL or the **Criteria API**."`
},
{
id: 8,
title: "How to create Immutable class in Java?",
eng: `To create an immutable class: <br>1. Declare the class as <code>final</code> so it can't be extended.<br>2. Make all fields <code>private</code> and <code>final</code>.<br>3. Do NOT provide Setter methods.<br>4. Initialize fields via constructor only.<br>5. If a field holds a mutable object, return a clone/copy in the getter, not the original.`,
hinglish: `Immutable class banane ke liye 5 rules hain: <br>1. Class ko <code>final</code> banao (koi inherit na kare).<br>2. Variables ko <code>private final</code> banao.<br>3. Setters mat banao.<br>4. Constructor ke through value set karo.<br>5. Agar koi list ya object field hai, to getter mein uski copy return karo, original nahi.`,
strategy: `Mention HashMap: "We do this heavily when creating keys for **HashMaps**, to prevent data loss."`
},
{
id: 9,
title: "What is final keyword?",
eng: `The <code>final</code> keyword helps restrict usage: <br>1. **Variable:** Value cannot be changed (constant).<br>2. **Method:** Cannot be Overridden by child classes.<br>3. **Class:** Cannot be Inherited (extended).`,
hinglish: `<code>final</code> ka matlab hai "Bas, ye final hai": <br>1. **Variable:** Value change nahi hogi.<br>2. **Method:** Child class isko change (override) nahi kar sakti.<br>3. **Class:** Iska koi child nahi ban sakta (inheritance band).`,
strategy: `Differentiation: "It is often confused with **finally** (exception handling) and **finalize** (garbage collection), but they are totally different."`
},
{
id: 10,
title: "What is static keyword?",
eng: `<code>static</code> implies that a member belongs to the **Class** rather than a specific instance (object). <br><br>Static variables are shared among all objects. Static methods can be called without creating an object of the class. They are loaded into memory only once.`,
hinglish: `<code>static</code> ka matlab hai wo chiz **Class ki hai**, object ki nahi. <br><br>Static variable ki value sab objects ke liye same rehti hai. Static method ko call karne ke liye <code>new Class()</code> karne ki zarurat nahi padti, direct ClassName se call kar sakte hain.`,
strategy: `Memory Tip: "Since static members belong to the class, they are stored in a special memory area called **Metaspace** (formerly PermGen)." (Leads to Memory/Metaspace questions).`
},
{
id: 11,
title: "What is the difference between method Overloading and Overriding?",
eng: `<strong>Method Overloading</strong> happens within the same class. It occurs when two methods have the same name but different parameters (different type or number of arguments). It is an example of <em>Compile-time Polymorphism</em>.<br><br><strong>Method Overriding</strong> happens between a Parent and Child class (Inheritance). The method signature (name and parameters) must be exactly the same. The child class gives its own specific implementation. It is <em>Runtime Polymorphism</em>.<br><br>
<strong>Real Life Example 1:</strong><br>
<em>Overloading:</em> Think of a 'Payment' system. You can <code>pay(Cash)</code>, <code>pay(CreditCard)</code>, or <code>pay(UPI, MobileNumber)</code>. The action is the same (Pay), but the inputs differ.<br>
<em>Overriding:</em> Think of a Father and Son. The Father has a method <code>drive()</code> (drives a vintage Scooter). The Son inherits this but overrides <code>drive()</code> to drive a Sports Car. The action is the same, but the implementation changed in the next generation.<br><br>
<strong>Real Life Example 2:</strong><br>
<em>Overloading:</em> A Search bar. You can <code>search("Shoes")</code> or <code>search("Shoes", "Nike")</code>.<br>
<em>Overriding:</em> A 'Notification' system. The generic method is <code>sendAlert()</code>. The 'EmailService' subclass sends an Email, while the 'SMSService' subclass sends a Text.`,
hinglish: `<strong>Overloading</strong> ka matlab hai ek hi class mein same naam ke methods hona, bas unke parameters alag hone chahiye. Ye <em>Compile-time</em> pe decide hota hai.<br><br><strong>Overriding</strong> tab hota hai jab Child class Parent class ke method ko badal deti hai (Inheritance). Naam aur parameters bilkul same hone chahiye. Ye <em>Runtime</em> pe decide hota hai.<br><br>
<strong>Real Life Example 1:</strong><br>
<em>Overloading:</em> Socho Amazon Pay. Method same hai 'Pay', par kabhi aap <code>pay(Card)</code> karte ho, kabhi <code>pay(UPI)</code>. Input alag hai, kaam wahi hai.<br>
<em>Overriding:</em> Socho Baap aur Beta. Papa ke paas method tha <code>drive()</code> (wo purana Scooter chalate the). Bete ne wo method inherit kiya par usne <code>drive()</code> ko override karke Sports Car chalana shuru kar diya.<br><br>
<strong>Real Life Example 2:</strong><br>
<em>Overloading:</em> Restaurant Menu. <code>order("Pizza")</code> ya fir <code>order("Pizza", "Extra Cheese")</code>.<br>
<em>Overriding:</em> Bank Interest. RBI ne rule banaya <code>getInterest()</code>. SBI ne use override karke 5% diya, aur HDFC ne override karke 6% diya.`,
strategy: `Lead with: "The key difference is when the binding happens. Overloading is static binding, while Overriding is dynamic binding." Then pause. This often leads them to ask "What are Covariant return types?" or "Can we override static methods?"`
},
{
id: 12,
title: "What is @SpringBootApplication annotation?",
eng: `This is the most essential annotation in a Spring Boot application. It is actually a combination of three distinct annotations: <br>1. <strong>@Configuration:</strong> Marks the class as a source of bean definitions.<br>2. <strong>@EnableAutoConfiguration:</strong> Tells Spring Boot to start adding beans based on classpath settings (e.g., if it sees 'spring-web', it sets up Tomcat automatically).<br>3. <strong>@ComponentScan:</strong> Tells Spring to look for other components, configurations, and services in the current package and sub-packages.<br><br>
<strong>Real Life Example 1:</strong><br>
Think of the <strong>Power Button</strong> on your smartphone. When you press it, it doesn't just turn on the screen; it boots the OS, initializes the network, checks the battery, and loads the UI. One button triggers a complex chain of setup events.<br><br>
<strong>Real Life Example 2:</strong><br>
A <strong>Swiss Army Knife</strong>. It looks like one tool, but inside it includes a knife, a screwdriver, and a bottle opener. Similarly, <code>@SpringBootApplication</code> looks like one annotation but packs three powerful configurations inside.`,
hinglish: `Ye Spring Boot ka sabse main annotation hai. Asal mein ye 3 annotations ka mixture hai: <br>1. <strong>@Configuration:</strong> Ye batata hai ki yahan beans define kiye gaye hain.<br>2. <strong>@EnableAutoConfiguration:</strong> Ye Spring Boot ka magic hai. Agar aapne dependencies mein 'Hibernate' dala hai, to ye apne aap database connect kar lega.<br>3. <strong>@ComponentScan:</strong> Ye Spring ko bolta hai ki "Jao, is package ke andar dhoondo ki kaunsi classes hain jinhe load karna hai".<br><br>
<strong>Real Life Example 1:</strong><br>
Phone ka <strong>Power Button</strong>. Jab aap use dabate hain, wo sirf screen on nahi karta, wo background mein OS load karta hai, network dhoondta hai, SIM check karta hai. Ek button, hazaron kaam.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Swiss Army Knife</strong> (Multi-tool). Dikhta ek chaku hai, par usme penchkas (screwdriver) aur opener bhi hota hai. Waise hi ye annotation dikhta ek hai, par kaam 3 karta hai.`,
strategy: `Close with: "This annotation is what makes Spring Boot 'opinionated'. It assumes defaults so we don't have to write XML configuration." This invites questions about "How to exclude specific auto-configurations?"`
},
{
id: 13,
title: "What is the difference between Checked and Unchecked exception?",
eng: `<strong>Checked Exceptions</strong> are checked at <em>Compile-time</em>. The Java compiler forces you to handle them (using try-catch or throws). If you don't, the code won't compile. These represent anticipated problems (e.g., File missing, SQL error).<br><br><strong>Unchecked Exceptions</strong> occur at <em>Runtime</em>. The compiler ignores them. They usually happen due to bad programming logic (e.g., NullPointer, ArrayIndexOfBounds). You aren't forced to handle them, but you should fix the logic.<br><br>
<strong>Real Life Example 1:</strong><br>
<em>Checked:</em> <strong>Passport Check at Airport.</strong> You cannot board the plane (compile/run) unless you show the passport. The authorities force you to handle this requirement before proceeding.<br>
<em>Unchecked:</em> <strong>Tire Puncture.</strong> This happens suddenly while driving (Runtime). No one checks your tires every 5 minutes, but if it happens, you have to stop and fix it.<br><br>
<strong>Real Life Example 2:</strong><br>
<em>Checked:</em> <strong>Exam Hall Ticket.</strong> The invigilator checks this before you enter. No ticket, no exam.<br>
<em>Unchecked:</em> <strong>Pen running out of ink.</strong> This happens while writing the exam. You didn't plan for it, but now you must handle it (borrow a pen) or fail.`,
hinglish: `<strong>Checked Exceptions</strong> wo hoti hain jo Compiler pakad leta hai. Code compile hi nahi hoga jab tak aap <code>try-catch</code> nahi lagate. Ye wo problems hain jo hum expect karte hain (jaise File nahi mili).<br><br><strong>Unchecked Exceptions</strong> wo hain jo <em>Runtime</em> pe aati hain. Compiler inhe ignore karta hai. Ye usually programmer ki galti se hoti hain (jaise kisi null cheez ko use karna).<br><br>
<strong>Real Life Example 1:</strong><br>
<em>Checked:</em> <strong>Airport Security.</strong> Plane mein baithne se pehle checking hoti hi hai. Agar Boarding Pass nahi hai, to aage nahi ja sakte. Ye mandatory hai.<br>
<em>Unchecked:</em> <strong>Tyre Puncture.</strong> Ye gadi chalate waqt achanak hota hai. Koi pehle se check nahi kar sakta ki raste mein keel hai ya nahi.<br><br>
<strong>Real Life Example 2:</strong><br>
<em>Checked:</em> <strong>Exam Admit Card.</strong> Teacher pehle check karega. Nahi hai to entry band.<br>
<em>Unchecked:</em> <strong>Pen ki siyahi (ink) khatam hona.</strong> Ye likhte-likhte achanak ho jata hai. Iska pehle se koi warning nahi milta.`,
strategy: `Mention: "In modern Spring Boot development, we often use Global Exception Handlers (@ControllerAdvice) to manage these cleanly." This guides them to ask about Exception Handling in Spring.`
},
{
id: 14,
title: "What is N+1 problem?",
eng: `The N+1 problem is a performance issue in ORM tools like Hibernate. It happens when you fetch a list of Parent entities, and then for <em>each</em> parent, Hibernate executes a separate query to fetch its Child entities.<br><br>If you have 1 Parent query and 100 records (N=100), Hibernate executes 1 query for the list + 100 queries for the details. Total 101 queries. This kills database performance.<br><br>
<strong>Real Life Example 1:</strong><br>
Imagine you are a <strong>Pizza Delivery Driver</strong>. You have 10 pizzas for 10 houses in the same neighborhood.<br>
<em>N+1 way:</em> You drive to the store, pick up Pizza 1, deliver it. Drive back to the store, pick up Pizza 2, deliver it. You do this 10 times. (Very slow).<br>
<em>Optimized way:</em> You pick up all 10 pizzas at once and deliver them in one go.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Teacher grading papers.</strong><br>
<em>N+1 way:</em> Teacher calls Student 1, checks copy, sends him back. Calls Student 2, checks copy, sends back.<br>
<em>Optimized way:</em> Teacher collects all copies at once (1 query) and checks them continuously.`,
hinglish: `N+1 problem Hibernate ki sabse badi performance issue hai. Ye tab hoti hai jab aap ek List nikalte ho, aur fir har item ke liye Hibernate database se dubara data maangta hai.<br><br>Agar aapne 100 Students nikale (1 query), aur har Student ka Address maanga, to Hibernate 100 alag queries chalayega Address ke liye. Total 101 queries ho jayengi. Database slow ho jayega.<br><br>
<strong>Real Life Example 1:</strong><br>
Socho aap <strong>Pizza Delivery Boy</strong> ho. 10 gharon mein pizza dena hai.<br>
<em>N+1 tarika:</em> Aap dukan gaye, 1 pizza uthaya, deliver kiya. Wapas dukan gaye, dusra uthaya, deliver kiya. Bahut time lagega.<br>
<em>Sahi tarika (Join Fetch):</em> Sare 10 pizza ek saath utha liye aur line se sabko de diye.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Kirana Store wala.</strong><br>
<em>N+1 tarika:</em> Aapne chini maangi, wo godown gaya lekar aaya. Fir aapne chawal maanga, wo fir godown gaya. <br>
<em>Sahi tarika:</em> Aapne list di, wo ek baar godown gaya aur sab lekar aa gaya.`,
strategy: `End with: "We solve this using 'Join Fetch' in HQL or Entity Graphs." This proves you know the solution, not just the problem.`
},
{
id: 15,
title: "What is Serialization?",
eng: `Serialization is the process of converting a Java object into a byte stream (a sequence of 0s and 1s). This is done so the object can be saved to a file, stored in a database, or sent over a network.<br><br>Deserialization is the reverse process: recreating the Java object from the byte stream. To make a class serializable, it must implement the <code>Serializable</code> marker interface.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>IKEA Furniture.</strong> When you buy a table, it is "Serialized" (dismantled) into a flat box so it can be shipped easily. When you reach home, you "Deserialize" it by assembling it back into a table.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Freezing Food.</strong> You cook pasta (Object). To store it for later, you freeze it (Serialization). It changes state to a solid block. Later, you microwave it (Deserialization) to bring it back to its original edible state.`,
hinglish: `Serialization ka matlab hai Java ke Object ko 'Byte Stream' (0 aur 1 ki series) mein convert karna. Ye hum tab karte hain jab humein Object ko file mein save karna ho ya internet pe bhejna ho.<br><br>Deserialization iska ulta hai—wapas bytes se Object banana. Iske liye humein <code>Serializable</code> interface implement karna padta hai.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>IKEA ka Furniture.</strong> Jab aap table kharidte ho, wo usse khol kar (dismantle karke) box mein pack kar dete hain (Serialization) taaki wo car mein fit aa jaye. Ghar aakar aap use wapas jod lete ho (Deserialization).<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Khana Freeze karna.</strong> Aapne khana banaya (Object). Use lambe samay tak rakhne ke liye Freeze kar diya (state change kar di). Jab khana ho, to Garam (Deserialize) kiya aur wo wapas waisa hi ho gaya.`,
strategy: `Mention: "If we don't want to save a specific field, like a password, we use the **transient** keyword." This almost guarantees the next question will be about the transient keyword.`
},
{
id: 16,
title: "What is Marker interface?",
eng: `A Marker Interface is an interface that has <strong>no methods and no constants</strong>. It is empty. It basically acts as a "tag" or a "signal" to the JVM or Compiler that the class implementing it belongs to a special category.<br><br>Common examples are <code>Serializable</code>, <code>Cloneable</code>, and <code>Remote</code>. However, since Java 5, Annotations are preferred over Marker Interfaces.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>'Fragile' Sticker on a Box.</strong> The sticker doesn't do anything itself (it has no methods). But it tells the courier guy (JVM), "Handle this box with care."<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>VIP Wristband in a Club.</strong> The wristband doesn't give you muscles. But when the bouncer (JVM) sees it, he lets you enter the VIP area. It just marks you as special.`,
hinglish: `Marker Interface wo interface hai jiske andar <strong>kuch nahi hota</strong>—na koi method, na koi variable. Ye khaali hota hai. Ye bas JVM ko ek "Signal" dene ke liye use hota hai ki "Bhai, ye class special hai".<br><br>Example: <code>Serializable</code>, <code>Cloneable</code>. Aajkal hum iski jagah Annotations use karte hain.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Box pe 'Fragile' ka sticker.</strong> Sticker khud kuch nahi karta. Par delivery boy (JVM) jab sticker dekhta hai, to samajh jata hai ki is dabbe ko aaram se uthana hai.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Club ka VIP Band.</strong> Haath mein band hone se aap badal nahi jate, par Guard (JVM) jab wo band dekhta hai to aapko VIP treatment deta hai.`,
strategy: `Say: "It represents a 'Is-A' relationship without adding behavior. But now in Spring, we prefer using Annotations like @Component to mark classes."`
},
{
id: 17,
title: "Why do we need Interface and Abstract Class in Java?",
eng: `<strong>Interface</strong> is used for "Capabilities" (What can you do?). It provides 100% abstraction (before Java 8). It allows Multiple Inheritance. Use it when unrelated classes need to do the same thing (e.g., Plane and Bird both <code>Flyable</code>).<br><br><strong>Abstract Class</strong> is used for "Identity" (What are you?). It can hold common state (variables) and behavior for child classes. Use it when classes are closely related (e.g., Dog and Cat both extend <code>Animal</code>).<br><br>
<strong>Real Life Example 1:</strong><br>
<em>Interface (USB Port):</em> A Mouse, Keyboard, and Printer are totally different, but they all fit into a USB port. They agree to a common "contract" of connection.<br>
<em>Abstract Class (Vehicle):</em> Car and Truck are both Vehicles. They share common engine logic, wheels logic, but implement 'loadCapacity' differently.<br><br>
<strong>Real Life Example 2:</strong><br>
<em>Interface (Remote Control):</em> Sony, LG, and Samsung remotes look different, but buttons (Volume Up, Power) work the same way. That's an interface.<br>
<em>Abstract Class (Employee):</em> Manager and Developer are both Employees. They share 'Name' and 'ID' (common code), but 'CalculateBonus()' is different.`,
hinglish: `<strong>Interface</strong> batata hai ki aap "Kya kar sakte ho" (Capabilities). Example: Udna (Flyable). Kabootar bhi udta hai, Plane bhi. Dono ka rishta nahi hai par capability same hai.<br><br><strong>Abstract Class</strong> batata hai ki aap "Kya ho" (Identity). Example: Animal. Kutta aur Billi dono janwar hain, unka khoon, saans lene ka tarika (common code) same hai.<br><br>
<strong>Real Life Example 1:</strong><br>
<em>Interface (USB Port):</em> Mouse, Keyboard, Printer sab alag hain, par sab USB port mein lag jate hain. Kyunki unhone USB ka contract sign kiya hai.<br>
<em>Abstract Class (Gadi/Vehicle):</em> Car aur Truck dono gadi hain. Dono mein Engine, Steering (common chizein) hoti hain jo dubara banane ki zarurat nahi.<br><br>
<strong>Real Life Example 2:</strong><br>
<em>Interface (Bijli ka Plug):</em> Aap usme TV lagao ya Press, socket ko farak nahi padta. Interface standard hai.<br>
<em>Abstract Class (Insaan):</em> Hum sab Insaan hain. Sabke paas dil aur dimaag (common code) hai. Par 'Kaam' sab alag karte hain (Abstract method).`,
strategy: `Pivot: "With Java 8, Interfaces can now have Default methods, which blurs the line between them. This allows us to evolve interfaces without breaking existing code."`
},
{
id: 18,
title: "Can we have concrete methods in Java interface?",
eng: `Historically, No. But since <strong>Java 8</strong>, Yes! We can have <code>default</code> and <code>static</code> methods in interfaces.<br><br>This was introduced to support backward compatibility. Imagine if Java added a new abstract method to the <code>Collection</code> interface; every single class in the world implementing Collection would break. By making it a <code>default</code> method (like <code>stream()</code>), old code keeps working while new code gets the feature.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Mobile OS Update.</strong> When Apple releases a new iOS update, your old phone gets new features (like a new Calculator app) automatically without you buying new hardware. That's a 'default' method added to your existing device.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Standard Car Features.</strong> Earlier, AC was a luxury. Now, every car model (Class) gets AC as a 'default' feature from the manufacturer (Interface). You don't have to install it yourself.`,
hinglish: `Pehle (Java 7 tak) mana tha. Par <strong>Java 8</strong> ke baad "Haan". Hum <code>default</code> aur <code>static</code> methods bana sakte hain.<br><br>Ye isliye kiya gaya taaki purana code kharab na ho. Agar Java walon ne <code>Collection</code> interface mein naya method dala hota, to sari purani classes error deti. <code>default</code> method se sabko naya feature mil gaya bina code tode.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Phone Update.</strong> Jab naya Android update aata hai, to purane phone mein bhi naye features aa jate hain bina phone badle. Ye 'default method' jaisa hai—sabko free mein mil gaya.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Society ke Rules.</strong> Society ne naya rule banaya "Sabke ghar Free WiFi". Jinhone khud lagwaya hai (Override) wo apna use karein, jinke paas nahi hai wo society ka default wala use karein.`,
strategy: `Warning: "However, we cannot override the methods of the Object class (like toString) as default methods in an interface. That's a strict rule."`
},
{
id: 19,
title: "What is Encapsulation?",
eng: `Encapsulation is the mechanism of wrapping data (variables) and code (methods) together as a single unit. It is primarily used for <strong>Data Hiding</strong> and Security.<br><br>We achieve this by making variables <code>private</code> and providing <code>public</code> Getter/Setter methods. This gives us control. For example, in the setter, we can add logic to prevent negative numbers for age.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Capsule Medicine.</strong> The medicine powder (variables) is hidden inside a plastic shell (class). You consume the capsule (public method), but you cannot touch the chemicals directly.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Car Engine.</strong> The complex engine wires (private data) are hidden under the hood. You only interact with the Steering Wheel and Pedals (public methods). You can't directly pour petrol into the cylinders while driving.<br><br>
<strong>Real Life Example 3:</strong><br>
<strong>ATM Machine.</strong> Cash is inside the box. You cannot grab it directly. You must use the keypad (public interface) to validate your PIN before the machine gives you money.`,
hinglish: `Encapsulation ka matlab hai data (variables) aur code (methods) ko ek box mein band karna. Iska main maqsad hai <strong>Suraksha (Security)</strong>.<br><br>Hum variables ko <code>private</code> bana dete hain taaki koi bahar se direct change na kar sake. Sirf <code>public</code> methods ke through hi access milega.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Dawayi ka Capsule.</strong> Asli dawai (chemical) ek plastic cover ke andar hoti hai. Aap capsule khate ho, chemical ko haath nahi lagate. Chemical safe rehta hai.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>ATM Machine.</strong> Paise machine ke andar hain (Private data). Aap seedha haath daal ke paise nahi nikal sakte. Aapko button dabane padenge (Public method) aur PIN daalna padega.<br><br>
<strong>Real Life Example 3:</strong><br>
<strong>School Bag.</strong> Aapka lunch box aur books bag ke andar (Private) hain. Zip band hai. Koi bahar se nahi dekh sakta jab tak aap khol ke na dikhao (Getter method).`,
strategy: `Say: "It also helps in making a class 'Read-Only' or 'Write-Only' by omitting getters or setters. It creates a controlled environment for data."`
},
{
id: 20,
title: "What is Abstraction?",
eng: `Abstraction means <strong>hiding the internal complexity</strong> and showing only the essential functionality to the user. It focuses on "What it does" rather than "How it does it".<br><br>In Java, we achieve abstraction using <strong>Abstract Classes</strong> (0-100% abstraction) and <strong>Interfaces</strong> (100% abstraction). It reduces complexity for the end-user.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Driving a Car.</strong> You know that pressing the accelerator increases speed. You don't need to know how the fuel injects, how the pistons move, or how the combustion happens. The complexity is abstracted away.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Coffee Machine.</strong> You press the "Cappuccino" button. You get coffee. You don't care about the boiler pressure, water temperature, or grinding mechanism inside. You just want the result.<br><br>
<strong>Real Life Example 3:</strong><br>
<strong>Sending an Email.</strong> You type and hit Send. You don't know TCP/IP protocols, DNS lookups, or server routing. That complexity is hidden.`,
hinglish: `Abstraction ka matlab hai "Faltu ki details chupana aur sirf kaam ki cheez dikhana". User ko bas result se matlab hai, process se nahi.<br><br>Java mein hum ye <strong>Abstract Class</strong> aur <strong>Interface</strong> se karte hain.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Car chalana.</strong> Aap accelerator dabate ho gadi bhagti hai. Aapko ye janne ki zarurat nahi ki engine mein petrol kaise jala ya piston kaise ghuma. Wo detail chupi hui hai.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Bijli ka Switch.</strong> Aap switch on karte ho, light jalti hai. Piche taar kaise jude hain, power plant se bijli kaise aayi, ye sab aapse chupa hua hai.<br><br>
<strong>Real Life Example 3:</strong><br>
<strong>Google Search.</strong> Aapne type kiya aur enter mara. Google ke servers ne kaise dhoonda, ye complex logic aapse hidden hai. Aapko bas answer mila.`,
strategy: `Differentiate: "While Encapsulation hides data (security), Abstraction hides complexity (design). They often go hand-in-hand."`
},
{
id: 21,
title: "What is Inheritance?",
eng: `Inheritance is a fundamental OOP concept where one class (Child/Subclass) acquires the properties and behaviors of another class (Parent/Superclass). It promotes **Code Reusability** and creates an **"Is-A"** relationship.<br><br>We use the <code>extends</code> keyword for classes and <code>implements</code> for interfaces. It allows us to write common code once in the parent and use it everywhere in child classes.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Genetics (DNA).</strong> You inherit features like eye color or height from your parents. You didn't invent them; you reused their genetic code. You are a "Child" class extending the "Parent" class.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Mobile Phones.</strong> 'iPhone 15' inherits features from 'iPhone 14' (like the OS structure, face ID logic) and adds new features (Titanium body). It extends the previous version rather than building from scratch.`,
hinglish: `Inheritance ka matlab hai "Viraasat". Jab ek Child class apne Parent class ki properties aur methods ko copy/use kar leti hai. Iska main fayda hai **Code Reusability**—ek baar likho, baar baar use karo.<br><br>Hum <code>extends</code> keyword use karte hain. Ye **"Is-A"** rishta banata hai (e.g., Dog IS-A Animal).<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>DNA/Khandaan.</strong> Aapki aankhon ka rang ya height aapke mata-pita se milti hai. Aapne wo khud nahi banaya, aapne bas unka code (DNA) inherit kiya hai.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Gadi ke Models.</strong> Maruti Swift ka naya model purane model ke engine aur design ko inherit karta hai, aur bas naye features (jaise sunroof) add karta hai. Pura wheel dubara invent nahi karte.`,
strategy: `Lead with: "While it enables reusability, overuse of inheritance creates **Tight Coupling**. That's why we often prefer **Composition over Inheritance**." (This is a pro-level statement).`
},
{
id: 22,
title: "Can static methods be abstract in Java?",
eng: `**No, absolutely not.**<br><br>Reason 1: **Logic Clashes.** Abstract methods *must* be overridden by the child class to provide functionality. Static methods belong to the class and *cannot* be overridden (they are hidden, not overridden).<br>Reason 2: **Invocation.** Static methods are called using the Class Name without creating an object. If a method is abstract, it has no body code. If you call <code>ClassName.abstractStaticMethod()</code>, there is no code to execute! It would crash immediately.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Blueprint vs Actual House.</strong> An abstract method is like a "Place for a door" on a blueprint. You can't open that door until the house is built. Static means "The Architect's Office". You can't say "Open the door in the Architect's office" if the door exists only on paper.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Ghosts.</strong> Abstract methods are like ghosts—they have no body. Static methods are physical billboards. You cannot have a billboard that is invisible (no body).`,
hinglish: `**Nahi, bilkul nahi.**<br><br>Wajah 1: Abstract method wo hota hai jise Child class ko override karna PADTA hai. Par Static method ko override nahi kiya ja sakta (wo class se juda hota hai).<br>Wajah 2: Static method ko hum bina object banaye call karte hain. Agar method abstract hai (matlab khali hai), aur humne use call kar diya, to run kya hoga? Kuch hai hi nahi wahan! Isliye Java iski permission nahi deta.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Khayali Pulao.</strong> Abstract method ek 'Khayali Pulao' hai (sirf socha hai, bana nahi). Static method ek 'Dukan' hai. Aap khayali pulao dukan pe nahi bech sakte.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Adha-adhura Niyam.</strong> Sarkar ne rule banaya "Tax pay karo" (Static rule), par ye nahi bataya kaise (Abstract). Aisa rule lagu nahi ho sakta.`,
strategy: `Pivot to Overriding: "Since we can't override static methods, if we declare a static method with the same name in a child class, it is called **Method Hiding**, not Overriding."`
},
{
id: 23,
title: "What is @Override annotation in Java?",
eng: `The <code>@Override</code> annotation is a safety check provided by the compiler. It tells the compiler: "I intend to override a method from the parent class."<br><br>If you make a mistake (like a typo in the method name or wrong parameter types), the compiler will throw an error immediately. Without this annotation, the compiler might think you are creating a *new* method instead of overriding, leading to bugs that are hard to find.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Spell Checker.</strong> Writing code without <code>@Override</code> is like writing an essay without spell-check. If you type "Helo" instead of "Hello", no one warns you until you read it later. <code>@Override</code> is the red line that warns you instantly.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>GPS Navigation.</strong> If you miss a turn, GPS says "Rerouting". If you didn't have GPS (Annotation), you would keep driving on the wrong road thinking you are going correctly.`,
hinglish: `<code>@Override</code> ek safety guard hai. Ye Compiler ko batata hai ki "Main Parent class ka method change karne wala hoon".<br><br>Agar aapne spelling mistake kar di (jaise <code>run()</code> ki jagah <code>runn()</code> likh diya), to Compiler turant error dega. Agar ye annotation nahi lagaya, to Compiler sochega ki aapne koi naya method banaya hai, aur code galat chalega.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Form bharna.</strong> Agar form mein 'Name' ki jagah galti se 'Nmae' likh diya, to computer error dega. <code>@Override</code> wahi error checker hai.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Signature Match.</strong> Bank mein check pe sign karte waqt agar sign match nahi hua to cashier rok deta hai. Ye annotation wahi cashier hai jo check karta hai ki aap sahi method copy kar rahe ho ya nahi.`,
strategy: `Say: "It is considered a best practice to always use it. It prevents 'Accidental Overloading' where you meant to override but changed the arguments by mistake."`
},
{
id: 24,
title: "What are the new features of Java 8?",
eng: `Java 8 was the biggest update in Java history. It shifted Java from purely OOP to **Functional Programming**. Key features include:<br>1. **Lambda Expressions:** Anonymous functions (coding with less boilerplate).<br>2. **Streams API:** For processing collections efficiently.<br>3. **Optional Class:** To handle NullPointerExceptions.<br>4. **Default & Static methods** in Interfaces.<br>5. **Date & Time API:** A new, immutable API (LocalDate).<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Smartphones (Touchscreen era).</strong> Before Java 8 (Keypad phones), doing things took many clicks. Java 8 (iPhone/Android) introduced shortcuts and swipes (Lambdas) that made life fast and smooth.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Ordering Food.</strong> Old Java: Go to shop, order, wait, eat. (Imperative). Java 8: Use Swiggy/Zomato. Just click "Reorder". (Declarative/Functional).`,
hinglish: `Java 8 Java ke itihas ka sabse bada update tha. Isne Java ko modern banaya. Main features hain:<br>1. **Lambda Expressions:** Code chota karne ka tarika.<br>2. **Streams API:** List aur data ko filter/map karne ka naya tarika.<br>3. **Optional Class:** Null error se bachne ke liye.<br>4. **Default Methods:** Interface ke andar body wala method.<br>5. **New Date Time API:** Purana Date class kharab tha, ye naya aur acha hai.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Manual vs Automatic Car.</strong> Java 7 Manual car thi—gear khud badlo (loop khud likho). Java 8 Automatic car hai—bas accelerator dabao (Stream API use karo), baki gadi khud karegi.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Telegram vs Postcard.</strong> Pehle chitti likhte the (Boilerplate code). Ab WhatsApp pe emoji bhejte hain (Lambda expression). Kaam wahi hai, par fast hai.`,
strategy: `The interviewer WILL ask about one of these next. Guide them: "My personal favorite is the **Streams API** because it drastically reduced the lines of code I write for loop operations."`
},
{
id: 25,
title: "What is Streams API?",
eng: `Streams API is used to process collections of objects (like Lists or Sets) in a functional and declarative way. It allows operations like **Filter, Map, Reduce, and Sort**.<br><br>Unlike a Collection (which stores data), a Stream does not store data; it moves data from a source through a pipeline of computational operations. It supports parallel processing easily.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Water Purification System (RO).</strong> The water tank is the Collection (Source). The pipes are the Stream. The filters (sediment, carbon, UV) are the operations (filter/map). The clean water in your glass is the result (collect). The water flows through; the pipe doesn't hold it.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Assembly Line.</strong> A car factory. Raw metal (Source) moves on a conveyor belt (Stream). Robots paint it (Map), check quality (Filter), and assemble it. Finally, a car comes out.`,
hinglish: `Streams API Lists ya data ko process karne ka ek modern tarika hai. Isme hum loops (for-loop) nahi lagate, balki functions use karte hain jaise Filter (chhatna), Map (badalna), aur Collect (jama karna).<br><br>Stream data store nahi karta, bas data ko ek pipeline se guzaarta hai.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Falo ka Juice nikalna.</strong> Tokri mein Fal hain (Collection). Aapne unhe machine mein daala (Stream). Machine ne chilka hataya (Filter), juice banaya (Map), aur glass mein bhara (Collect).<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Security Check.</strong> Airport pe line (Stream) lagi hai. Guard ne ticket check kiya (Filter), bag scan kiya (Map), aur aap plane mein gaye (Terminal operation).`,
strategy: `Mention: "Streams have intermediate operations (lazy) and terminal operations (eager). Nothing happens until a terminal operation like .collect() or .count() is called."`
},
{
id: 26,
title: "What is Optional class?",
eng: `<code>Optional</code> is a container object used to contain not-null objects. It was introduced to avoid the infamous **NullPointerException**.<br><br>Instead of returning <code>null</code>, a method returns an <code>Optional</code>. The caller is forced to check if the value is present using methods like <code>isPresent()</code>, <code>orElse()</code>, or <code>ifPresent()</code>. It makes the code more readable and safe.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Courier Delivery Box.</strong> When you order something, you get a box. The box might contain the item (Present) or it might be empty (Empty). You check the box first. You don't blindly grab air expecting an item.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Lottery Ticket.</strong> A ticket is an Optional container. It *might* have a prize (Value), or it *might* have nothing (Null). You verify it before going to the bank.`,
hinglish: `<code>Optional</code> ek dabba (container) hai jo <code>NullPointerException</code> se bachane ke liye banaya gaya hai.<br><br>Agar koi method null return karne wala hai, to hum use Optional return karwate hain. Ye programmer ko majboor karta hai check karne ke liye ki "Bhai, andar maal hai ya nahi?".<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Gift Box.</strong> Aapko kisi ne gift diya. Wo khali bhi ho sakta hai. Optional ek band dabba hai. Aap pehle check karte ho (isPresent) fir nikalte ho. Direct haath nahi dalte.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>ATM Cash.</strong> ATM machine ek Optional hai. Ho sakta hai cash ho, ho sakta hai cash na ho. Aapko <code>orElse()</code> sochna padta hai (agar cash nahi mila to main bank jaunga).`,
strategy: `Say: "I use .orElseThrow() heavily in Service layers when finding entities by ID. It cleanly throws a custom 'ResourceNotFoundException' if the data isn't there."`
},
{
id: 27,
title: "What is the difference between Comparable and Comparator?",
eng: `Both are interfaces used for sorting objects.<br><br><strong>Comparable (java.lang):</strong> Used for **Natural Ordering**. The class implements it itself (e.g., Student implements Comparable) and overrides <code>compareTo()</code>. It modifies the original class. You can only have one logic (e.g., sort by ID).<br><br><strong>Comparator (java.util):</strong> Used for **Custom Ordering**. You create a separate class (e.g., NameSorter, AgeSorter) that implements Comparator and overrides <code>compare()</code>. It doesn't modify the original class. You can have multiple sorting logics.<br><br>
<strong>Real Life Example 1:</strong><br>
<em>Comparable:</em> <strong>Height.</strong> Humans are naturally comparable by height. It's an internal property.<br>
<em>Comparator:</em> <strong>Exam Rank.</strong> A teacher sorts students by Marks, another teacher by Attendance. The logic is external to the student.<br><br>
<strong>Real Life Example 2:</strong><br>
<em>Comparable:</em> <strong>Dictionary.</strong> Words are always sorted A-Z internally.<br>
<em>Comparator:</em> <strong>Spotify Playlist.</strong> You can sort songs by 'Artist', 'Date Added', or 'Duration'. These are external sorters.`,
hinglish: `Dono sorting ke liye use hote hain.<br><br><strong>Comparable:</strong> Ye **Default Sorting** hai. Class khud apne aapko compare karti hai. Jaise Student class mein humne likh diya ki hamesha ID se sort hoga. (Method: <code>compareTo</code>).<br><br><strong>Comparator:</strong> Ye **Custom Sorting** hai. Agar humein kabhi Naam se, kabhi Age se sort karna ho, to hum alag se Comparator banate hain. Original class ko chedne ki zarurat nahi. (Method: <code>compare</code>).<br><br>
<strong>Real Life Example 1:</strong><br>
<em>Comparable:</em> <strong>School Line.</strong> Bacche hamesha Height wise khade hote hain (Default rule).<br>
<em>Comparator:</em> <strong>Cricket Team Selection.</strong> Kabhi Batting average pe sort karte hain, kabhi Bowling speed pe. Ye selector ki marzi hai (External logic).<br><br>
<strong>Real Life Example 2:</strong><br>
<em>Comparable:</em> <strong>Calendar.</strong> Dates hamesha purane se naye kram mein hoti hain.<br>
<em>Comparator:</em> <strong>Online Shopping.</strong> Filter lagana—Price: Low to High, ya Rating: High to Low. Ye Comparator hai.`,
strategy: `Tip: "In Java 8, Comparator became very powerful. We can now chain them like \`Comparator.comparing(Student::getAge).thenComparing(Student::getName)\`."`
},
{
id: 28,
title: "What is the difference between Eager Loading and Lazy Loading?",
eng: `This refers to how related data is fetched from the database (Hibernate/JPA).<br><br><strong>Eager Loading:</strong> Fetches the main data AND all related data immediately in one go. (e.g., Load User + Load all his Orders). Can be slow if too much data is loaded.<br><strong>Lazy Loading:</strong> Fetches only the main data. The related data is fetched <em>on-demand</em> only when you specifically ask for it (call the getter method). This is the default and is more efficient.<br><br>
<strong>Real Life Example 1:</strong><br>
<em>Eager:</em> <strong>Thali Meal.</strong> You get Roti, Sabji, Dal, Rice, Salad all at once on the plate, whether you eat it or not.<br>
<em>Lazy:</em> <strong>Buffet System.</strong> You take a plate. If you want Rice, you go get it. If you want Sweet, you go get it. You fetch only what is needed.<br><br>
<strong>Real Life Example 2:</strong><br>
<em>Eager:</em> <strong>Downloading a Game.</strong> You wait for 50GB to download completely before playing.<br>
<em>Lazy:</em> <strong>Streaming Netflix.</strong> It loads the first 5 minutes. As you watch, it loads the next part. It doesn't download the whole movie instantly.`,
hinglish: `Ye database se data nikalne ka tareeka hai.<br><br><strong>Eager Loading:</strong> Sab kuch ek saath utha laao. Agar User nikala, to uske Orders, Address, History sab saath mein aayega. Ye bhari pad sakta hai.<br><strong>Lazy Loading:</strong> Sirf main data laao. Baki cheezein tab laana jab zarurat ho (jab getter method call ho). Ye default hota hai aur fast hota hai.<br><br>
<strong>Real Life Example 1:</strong><br>
<em>Eager:</em> <strong>Shadi ki Plate.</strong> Pura khana (Starter, Main Course, Dessert) ek saath plate mein bhar liya.<br>
<em>Lazy:</em> <strong>Restaurant Order.</strong> Pehle Starter mangaya. Khaya. Fir man kiya to Main Course mangaya. Zarurat ke hisaab se.<br><br>
<strong>Real Life Example 2:</strong><br>
<em>Eager:</em> <strong>Exam se pehle ratta marna.</strong> Puri book padh li, chahe question aaye ya na aaye.<br>
<em>Lazy:</em> <strong>Open Book Exam.</strong> Jab question dekha, tab book mein wo page khola aur padha.`,
strategy: `Warning: "Lazy loading can lead to the **LazyInitializationException** if we try to access the data after the session is closed. We solve this using 'Open Session In View' or 'Join Fetch'."`
},
{
id: 29,
title: "Explain final, finally {} and finalize()?",
eng: `These three look similar but are totally different.<br><br>1. **final (Keyword):** Used to apply restrictions. A final variable is a constant. A final method cannot be overridden. A final class cannot be inherited.<br>2. **finally (Block):** Used in Exception Handling. The code inside this block *always* executes, whether an exception occurs or not. Used for cleanup (closing connections).<br>3. **finalize() (Method):** Used by Garbage Collector. It is called just before an object is destroyed to perform cleanup. (Deprecated in Java 9).<br><br>
<strong>Real Life Example 1:</strong><br>
<em>final:</em> **Permanent Marker.** Once written, cannot be erased/changed.<br>
<em>finally:</em> **Paying the Bill.** Whether food was good or bad (Exception), you *must* pay the bill before leaving.<br>
<em>finalize:</em> **Last Will/Testament.** Before a person dies (Garbage collection), they write a will to distribute assets.<br><br>
<strong>Real Life Example 2:</strong><br>
<em>final:</em> **Full Stop.** The sentence ends here. No more additions.<br>
<em>finally:</em> **Closing Shop.** Whether sales were high or low, you pull down the shutter at night.<br>
<em>finalize:</em> **Death Row Last Meal.** The final request granted before execution.`,
hinglish: `Ye teeno bilkul alag hain:<br><br>1. **final (Keyword):** Rok lagane ke liye. Final variable change nahi hota. Final class ka child nahi banta.<br>2. **finally (Block):** Try-Catch ke saath lagta hai. Iska code *hamesha* chalta hai, chahe error aaye ya na aaye. (Jaise database close karna).<br>3. **finalize() (Method):** Ye Garbage Collector call karta hai object ko delete karne se theek pehle. (Ab Java 9 se ye band/deprecated ho gaya hai).<br><br>
<strong>Real Life Example 1:</strong><br>
<em>final:</em> **Patthar ki lakeer.** Jo likh diya wo badlega nahi.<br>
<em>finally:</em> **Haath dhona.** Khana kaisa bhi ho, khane ke baad haath dhona hi padta hai.<br>
<em>finalize:</em> **Aakhri Ichha.** Marne se pehle (delete hone se pehle) jo aakhri kaam kiya jaye.<br><br>
<strong>Real Life Example 2:</strong><br>
<em>final:</em> **Laminate karwana.** Certificate laminate ho gaya, ab usme change nahi kar sakte.<br>
<em>finally:</em> **Seat Belt.** Gadi start ho ya thuk jaye, seat belt pehenna zaruri hai.<br>
<em>finalize:</em> **Retirement Party.** Jane se pehle ki vidai.`,
strategy: `Trap: "Note that 'finally' block will NOT execute if we call System.exit(0) or if the JVM crashes."`
},
{
id: 30,
title: "What are the new Java 9 features?",
eng: `Java 9 introduced the **Module System (Jigsaw)**, which allows dividing the JDK into smaller modules. This solved the "Jar Hell" problem and made Java applications lighter.<br><br>Other features:<br>1. **JShell:** A REPL tool (run code immediately without creating class/main method).<br>2. **Factory Methods for Collections:** <code>List.of()</code>, <code>Set.of()</code>, <code>Map.of()</code> for creating immutable collections easily.<br>3. **Private methods in Interfaces.**<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Modules (Kitchen Sections).</strong> Before, the kitchen was one mess. Now, we have specific cabinets: Spices Module, Utensils Module, Fridge Module. You only open what you need.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>JShell (Scratchpad).</strong> Before, to test 2+2, you wrote a whole exam paper (Class/Main). Now JShell is like a rough notebook where you just write 2+2 and get 4.`,
hinglish: `Java 9 ka sabse bada feature tha **Modules (Project Jigsaw)**. Isne Java ko chote-chote tukdon mein baant diya taaki application heavy na ho.<br><br>Aur features:<br>1. **JShell:** Code test karne ke liye turant run karna (bina class banaye).<br>2. **Factory Methods:** <code>List.of("A", "B")</code> likhna aasan ho gaya. Pehle 4 line likhni padti thi.<br>3. **Private Methods in Interface:** Interface ke andar code reuse karne ke liye private methods.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Modules (IKEA Furniture).</strong> Pura sofa ek saath lane ki jagah, alag-alag tukdon mein laaye aur jahan zarurat thi wahan fit kiya.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>JShell (Calculator).</strong> Pehle ganit karne ke liye formula likhna padta tha, ab calculator pe sidha button dabao aur result dekho.`,
strategy: `Say: "I rarely use Modules in standard web apps, but I use \`List.of()\` and \`Map.of()\` every single day because they are immutable and cleaner."`
},
{
id: 31,
title: "What are the new Java 10 features?",
eng: `The main highlight of Java 10 is **Local Variable Type Inference (var)**.<br><br>You can now declare local variables using the <code>var</code> keyword without specifying the type explicitly. The compiler infers the type from the right, hand side.<br>Example: <code>var name = "John";</code> (Compiler knows it is String).<br><br>It reduces verbosity, especially with complex generic types like <code>Map<String, List<User>></code>.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Packing Boxes.</strong> Instead of labeling a box "Kitchen-Cutlery-Spoons", you just use a transparent box (var). You look inside, see spoons, and know what it is automatically.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Nicknames.</strong> Instead of calling someone "Doctor Professor Sheldon Cooper" (Explicit Type), you just call them "Shelly" (var). Everyone knows who you are referring to based on context.`,
hinglish: `Java 10 ka hero feature hai **'var' keyword**.<br><br>Ab humein variable ka type likhne ki zarurat nahi. Compiler khud samajh jata hai.<br>Example: <code>var x = 10;</code> (Compiler samajh gaya ye int hai).<br>Ye tab bahut kaam aata hai jab type ka naam bahut lamba ho.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Transparent Dabba.</strong> Dabbey pe 'Chini' likhne ki zarurat nahi agar dabba transparent hai. Andar safed dane dikh rahe hain to wo chini hi hogi.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Context.</strong> Agar main haath mein cricket bat pakda hoon, to mujhe bolne ki zarurat nahi "I am a Batsman". Log dekh ke (Infer karke) samajh jate hain.`,
strategy: `Clarify: "Remember, 'var' only works for **Local Variables** inside methods. We cannot use it for class fields or method parameters."`
},
{
id: 32,
title: "Why multiple inheritance is not allowed in Java?",
eng: `It is not allowed to avoid the **Diamond Problem** (Ambiguity).<br><br>Imagine Class B and Class C both extend Class A and override a method <code>run()</code>. Now, if Class D extends both B and C, and you call <code>D.run()</code>, which one should it execute? B's version or C's version? This confusion causes bugs.<br>Java solved this by removing multiple inheritance of classes and using **Interfaces** instead.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Two Bosses.</strong> You have two bosses. Boss A says "Write code in Java". Boss B says "Write code in Python". Who do you listen to? You get confused (Ambiguity).<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Driving Directions.</strong> Mom says "Turn Left". Dad says "Turn Right". You are the child class. You crash because you don't know whose instruction to follow.`,
hinglish: `Ye **Diamond Problem** (Confusion) se bachne ke liye ban hai.<br><br>Socho Class B aur Class C dono ke paas <code>show()</code> method hai. Agar Class D in dono ko extend kare aur <code>D.show()</code> call kare, to wo kiska method chalayega? B ka ya C ka? Compiler confuse ho jayega.<br>Isliye Java ne kaha "Ek time pe ek hi Baap (Parent) hoga".<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Do Boss.</strong> Aapke do manager hain. Ek ne bola "Aaj chutti lelo", dusre ne bola "Aaj overtime karo". Aap confuse ho jaoge (Ambiguity).<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Double Role.</strong> Agar ek actor ko ek hi scene mein Hero aur Villain dono ka role play karna ho, to wo kaise karega? Conflict ho jayega.`,
strategy: `Pivot: "However, Java DOES allow multiple inheritance of **Interfaces**, because interfaces don't have method bodies (historically), so there was no ambiguity about implementation."`
},
{
id: 33,
title: "What is Hibernate Criteria API?",
eng: `Criteria API is a way to create queries programmatically (using Java code) rather than writing string-based queries like HQL or SQL.<br><br>It is purely object-oriented and type-safe. It helps in writing **Dynamic Queries** (e.g., search filters where parameters are optional). If the user selects a date, we add a date condition; if not, we don't.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Building a Custom Sandwich.</strong> You don't pick a pre-made sandwich (HQL). You stand at the counter and say "Add Cheese", "Add Tomato", "No Onion". You build the query step-by-step dynamically.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Online Shopping Filters.</strong> You select "Brand: Nike". Then "Size: 10". Then "Color: Black". The query is built dynamically based on your clicks. Criteria API handles this perfectly.`,
hinglish: `Criteria API bina SQL likhe Java code se query banane ka tarika hai.<br><br>Iska sabse bada fayda hai **Dynamic Search**. Jab humein pata nahi hota ki user kya search karega. Agar user ne sirf Naam dala, to sirf Naam search karo. Agar Naam aur Date dono dala, to dono search karo. Ye if-else laga ke query banana Criteria se aasan hai.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Subway Sandwich.</strong> Wahan menu fix nahi hota. Aap batate ho "Bread ye wali", "Sauce ye wala". Aap apni dish (Query) khud banate ho step-by-step.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Amazon Filter.</strong> Kabhi aap sirf 'Shoes' search karte ho, kabhi 'Shoes + Puma + Under 2000'. Query har baar badal rahi hai. Ye Criteria API ka kaam hai.`,
strategy: `Note: "The old Criteria API was deprecated in Hibernate 5.2. Now we use the **JPA CriteriaBuilder**, which is standard across all ORMs."`
},
{
id: 34,
title: "What is volatile keyword?",
eng: `The <code>volatile</code> keyword is used in Multithreading. It guarantees **Visibility** of changes to variables across threads.<br><br>Normally, threads cache variables in their local CPU cache for speed. If Thread A updates a variable, Thread B might still see the old value in its cache. Declaring a variable <code>volatile</code> forces threads to read/write directly from **Main Memory (RAM)**, ensuring everyone sees the latest value.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Digital Scoreboard.</strong> In a cricket match, the scoreboard is 'volatile'. When the scorer updates it, every spectator (Thread) sees the new score immediately. If it wasn't volatile, some people might still see the old score.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Office Notice Board.</strong> If the boss puts a notice on the main board (Main Memory), everyone sees it. If he writes it in his personal diary (CPU Cache), no one else knows. Volatile puts it on the Notice Board.`,
hinglish: `<code>volatile</code> keyword Multithreading mein use hota hai. Ye sure karta hai ki agar ek Thread ne value badli, to baki sabhi Threads ko turant pata chale.<br><br>Computer mein har Thread ka apna chota dimaag (Cache) hota hai. Wo purani value yaad rakh sakta hai. <code>volatile</code> bolta hai: "Apne dimaag mein mat rakho, Main Memory (RAM) se padho".<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Live Cricket Score.</strong> Jab TV pe score badalta hai, to puri duniya ko turant dikhta hai. Ye volatile variable hai. Agar update na ho, to log purana score dekhte rahenge.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>WhatsApp Group Message.</strong> Agar main group mein message bhejun, to sabke phone mein bajta hai. Sabka data sync ho jata hai.`,
strategy: `Contrast: "Volatile guarantees visibility, but NOT atomicity. For atomic operations (like counter++), we need **AtomicInteger** or **Synchronized**."`
},
{
id: 35,
title: "What is the difference between ArrayList and LinkedList?",
eng: `Both implement the List interface, but their internal structure is different.<br><br><strong>ArrayList:</strong> Uses a **Dynamic Array**. Fast for accessing data (<code>get(5)</code> is instant). Slow for inserting/deleting in the middle (because all other elements must shift).<br><strong>LinkedList:</strong> Uses a **Doubly Linked List**. Fast for insertion/deletion (just change pointers). Slow for accessing data (must travel node by node from start).<br><br>
<strong>Real Life Example 1:</strong><br>
<em>ArrayList:</em> **Bookshelf.** Picking the 5th book is easy. But if you want to insert a book in the middle, you have to shift all other books to the right.<br>
<em>LinkedList:</em> **Treasure Hunt Chain.** To find clue #5, you must visit clue #1, then #2, then #3... You can't jump directly. But adding a new clue in the middle is easy (just change the paper note).<br><br>
<strong>Real Life Example 2:</strong><br>
<em>ArrayList:</em> **Cinema Seats.** Numbered seats. You find seat H-5 instantly.<br>
<em>LinkedList:</em> **Human Chain.** People holding hands. To find a person, you start from the first and ask "Who is next?".`,
hinglish: `<strong>ArrayList:</strong> Ye **Array** use karta hai. Data dhoondna (Search) bahut fast hai. Par beech mein data dalna (Insert/Delete) slow hai kyunki baki sabko khiskana padta hai.<br><strong>LinkedList:</strong> Ye **Chain** (zanjeer) use karta hai. Beech mein data dalna fast hai (bas kadi kholo aur jodo). Par dhoondna slow hai kyunki shuru se check karna padta hai.<br><br>
<strong>Real Life Example 1:</strong><br>
<em>ArrayList:</em> **Kitabon ki rack.** 5vi kitab nikalna aasan hai. Par beech mein nayi kitab ghusani ho to baki sabko side karna padega.<br>
<em>LinkedList:</em> **Train ke dabbe.** Beech mein naya dabba jodna aasan hai, bas hook kholo aur jodo. Par 50ve dabbe tak jane ke liye 1 se 49 cross karne padenge.<br><br>
<strong>Real Life Example 2:</strong><br>
<em>ArrayList:</em> **Numbered Parking.**<br>
<em>LinkedList:</em> **Haath pakad ke khade log.**`,
strategy: `Guidance: "90% of the time we use ArrayList because usually, we read more than we write. LinkedList consumes more memory due to storing 'Next' and 'Prev' pointers."`
},
{
id: 36,
title: "Can Java code be executed without generating .class file?",
eng: `Before Java 11: **No.** You had to compile (<code>javac</code>) to create a .class file, then run (<code>java</code>).<br><br>Since **Java 11**: **Yes!** For single-file source code, you can run it directly using <code>java MyFile.java</code>. The JVM compiles it in memory and executes it immediately without producing a .class file on disk.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Instant Noodles.</strong> Old Java: Buy veggies, chop them, cook them (Compile), then eat. Java 11: Cup Noodles. Just pour hot water and eat immediately. No prep work stored on disk.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Streaming Music.</strong> Old way: Download MP3 file (.class), then play. New way: Stream directly (Spotify). You listen to the song without saving a permanent file.`,
hinglish: `Java 11 se pehle: **Nahi.** Pehle .class file banana zaruri tha.<br><br>Java 11 ke baad: **Haan.** Agar code ek hi file mein hai, to aap sidha <code>java MyCode.java</code> likh kar run kar sakte ho. Java andar hi andar memory mein compile karke run kar dega, hard disk pe file nahi banayega.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Live Speech vs Recorded.</strong> Pehle speech record hoti thi (.class file) fir sunayi jati thi. Ab Live speech (Java 11) sidha suni jati hai, record karne ki zarurat nahi.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Instant Photo Print.</strong> Pehle negative reel dhulwani padti thi. Ab Polaroid camera se photo sidha bahar aati hai.`,
strategy: `Context: "This feature was added primarily to make Java friendlier for beginners and for writing simple scripts, similar to Python."`
},
{
id: 37,
title: "What is the difference between HashSet, LinkedHashSet and TreeSet?",
eng: `All implement the Set interface (Unique elements only), but order differs:<br><br>1. **HashSet:** **No Order.** Stores elements using Hashing. Fastest performance (O(1)). Use this if you don't care about order.<br>2. **LinkedHashSet:** **Insertion Order.** Remembers the order in which you added elements. Slightly slower than HashSet.<br>3. **TreeSet:** **Sorted Order.** Stores elements sorted (A-Z or 1-100). Slowest (O(log n)) because it sorts continuously.<br><br>
<strong>Real Life Example 1:</strong><br>
<em>HashSet:</em> **Bag of Balls.** You throw balls in a bag. When you take them out, they come out randomly.<br>
<em>LinkedHashSet:</em> **Playlist Queue.** Songs play in the exact order you added them.<br>
<em>TreeSet:</em> **Dictionary.** No matter in what order you add words, they will always be arranged A-Z.<br><br>
<strong>Real Life Example 2:</strong><br>
<em>HashSet:</em> **Crowd in a Mela.** Random arrangement.<br>
<em>LinkedHashSet:</em> **Line at Ticket Counter.** First come, first served.<br>
<em>TreeSet:</em> **Assembly Line Height-wise.** Students stand sorted by height.`,
hinglish: `Teeno mein Duplicate allow nahi hai, bas "Order" ka fark hai:<br><br>1. **HashSet:** **Koi Order nahi.** Fast hota hai. Data kaise bhi store hoga. (Randon).<br>2. **LinkedHashSet:** **Insertion Order.** Jaise dala, waise niklega (Line mein).<br>3. **TreeSet:** **Sorted Order.** Ye data ko sort karke rakhta hai (A-Z ya 1-10). Thoda slow hota hai.<br><br>
<strong>Real Life Example 1:</strong><br>
<em>HashSet:</em> **Sikke ka dabba.** Sikke daalo, nikalte waqt koi bhi pehle aa sakta hai.<br>
<em>LinkedHashSet:</em> **YouTube History.** Jo video pehle dekhi, wo list mein pehle dikhegi.<br>
<em>TreeSet:</em> **Attendance Register.** Bachon ke naam hamesha A to Z likhe hote hain.`,
strategy: `Trap: "TreeSet does not allow NULL values because it cannot compare null with other values for sorting. HashSet allows one Null."`
},
{
id: 38,
title: "What is the difference between JDK, JRE and JVM?",
eng: `Think of it as a hierarchy:<br><br>1. **JVM (Java Virtual Machine):** The engine that actually runs the code. It is platform-dependent (Windows JVM is different from Mac JVM).<br>2. **JRE (Java Runtime Environment):** JVM + Libraries. It is for *users* who just want to run Java apps (like Minecraft). They don't need to write code.<br>3. **JDK (Java Development Kit):** JRE + Compiler (javac) + Tools. It is for *developers* who need to write and compile code.<br><br>Formula: **JDK = JRE + Development Tools**. **JRE = JVM + Library Classes**.<br><br>
<strong>Real Life Example 1:</strong><br>
<em>JVM:</em> **The Driver.** He actually drives the car.<br>
<em>JRE:</em> **The Car + Driver.** A complete package to travel (Run).<br>
<em>JDK:</em> **Car Factory + Car + Driver.** You can build (Code) new cars and also drive them.<br><br>
<strong>Real Life Example 2:</strong><br>
<em>JVM:</em> **Stomach.** It digests the food.<br>
<em>JRE:</em> **Body + Stomach.** Needed to live.<br>
<em>JDK:</em> **Chef + Kitchen + Body.** Needed to *cook* food (Develop) and eat it.`,
hinglish: `Ye ek Russian Doll jaisa hai (Ek ke andar ek):<br><br>1. **JVM:** Ye Engine hai jo code run karta hai.<br>2. **JRE:** JVM + Libraries. Ye normal logo ke liye hai jinhe bas game khelna hai ya app chalana hai.<br>3. **JDK:** JRE + Developer Tools (javac). Ye programmers ke liye hai taaki wo code likh sakein aur compile kar sakein.<br><br>
<strong>Real Life Example 1:</strong><br>
<em>JVM:</em> **Driver.** Jo gadi chalata hai.<br>
<em>JRE:</em> **Taxi.** Gadi aur Driver dono hain, baitho aur jao (Run karo).<br>
<em>JDK:</em> **Garage/Workshop.** Yahan gadi banti bhi hai (Develop) aur chalti bhi hai.<br><br>
<strong>Real Life Example 2:</strong><br>
<em>JVM:</em> **Pet (Stomach).** Khana hazam karta hai.<br>
<em>JRE:</em> **Insaan.** Khana khata hai.<br>
<em>JDK:</em> **Cook (Rasoiya).** Jo khana bana bhi sakta hai aur kha bhi sakta hai.`,
strategy: `Detail: "Remember, JVM is platform dependent (software for Windows/Linux is different), but Java Language is platform independent (Write Once Run Anywhere)." (This is the classic slogan).`
},
{
id: 39,
title: "Can we have default arguments in Java?",
eng: `**No**, unlike C++ or Python, Java does strictly **NOT** support default arguments in methods.<br><br>However, we can simulate this behavior using **Method Overloading**. We create multiple methods with the same name but different parameters. The method with fewer parameters calls the method with more parameters, passing a default value.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Coffee Shop.</strong> Java doesn't have a button "Coffee" that assumes sugar. Instead, Java creates two buttons: 1. <code>Coffee()</code> which internally calls 2. <code>Coffee(Sugar)</code> passing "Medium Sugar" as default.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Search Bar.</strong> You can't have a default search. So we overload: <code>search()</code> calls <code>search("All Categories")</code> internally.`,
hinglish: `**Nahi**, Java mein C++ ya Python ki tarah Default Arguments nahi hote.<br><br>Par hum "Jugad" karte hain **Method Overloading** se. Hum ek bina argument wala method banate hain, aur uske andar se main method ko call kar dete hain default value ke saath.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Chai banana.</strong> Java mein automatic cheeni nahi padti. Hum do method banate hain: <code>chaiBanao()</code> jo apne aap <code>chaiBanao(2 chammach)</code> ko call kar deta hai.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Pizza Order.</strong> Agar customer ne topping nahi boli, to hum manually 'Cheese' topping select karke order place karte hain.`,
strategy: `Say: "This design choice was made to keep Java simple and avoid ambiguity. Overloading is explicitly clear about which method is being called."`
},
{
id: 40,
title: "Can a constructor be final in Java?",
eng: `**No.** A constructor cannot be marked as <code>final</code>, <code>static</code>, or <code>abstract</code>.<br><br>Why? Because <code>final</code> methods cannot be overridden. But **Constructors are NEVER overridden** anyway (they are not inherited). So, marking it final makes no sense logically. It's redundant. The compiler will give an error.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Birth Certificate.</strong> A constructor is like being born. You are born only once. You can't "Override" your birth. Saying "This birth is final" is silly because birth is always unique to you.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Foundation of a House.</strong> The foundation is built once. You can't "inherit" a foundation and change it for the second floor. It belongs strictly to the ground floor.`,
hinglish: `**Nahi.** Constructor kabhi <code>final</code> nahi ho sakta.<br><br>Kyun? Kyunki <code>final</code> ka matlab hota hai "Override mat karna". Aur Constructors waise bhi kabhi Override hote hi nahi hain (Kyunki Child class ka naam alag hota hai Parent class se). To ye bolna befizool hai. Compiler error dega.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Janam.</strong> Constructor janam jaisa hai. Aapka janam bas aapka hai. Aapka beta aapka janam 'Override' nahi kar sakta, uska apna janam hoga.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Makan ki neev.</strong> Neev ek baar padti hai. Uspe 'Final' likhne ka koi matlab nahi kyunki wo waise bhi badli nahi ja sakti.`,
strategy: `Lead: "However, a constructor CAN be private. We use **Private Constructors** to create Singleton classes or Utility classes (like java.lang.Math) to prevent instantiation."`
},
{
id: 41,
title: "What are the new Java 11 features?",
eng: `Java 11 is a Long Term Support (LTS) version. Key features include:<br>1. **Direct execution of single file source code** (Run without compile).<br>2. **String Methods:** <code>isBlank()</code>, <code>lines()</code>, <code>strip()</code>, <code>repeat()</code>.<br>3. **New File Methods:** <code>Files.readString()</code> and <code>Files.writeString()</code> making file IO incredibly easy.<br>4. **var in Lambda:** You can now use <code>var</code> inside lambda parameters.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>New String Tools.</strong> Earlier checking for blank space was manual. Now <code>" ".isBlank()</code> is a built-in tool, like a Swiss Knife feature.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Reading a Book.</strong> Old Java: Open book, read line by line, buffer it, close book. Java 11: <code>Files.readString()</code> is like "Scan whole page instantly".`,
hinglish: `Java 11 ek LTS (Stable) version hai. Iske naye features:<br>1. **Direct Run:** Bina compile kiye code run karna.<br>2. **String ke naye methods:** <code>isBlank()</code> (kya khali hai?), <code>repeat(3)</code> (3 baar likho).<br>3. **File Handling:** Ab file padhna baccho ka khel hai <code>readString()</code> ke saath. Pehle 10 line likhni padti thi.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>File Padhna.</strong> Pehle file padhna matlab pura process follow karna (BufferedReader etc). Ab bas ek command: "Puri file padh lo".<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>String Repeat.</strong> Agar "Sorry" 100 baar likhna hai, to loop mat lagao. Bas <code>"Sorry".repeat(100)</code> likho.`,
strategy: `Say: "The HttpClient API was also standardized in Java 11, which replaced the ancient HttpURLConnection. It supports HTTP/2 and WebSocket."`
},
{
id: 42,
title: "What is Classloader in Java?",
eng: `The Classloader is a subsystem of JVM responsible for loading <code>.class</code> files (Bytecode) into memory dynamically when needed.<br><br>It follows a **Delegation Model**: <br>1. **Bootstrap:** Loads core Java classes (rt.jar like String, System).<br>2. **Extension:** Loads external extensions.<br>3. **Application:** Loads your own code (classpath).<br>When you ask for a class, the App Classloader asks the Extension, which asks the Bootstrap. If no one finds it, you get <code>ClassNotFoundException</code>.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Looking for a File.</strong> You (App) ask your Manager (Ext). Manager asks the CEO (Bootstrap). If CEO has it, good. If not, Manager checks. If not, You check. If no one has it -> Error.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Librarian.</strong> You ask for a book. The Junior librarian asks the Senior. Senior asks the Head Librarian. They search top-down.`,
hinglish: `Classloader JVM ka wo hissa hai jo files (.class) ko dhoond kar memory mein lata hai. Ye 3 level pe kaam karta hai (Delegation):<br>1. **Bootstrap:** Ye Java ki main files lata hai (String, Integer).<br>2. **Extension:** Ye extra libraries lata hai.<br>3. **Application:** Ye aapka likha hua code lata hai.<br>Hamesha request upar (Bootstrap) jati hai. Agar upar wale ke paas nahi mila, tab niche wala dhoondta hai.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Ghar mein saman dhoondna.</strong> Aapne Mummy (Bootstrap) se pucha. Unhe nahi mila to Bade bhai (Ext) se pucha. Nahi mila to khud (App) dhoonda. Kahin nahi mila to "Kho gaya" (Exception).<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>School Permission.</strong> Pehle Principal (Bootstrap) se pucho. Fir Teacher (Ext) se. Fir Monitor (App) se.`,
strategy: `Trap: "A Classloader cannot see classes loaded by its child classloader, but a child can see classes loaded by the parent. This isolation is crucial for security."`
},
{
id: 43,
title: "What is Primary Cache in Hibernate?",
eng: `Primary Cache (First Level Cache) is the default cache provided by Hibernate. It is associated with the **Session** object.<br><br>It is enabled by default and cannot be disabled. If you request the same object (same ID) twice within the same Session, Hibernate returns it from the cache instead of hitting the database again.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Wallet (Pocket).</strong> Primary cache is like your wallet. If you need money, you check your wallet first. You only go to the ATM (Database) if the wallet is empty. Once you withdraw, you keep it in the wallet for next time.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Browser Cache.</strong> When you visit a website, images are stored locally. If you refresh, it loads from local memory, not from the server.`,
hinglish: `Primary Cache (Level 1) Hibernate ka default cache hai. Ye **Session** ke saath juda hota hai.<br><br>Ye hamesha ON rehta hai. Agar aapne ek transaction mein user ID 1 manga, aur 2 second baad firse user ID 1 manga, to Hibernate database nahi jayega. Wo pehli baar wala hi wapas de dega.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Jeb (Pocket).</strong> Agar paise chahiye to pehle jeb check karoge. Agar jeb mein hai (Cache hit), to Bank (Database) jane ki zarurat nahi.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Short Term Memory.</strong> Agar maine abhi phone number bola, to wo aapke dimaag mein hai. Agar 1 minute baad fir pucha, to aap turant bata doge (Cache). Yaad nahi karna padega.`,
strategy: `Contrast: "However, L1 cache dies when the Session is closed. For caching across multiple sessions (global), we need **Secondary Cache (Level 2)** like EhCache or Redis."`
},
{
id: 44,
title: "Why String is immutable in Java?",
eng: `String is immutable (unchangeable) for three main reasons:<br>1. **String Pool:** To save memory, Java reuses String literals. If Strings were mutable, changing one reference would affect all other variables pointing to that same string.<br>2. **Security:** Strings are used for database connections, usernames, and passwords. If they were mutable, a hacker could change the connection URL after security checks passed.<br>3. **Thread Safety:** Immutable objects are automatically thread-safe. Multiple threads can share a String without synchronization.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Bank Cheque.</strong> Once you write "$1000" and sign it, it becomes immutable. If it were mutable, someone could add a zero and make it "$10000". Immutability provides security.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Notice Board.</strong> If 10 people are reading a notice, and one person erases a word, everyone gets wrong information. Immutability means no one can erase the notice.`,
hinglish: `String ko immutable (na badalne wala) banaya gaya 3 wajah se:<br>1. **Memory (String Pool):** Java memory bachane ke liye ek hi "Hello" ko 10 jagah share karta hai. Agar ek ne badal diya, to sabka badal jayega. Isliye badalna mana hai.<br>2. **Security:** Passwords aur Username String hote hain. Agar wo change ho sakein, to hacker security check ke baad password badal dega.<br>3. **Thread Safety:** Kyunki wo change nahi ho sakta, kai threads usse ek saath use kar sakte hain bina dar ke.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Check pe Sign.</strong> Ek baar amount likh ke sign kar diya, to wo final hai. Agar wo mutable hota, to koi bhi zero badha deta.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Printed Book.</strong> Kitab chap gayi to chap gayi. Aap uske text ko change nahi kar sakte. Agar sabke paas alag text hota to confusion hoti.`,
strategy: `Lead: "Since String is immutable, manipulating strings in a loop creates many garbage objects. That is why we use **StringBuilder** or **StringBuffer** for heavy modifications."`
},
{
id: 45,
title: "What is an Enum in Java?",
eng: `An Enum (Enumeration) is a special data type used to define a collection of **Constants**. It is type-safe.<br><br>Enums are more powerful in Java than in C++. In Java, an Enum is technically a **Class**. It can have constructors, methods, and variables. We use it when we know all possible values at compile time (e.g., Days of Week, Colors, OrderStatus).<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Traffic Lights.</strong> There are only 3 valid states: RED, YELLOW, GREEN. You can't have a "PURPLE" light. Enum ensures you only pick from these 3.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Pizza Sizes.</strong> SMALL, MEDIUM, LARGE. You cannot order a "Gigantic" size if it's not in the menu (Enum).`,
hinglish: `Enum constants ka ek group hai. Iska use tab karte hain jab humein pata ho ki values fix hain aur badlengi nahi.<br><br>Java mein Enum ek tarah ki **Class** hi hoti hai. Iske andar hum methods aur constructor bhi bana sakte hain.<br><br>
<strong>Real Life Example 1:</strong><br>
<strong>Hafte ke Din.</strong> Sunday se Saturday tak 7 hi din hote hain. 8va din nahi ho sakta. Ye Enum hai.<br><br>
<strong>Real Life Example 2:</strong><br>
<strong>Payment Status.</strong> PENDING, SUCCESS, FAILED. Iske alawa chotha option nahi ho sakta.`,
strategy: `Mention: "A very popular interview question is using Enum to create a **Singleton**, as it is the safest way to prevent Reflection attacks."`
},