-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
2420 lines (2391 loc) · 119 KB
/
index.html
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>Software Development Methodologies</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
min-height: 100vh;
color: #fff;
background-color: #000;
}
header {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
h1 {
margin: 0;
}
.main {
display: flex;
flex: 1;
background-size: contain;
background-repeat: no-repeat;
background-position: left;
background-attachment: fixed;
}
.index {
position: sticky;
top: 0;
padding: 20px;
background-color: #f4f4f4;
width: 250px;
height: 100vh;
overflow-y: auto;
box-sizing: border-box;
color: #000;
}
.index ul {
list-style: none;
padding: 0;
}
.index li {
margin-bottom: 10px;
}
.index a {
text-decoration: none;
color: #000;
}
.index a:visited {
color: #000;
}
.container {
display: flex;
flex: 1;
max-width: 800px;
margin: 0 auto;
padding: 0 20px;
box-sizing: border-box;
}
.content {
flex: 3;
}
.chapter {
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 20px;
padding: 20px;
box-sizing: border-box;
}
.chapter h2 {
margin-top: 0;
}
.chapter p {
margin-bottom: 10px;
}
@media (max-width: 768px) {
.index {
display: none;
}
.container {
margin: 0 10px;
padding: 0;
}
}
footer {
background-color: #333;
color: #fff;
text-align: center;
padding: 10px;
}
</style>
</head>
<body>
<header>
<h1>Software Development Methodologies</h1>
</header>
<div class="main">
<div class="index" id="index">
<h2>Chapter Index</h2>
<ul></ul>
</div>
<div class="container">
<div class="content">
<div class="chapter" id="memory">
<h2>JVM Architecture</h2>
<p>The Java Virtual Machine (JVM) architecture consists
of several components that work together to execute
Java programs. The main components include:</p>
<h3>ClassLoader</h3>
<p>The ClassLoader performs three key activities:</p>
<ul>
<li><strong>Loading:</strong> Generates binary data
from .class bytecode and saves it in the method
area.</li>
<li><strong>Linking:</strong> Ensures the
correctness of the .class file and allocates
memory for static variables.</li>
<li><strong>Initialization:</strong> Assigns values
to static variables and executes static
blocks.</li>
</ul>
<h3>Execution Engine</h3>
<p>The Execution Engine is responsible for executing the
bytecode. It consists of three parts:</p>
<ul>
<li><strong>Interpreter:</strong> Interprets
bytecode line by line, which can result in
multiple interpretations for methods called
multiple times.</li>
<li><strong>Just-In-Time Compiler (JIT):</strong>
Compiles the entire bytecode, eliminating the
need for re-interpretation of repeated method
calls.</li>
<li><strong>Garbage Collector:</strong> Destroys
unreferenced objects.</li>
</ul>
</ul>
<p><strong>Memory:</strong></p>
<ul>
<li><strong>Method area:</strong> Class-level
information
(name, parent class name, methods and variables
info,
static variables). Only one and shared.</li>
<li><strong>Heap area:</strong> Information of all
objects.
Only one and shared resource.</li>
<li><strong>Stack area:</strong> Stores one run-time
stack
for every thread. Every frame of the stack
stores
method
calls, destroyed and not shared.</li>
<li><strong>PC Registers:</strong> Store address of
current
instruction of a thread.</li>
<li><strong>Native method stacks:</strong> Store
native
method info for every thread.</li>
</ul>
<p><strong>Run-Time Memory Areas:</strong></p>
<ul>
<li><strong>Static area:</strong> Fixed size and
content.</li>
<li><strong>Run-time stack:</strong> Variable size
and
content, function call and return.</li>
<li><strong>Heap:</strong> Fixed size, variable
content,
dynamically allocated objects and data
structures.
Each
memory word in the heap has 3 states: unused,
undefined,
or value. Function new(k) allocates a block of
heap
space and returns the address of the next block
of k
unused words available.</li>
</ul>
<p><strong>Common Issues:</strong></p>
<ul>
<li><strong>Stack overflow:</strong> When the top of
a
stack
exceeds its fixed limit.</li>
<li><strong>Heap overflow:</strong> When the heap
does
not
have enough blocks available to satisfy a call
to
new.</li>
</ul>
</div>
<div class="chapter" id="types">
<h2>Java Types in Memory</h2>
<p><strong>Primitive types:</strong> have unique dimension
and encoding.</p>
<p><strong>Class types:</strong> declaration allocates
memory space for the reference
</p>
<p><strong>Types of variables: </strong></p>
<ul>
<li>Objects are stored in the heap.</li>
<li>Instance variables (or fields or attributes) -
Stored
within objects in the heap.</li>
<li>Local Variables (in methods) - Stored in the
Stack,
destroyed at the end of the block.</li>
<li>Static Variables - Only one copy is stored in
static
memory.</li>
</ul>
<p><strong>Array:</strong> An array is an object stored
in
the
heap. Declaration allocates memory space for a
reference,
default is null.</p>
<p><strong>Creation:</strong> <code>int[] a = new
int[10];</code> <code>int[] primes =
{2,3,5,7,11,13};</code></p>
<p><strong>Access:</strong> <code>for (int i=0; i <
a.length;
i++) a[i] = i;</code></p>
<p><strong>Multidimensional:</strong> <code>String[][]
table
=
new String[2][3];</code> <code>table[0][2] = new
String(“Mary”);</code></p>
<p><strong>String:</strong> "<code>ciao</code>" <>
<code>new
String("ciao")</code></p>
</div>
<div class="chapter" id="gc">
<h2>Garbage Collection</h2>
<p>Garbage Collection is the process of removing unused
objects
from the heap space. It involves two main steps:</p>
<ol>
<li><strong>Mark:</strong> Identifies which pieces
of
memory
are in use and which aren't.</li>
<li><strong>Sweep:</strong> Removes objects
identified
during the “mark” phase.</li>
</ol>
<p>Garbage can occur when:</p>
<ul>
<li>An allocated block of heap memory has no
reference
to it
(an “orphan”) (memory leak)</li>
<li>A reference exists to a block of memory that is
no
longer allocated (a “widow”) (dangling
reference).</li>
</ul>
<p><code>System.gc()</code> can be used to force garbage
collection.</p>
<p>There are different algorithms for garbage
collection:</p>
<ul>
<li><strong>Reference counting:</strong> Gives each
object a
counter of references. When it becomes 0, it is
considered garbage. However, not all garbage is
collected, especially in circular chains.</li>
<li><strong>Mark and Sweep:</strong> Sets a Mark Bit
to
1
for reachable objects and clears objects with
the
Mark
Bit set to 0.</li>
<li><strong>Copy Collection:</strong> Faster than
mark-sweep
as it requires only one pass, but it reduces the
size of
the heap space.</li>
</ul>
<p>Garbage Collection implementations include:</p>
<ul>
<li><strong>Serial Garbage Collector:</strong>
Freezes
all
application threads when it runs.</li>
<li><strong>Parallel Garbage Collector:</strong>
Default
option, uses multiple threads for managing heap
space.</li>
<li><strong>CMS Garbage Collector:</strong>
Concurrent
Mark
Sweep (deprecated).</li>
<li><strong>G1 Garbage Collector:</strong> Designed
for
multiprocessor machines with large memory
space.</li>
<li><strong>Z Garbage Collector:</strong> Performs
all
expensive work concurrently, without stopping
the
execution of application threads.</li>
</ul>
</div>
<div class="chapter" id="threads">
<h2>Threads</h2>
<p><strong>Concurrency:</strong> Many processes share
one
CPU.</p>
<p><strong>Parallelism:</strong> Processes are allocated
to
parallel CPUs.</p>
<p>Threads (aka lightweight process or execution
context)
are
subprocesses within a single program/process run in
a
shared
memory space. Processes run in private separate
memory
spaces.</p>
<h3>Multithreading:</h3>
<p><strong>Cooperative threads:</strong> Run without
interruption (problem of Starvation and
non-responsiveness).</p>
<p><strong>Preemptive threads:</strong> Can be
switched.</p>
<h3>JVM Threads:</h3>
<p>JVM operates like a mini-OS and schedules its own
threads
regardless of the underlying OS. The
<code>start()</code>
method can be called on a Thread object only once
(otherwise
RuntimeException).</p>
<p><strong>Deadlock Problem:</strong> Progress of a
system
is
halted as each process is waiting to acquire a
resource
held
by some other process (circular wait).</p>
<h3>Java Thread States:</h3>
<ul>
<li><strong>Running:</strong> When thread scheduler
selects
it.</li>
<li><strong>Runnable:</strong> Queued & eligible to
run,
after the <code>start()</code> method.</li>
<li><strong>Blocked:</strong> NOT eligible to run or
waiting
for a resource.</li>
<li><strong>Sleeping:</strong> During
<code>Thread.sleep(ms)</code> time.</li>
<li><strong>Waiting:</strong> For thread interaction
(comes
back Runnable when another thread sends
notification).</li>
</ul>
<p><code>join()</code> method lets one thread "join onto
the
end” of another thread (<code>t.join(5000);</code>).
Current
thread moves to Waiting state and becomes Runnable
when
thread <code>t</code> is dead.</p>
<h3>Thread Priorities:</h3>
<p>A priority number (1-10) is assigned to each
thread.</p>
<h3>JVM Scheduling Policy:</h3>
<ul>
<li><strong>Non-preemptive:</strong> Current thread
is
executed until the end.</li>
<li><strong>Preemptive time-slicing:</strong> Thread
is
executed until its time-slice is over.</li>
</ul>
<p><strong>High priority threads:</strong></p>
<ul>
<li>Are executed more often, or have longer
time-slice.</li>
<li>Stop execution of lower-priority threads before
their
time-slice is over.</li>
</ul>
<p><code>t.setPriority(8);</code></p>
<p><code>t.yield()</code> makes the currently running
thread
go
back to Runnable state and allows other threads of
the
same
priority (but also the thread <code>t</code>) to
run.</p>
<p><code>t.sleep()</code> and <code>t.yield()</code>
affect
the
thread in execution (they are static methods).</p>
</div>
<div class="chapter" id="synchronization">
<h2>Thread Synchronization</h2>
<p><strong>Race Condition:</strong> Occurs when many
threads
can
access the same resource simultaneously, potentially
leading
to corrupted data.</p>
<p>The <code>synchronized</code> modifier locks a code
block,
allowing only one thread to access it at a time. It
ensures
thread safety.</p>
<p>A sleeping thread doesn't release locks it holds,
which
can
lead to deadlocks.</p>
<p><code>void wait()</code> Causes the current thread to
wait
until another thread invokes the
<code>notify()</code>
or
<code>notifyAll()</code> method for the same
object.</p>
<p>In a signaled object lock, the thread keeps
executing,
while
in a non-signaled object lock, the thread is
suspended.</p>
<p><code>void notify()</code> Wakes up a single thread
that
is
waiting on the lock of the current object.</p>
<p><code>void notifyAll()</code> Wakes up all threads
that
are
waiting on the lock of the current object.</p>
<p><strong>Livelock:</strong> Occurs when threads are
actively
running, but no progress is made due to continuous
response
to each other's actions.</p>
<p><strong>Thread Starvation:</strong> Happens when some
threads
make progress while others aren't executing, often
due
to
resource contention or priority inversion.</p>
<p><strong>Fork/Join Concurrency:</strong> Involves
splitting
tasks into smaller subtasks and executing them
concurrently.
Data is shared before forking and after joining.</p>
</div>
<div class="chapter" id="sockets">
<h2>Sockets</h2>
<p>Java Sockets provide an interface through which
processes
can
send and receive information.</p>
<p>A socket is defined by an IP address and a port
number.</p>
<p>A connection is identified by the source and
destination
socket pair.</p>
<p>There are different types of sockets:</p>
<ul>
<li><strong>STREAM:</strong> Uses TCP for reliable
communication.</li>
<li><strong>DATAGRAM:</strong> Uses UDP for
unreliable
communication.</li>
<li><strong>RAW:</strong> Allows direct data
transfer
over
the IP protocol.</li>
</ul>
<p>The <code>DataInputStream</code> class is used to
create
an
input stream to receive responses, while
<code>DataOutputStream</code> is used to send
information.</p>
<p>For server-side communication, multiple threads are
required
to allow communication with clients and listening
for
new
connections to occur simultaneously.</p>
<p>The <code>accept()</code> method listens (blocks) for
a
connection and then creates and returns a new Socket
for
communication. The <code>close()</code> method is
used
to
close the ServerSocket.</p>
<p>A servant thread is responsible for managing each
client
connection socket, avoiding blocking the server with
only
one client. On the client side, a receiver thread
listens to
incoming messages without blocking the main
application.</p>
</div>
<div class="chapter" id="gui">
<h2>Java GUI</h2>
<p>The Java GUI (Graphical User Interface) follows the
Model-View-Controller (MVC) architecture:</p>
<ul>
<li><strong>Model:</strong> Application logic
separated
from
the user interface.</li>
<li><strong>View:</strong> Places graphical elements
(visual
aspect).</li>
<li><strong>Controller:</strong> Associates behavior
to
elements events.</li>
</ul>
<p>Important Java GUI components and their usage:</p>
<ul>
<li><strong>JFrame:</strong>
<ul>
<li>Base class for creating a window.</li>
<li>By default, closing the window doesn't
terminate
the application. Use
<code>setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);</code>
to terminate the application on
close.</li>
</ul>
</li>
<li><strong>JButton(String text):</strong> A button
component that can hold text.</li>
<li><strong>JLabel(String text, int
alignment):</strong>
A
label with text and alignment options
(SwingConstants.LEFT, RIGHT, CENTER).</li>
<li><strong>JTextField(String text, int
size):</strong>
A
single-line text field.</li>
<li><strong>JTextArea(String text, int rows, int
columns):</strong> A multi-line text area.
Use
<code>setLineWrap(boolean)</code> and
<code>setWrapStyleWord(boolean)</code> for
wrapping.</li>
<li><strong>JScrollPane(Component
component):</strong>
Adds
scroll bars to a component.</li>
<li><strong>JList(Object[] data):</strong> Displays
a
list
of items.</li>
<li><strong>JCheckBox(String text, boolean
selected):</strong> A checkbox
component.</li>
<li><strong>JRadioButton(String text, boolean
selected):</strong> A radio button
component.</li>
<li><strong>ButtonGroup:</strong> Ensures mutual
exclusion
for a group of radio buttons or checkboxes.</li>
<li><strong>JOptionPane:</strong> Provides standard
dialog
boxes:
<ul>
<li><code>JOptionPane.showMessageDialog(frame,
"Message");</code> to show a message
dialog.</li>
<li><code>JOptionPane.showOptionDialog</code>
for
choices.</li>
<li><code>JOptionPane.showInputDialog</code>
to
prompt for user input.</li>
</ul>
</li>
</ul>
<p>Layout Managers:</p>
<ul>
<li><strong>FlowLayout:</strong> Arranges components
from
left to right.</li>
<li><strong>GridLayout(int rows, int cols):</strong>
Arranges components in a grid.</li>
<li><strong>BorderLayout:</strong> Divides the
container
into five regions: NORTH, SOUTH, EAST, WEST, and
CENTER.</li>
<li><strong>GridBagLayout:</strong> A flexible
layout
manager that aligns components vertically and
horizontally, using a GridBagConstraints
object.</li>
</ul>
<p>Event Handling:</p>
<ul>
<li>Common events: MouseEvent, KeyEvent,
ActionEvent,
AdjustmentEvent (scroll bars), FocusEvent,
ItemEvent,
MouseMotionEvent, WindowEvent.</li>
<li>Example: <code>aButton.addActionListener(e ->
doClick(),
this);</code></li>
</ul>
<p>Listener Interfaces:</p>
<ul>
<li><strong>ActionListener:</strong> Override
<code>actionPerformed</code> method.</li>
<li><strong>FocusListener:</strong> Methods:
<code>focusGained</code>,
<code>focusLost</code>.</li>
<li><strong>ItemListener:</strong> Method:
<code>itemStateChanged</code>.</li>
<li><strong>MouseListener:</strong> Methods:
<code>mouseClicked</code>,
<code>mouseEntered</code>,
<code>mouseExited</code>,
<code>mousePressed</code>,
<code>mouseReleased</code>.</li>
<li><strong>MouseMotionListener:</strong> Methods:
<code>mouseDragged</code>,
<code>mouseMoved</code>.</li>
<li><strong>KeyListener:</strong> Methods:
<code>keyPressed</code>,
<code>keyReleased</code>,
<code>keyTyped</code>.</li>
<li><strong>WindowListener:</strong> Handles window
events.</li>
</ul>
<p>Direct Drawing:</p>
<ul>
<li>Requires a callback method: <code>void
paint(Graphics
g)</code> provides methods to draw.</li>
<li>Use <code>repaint()</code> to invoke
<code>paint()</code> and update the view when
something
changes.</li>
</ul>
</div>
<div class="chapter" id="streams">
<h2>Streams</h2>
<p>Streams in Java are sequences of elements from a source
that support aggregate operations.</p>
<p><strong>Features:</strong></p>
<ul>
<li>Pipelining</li>
<li>Internal iteration (no explicit loop)</li>
<li>Lazy evaluation</li>
</ul>
<p>Example:</p>
<pre><code>Stream.of(1, 2, ...).sorted().limit(4).forEach(System.out::println);</code></pre>
<p><strong>Operations:</strong></p>
<ul>
<li><code>findAny()</code> - Returns any element
(unordered)</li>
<li><code>findFirst()</code> - Returns the first element
(order counts)</li>
<li><code>min()</code>, <code>max()</code>,
<code>count()</code>, <code>forEach()</code></li>
</ul>
<p><strong>Source:</strong></p>
<ul>
<li><code>Arrays.stream(s)</code></li>
<li><code>Stream.of(1, 2, 3, ...)</code></li>
<li><code>collection.stream()</code></li>
</ul>
<p><strong>Source Generation:</strong></p>
<ul>
<li><code>Stream.generate(() -> Math.random())</code> -
Infinite stream</li>
<li><code>Stream.iterate(0, p -> p + 2)</code></li>
</ul>
<p><strong>Numeric Streams:</strong>
<code>DoubleStream</code>, <code>IntStream</code>,
<code>LongStream</code></p>
<pre><code>IntStream n = IntStream.generate(() -> (int) ...);</code></pre>
<p><strong>Filters:</strong></p>
<ul>
<li><code>distinct()</code>, <code>limit(int n)</code>,
<code>skip(int n)</code></li>
<li><code>.filter(Student::isFemale)</code></li>
<li><code>.filter(s ->
s.getFirst().equals(...))</code></li>
</ul>
<p><strong>Sorting:</strong></p>
<ul>
<li>Natural order: <code>stream().sorted()</code></li>
<li>With comparator:
<code>stream().sorted(Comparator.comparingInt(Student::getId))</code></li>
</ul>
<p><strong>Mapping:</strong></p>
<ul>
<li><code>stream().map(Student::getFirst)</code></li>
<li>Mapping to primitive streams: <code>mapToInt</code>,
<code>mapToLong</code>,
<code>mapToDouble</code></li>
<li>Example:
<code>stream().map(Student::getFirst).mapToInt(String::length)</code></li>
</ul>
<p><strong>Flat Mapping:</strong></p>
<p>Flat mapping is used when stream elements are containers
(like a List).</p>
<pre><code>flatMap(Collection::stream) // Extract a stream for each element</code></pre>
<p><strong>Terminal Operations:</strong></p>
<ul>
<li><code>anyMatch()</code>, <code>allMatch()</code>,
<code>noneMatch()</code> - Return boolean</li>
<li><code>reduce()</code>, <code>collect()</code>,
<code>parallel()</code> - Often used for parallel
processing</li>
</ul>
<p><strong>Collectors:</strong> <code>collect()</code>
accumulates the elements into a result.</p>
<p><strong>Summarizing Collectors:</strong></p>
<ul>
<li><code>counting()</code>, <code>maxBy()</code>,
<code>minBy()</code>, <code>summingType()</code>,
<code>averagingType()</code>,
<code>summarizingType()</code></li>
</ul>
<p><strong>Accumulating Collectors:</strong></p>
<ul>
<li><code>toList()</code>, <code>toSet()</code>,
<code>toCollection(Supplier::new)</code>,
<code>joining()</code></li>
</ul>
<p><strong>Group Container Collectors:</strong></p>
<ul>
<li><code>groupingBy</code>,
<code>partitioningBy</code></li>
</ul>
<p><strong>Custom Collectors:</strong></p>
<pre><code>Collector.of(supplier, accumulator, combiner)</code></pre>
</div>
<div class="chapter" id="reflection">
<h2>Reflection</h2>
<p>Java Reflection is the process by which a program can
modify
its behavior at runtime. A program is reflective if
it
can
analyze and modify its own parameters
dynamically.</p>
<p><code>java.lang.Class</code>: This class provides
methods
to
get the class of an object.</p>
<pre><code>// Get the class of an existing object
Class<?> c = scan.getClass();
// When only the type is known
(AnyType).class;
// Get the class by name
Class<?> c1 = Class.forName("java.util.Scanner");
</code></pre>
<p><code>java.lang.reflect.Constructor</code>:
Represents a
constructor for a class object.</p>
<p><code>java.lang.reflect.Method</code>: Represents a
method in
a class.</p>
<p><code>java.lang.reflect.Field</code>: Represents a
field
within a class.</p>
<p><code>java.lang.reflect.AccessibleObject</code>: This
class
is used to modify accessibility at runtime.</p>
<p><code>java.lang.reflect.Modifier</code>: Provides
methods
to
extract facts about modifiers. For example,
<code>isPrivate(int i)</code> checks if the modifier
is
private.</p>
<p>Function Pointers: In Java, function pointers are
emulated by
passing method objects and invoking them.</p>
<p><code>ClassLoader</code>: This class is responsible
for
loading classes. Every class has a reference to the
ClassLoader that created it (except primitives).</p>
<p><strong>Bootstrap Class Loader:</strong> This is the
original
ClassLoader that has no parent class loader.</p>
</div>
<div class="chapter" id="verification-validation">
<h2>Verification and Validation</h2>
<p>Verification and Validation (V&V) are essential
processes
in
software engineering to ensure the correctness and
quality
of software products.</p>
<h3>Differences</h3>
<table>
<tr>
<th>Aspect</th>
<th>Verification</th>
<th>Validation</th>
</tr><tr>
<td>Question</td>
<td>"Are we building the product right?"</td>
<td>"Are we building the right product?"</td>
</tr>
<tr>
<td>Objective</td>
<td>Evaluating whether the software is built
correctly
according to specifications.</td>
<td>Evaluating whether the right product is
built to
meet user needs and expectations.</td>
</tr>
<tr>
<td>Focus</td>
<td>Process-oriented (internal quality)</td>
<td>Product-oriented (external quality)</td>
</tr>
<tr>
<td>Timing</td>
<td>Performed throughout the development
lifecycle.</td>
<td>Performed at the end of the development
lifecycle.</td>
</tr>
<tr>
<td>Method</td>
<td>Static analysis techniques, reviews, and
inspections.</td>
<td>Dynamic testing techniques, including
various
types
of testing.</td>
</tr>
</table>
<h3>Techniques:</h3>
<img src="img/v&v_techniques.png"
alt="Verification and Validation Techniques"
style="max-width: 100%; height: auto;">
<h3>Terminology:</h3>
<ul>
<li><strong>Fault:</strong> A feature that may lead
to
an
error due to a defect or incorrect
requirement.</li>
<li><strong>Error:</strong> The runtime effect of
executing
a fault, which may result in a failure.</li>
<li><strong>Failure:</strong> The manifestation of
an
error
external to the program.</li>
</ul>
<p>The longer the delay in detecting and removing
defects,
the
higher the cost incurred.</p>
<h3>Goals of V&V:</h3>
<ul>
<li>Minimize the number of defects inserted during
software
development.</li>
<li>Maximize the number of defects discovered and
removed
during testing.</li>
<li>Minimize detection delay to promptly address
issues.</li>
</ul>
<h3>Static Analysis:</h3>
<p>Static analysis involves examining software artifacts
without
executing them. It helps identify potential issues
early
in
the development process.</p>
<ul>
<li><strong>Automatic Code Analysis:</strong> This
is
performed on the source code at compile time,
providing
insights into code quality and potential
vulnerabilities.</li>
<li><strong>Code Smells:</strong> Indications in the
code
that usually correspond to a problem, such as
violations
of design principles.</li>
<li><strong>Technical Debt:</strong> Refers to the
implied
cost of additional rework caused by choosing an
expedient solution rather than the best one,
leading
to
the need for code rewriting.</li>
</ul>
</div>
<div class="chapter" id="testing">
<h2>Testing</h2>
<p>Testing is conducted to find defects and detect
differences
between actual and expected behavior.</p>
<h3>Why Testing?</h3>
<p>Testing is essential to:</p>
<ul>
<li>Improve software design.</li>
<li>Make software easier to understand.</li>
<li>Reduce debugging time.</li>
<li>Catch integration errors to produce better
code.</li>
</ul>
<h3>What to Test?</h3>
<p>Testing covers various aspects including:</p>
<ul>
<li>Boundary conditions.</li>
<li>Success and failure scenarios.</li>
<li>General functionality.</li>
</ul>
<h3>Test Case</h3>
<p>A test case is represented as:</p>
<p><strong>T1:</strong> (input1, input2, ...; expected
output)
// Name</p>
<h3>Test Suite</h3>
<p>A test suite is a collection of test cases:</p>
<p><strong>TS1:</strong> {T1, T2}</p>
<h3>Oracle</h3>
<p>An oracle is used to know the expected behavior for a
given
test case.</p>
<h3>Unit Test</h3>
<p>Unit testing can be performed in two ways:</p>
<ul>
<li><strong>Black Box:</strong> No knowledge of
internal
structure, focusing on functional testing,
involving
random testing, equivalence class partitioning,
and
boundary conditions.</li>
<li><strong>White Box:</strong> Structural testing,
examining the internal structure, and covering
structural elements such as statements,
decisions,
conditions, paths, and loops.</li>
</ul>
<h3>Integration Testing</h3>
<p>Integration testing involves adding one unit at a
time to
test the system.</p>
<h3>Regression Test</h3>
<p>Regression testing involves testing the old code to
verify it
works after changes.</p>
</div>
<div class="chapter" id="black-box-testing">
<h2>Black Box Testing</h2>
<p><strong>Black Box Tests</strong> focus on software
simplicity, making assumptions about implementation
and
testing component interactions. They target
interfaces
and
behavior.</p>
<h3>Selection Criteria:</h3>
<ul>
<li>Equivalence class-based</li>
<li>Boundary condition-based</li>
</ul>
<h3>Termination Criteria:</h3>