-
Notifications
You must be signed in to change notification settings - Fork 1
/
backtracking.html
4613 lines (4445 loc) · 264 KB
/
backtracking.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" />
<link rel="shortcut icon" href="assets/img/mainlogo.jpg" type="image/x-icon">
<title>Home</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="assets/prism.css">
<link rel="stylesheet" href="assets/css/style.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="myDesigns/assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700,300italic,400italic,700italic">
<link rel="stylesheet" href="myDesigns/assets/fonts/font-awesome.min.css">
<link rel="stylesheet" href="myDesigns/assets/fonts/simple-line-icons.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css" />
<style>
.scroll-to-top {
background-color: #f77b50 !important;
text-decoration: none !important;
}
.scroll-to-top:hover {
background: #f77b50 !important;
text-decoration: none !important;
}
footer .scroll-to-top {
text-decoration: none !important;
}
.offcanvas {
width: 700px !important; /* Override the default width */
}
</style>
</head>
<body id="page-top">
<nav class="navbar fixed-top navbar-expand-lg navbar-dark" style="background-color: rgb(1,4,45);">
<div class="container-fluid">
<a class="navbar-brand" href="index.html">
<img src="assets/img/mainlogo.jpg" alt="" style="height: 7vh;"> Cheatbook
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="index.html">Home</a>
</li>
<!--frontend -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Frontend
</a>
<ul class="dropdown-menu multi-column columns-2">
<div class="row">
<div class="col-sm-6">
<ul class="multi-column-dropdown">
<li><a class="dropdown-item" href="html.html">HTML</a></li>
<li><a class="dropdown-item" href="css.html">CSS</a></li>
<li><a class="dropdown-item"
href="javascript.html">JavaScript</a></li>
<li><a class="dropdown-item"
href="typescript.html">TypeScript</a></li>
<li>
<hr class="dropdown-divider" />
</li>
<li class="dropdown-header">JavaScript Frameworks</li>
<li><a class="dropdown-item" href="reactjs.html">Reacjs</a></li>
<li><a class="dropdown-item" href="nextjs.html">Nextjs</a></li>
<li><a class="dropdown-item"
href="angularjs.html">Angularjs</a></li>
<li><a class="dropdown-item" href="remix.html">Remixjs</a></li>
<li><a class="dropdown-item" href="vuejs.html">vuejs</a></li>
</ul>
</div>
<div class="col-sm-6">
<ul class="multi-column-dropdown">
<li><a class="dropdown-item" href="astrojs.html">Astrojs</a></li>
<li><a class="dropdown-item" href="electronjs.html">electronjs</a></li>
<li>
<hr class="dropdown-divider" />
</li>
<li class="dropdown-header">CSS Framework</li>
<li><a class="dropdown-item" href="bootstrap.html">Bootstrap</a></li>
<li><a class="dropdown-item" href="tailwindcss.html">Tailwind css</a></li>
<li><a class="dropdown-item" href="materialui.html">Material UI</a></li>
<li> <hr class="dropdown-divider" /> </li>
<li class="dropdown-header">State Management</li>
<li><a class="dropdown-item" href="redux.html">Redux</a></li>
</ul>
</div>
</div>
</ul>
</li>
<!-- backend -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Backend
</a>
<ul class="dropdown-menu multi-column columns-2">
<div class="row">
<div class="col-sm-6">
<ul class="multi-column-dropdown">
<li><a class="dropdown-item" href="django.html">Django</a></li>
<li><a class="dropdown-item" href="flask.html">Flask</a></li>
<li><a class="dropdown-item" href="fastapi.html">Fastapi</a></li>
<li><a class="dropdown-item" href="expressjs.html">Expressjs</a></li>
<li><a class="dropdown-item" href="nodejs.html">Nodejs</a></li>
<li><a class="dropdown-item" href="php.html">PHP</a></li>
<li><a class="dropdown-item" href="golang.html">GO</a></li>
<li><a class="dropdown-item" href="spring.html">Spring</a></li>
<li><a class="dropdown-item"href="springboot.html">Springboot</a></li>
<li> <hr class="dropdown-divider" /></li>
<li class="dropdown-header">Databases</li>
<li><a class="dropdown-item" href="Sql.html">SQL</a></li>
</ul>
</div>
<div class="col-sm-6">
<ul class="multi-column-dropdown">
<li><a class="dropdown-item" href="mysql.html">MySQL</a></li>
<li><a class="dropdown-item" href="mongodb.html">MongoDB</a></li>
<li><a class="dropdown-item" href="firebase.html">Firebase</a></li>
<li><a class="dropdown-item" href="cassandra.html">Cassandra</a></li>
<li><a class="dropdown-item" href="redis.html">Redis</a></li>
<li><a class="dropdown-item" href="postgresql.html">PostgreSQL</a></li>
<li><a class="dropdown-item" href="influxdb.html">infixDB</a></li>
<li> <hr class="dropdown-divider" /> </li>
<li class="dropdown-header">Java technologies</li>
<li><a class="dropdown-item" href="hibernet.html">Hibernet</a></li>
<li><a class="dropdown-item" href="jdbc.html">jdbc</a></li>
<li><a class="dropdown-item" href="servlets.html">servlets</a></li>
</ul>
</div>
</div>
</ul>
</li>
<!-- programming -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Programming
</a>
<ul class="dropdown-menu multi-column columns-2">
<div class="row">
<div class="col-sm-6">
<ul class="multi-column-dropdown">
<li><a class="dropdown-item" href="cplus.html">C++</a></li>
<li><a class="dropdown-item" href="c.html">C</a></li>
<li><a class="dropdown-item" href="java.html">Java</a></li>
<li><a class="dropdown-item" href="python.html">Python</a></li>
</ul>
</div>
<div class="col-sm-6">
<ul class="multi-column-dropdown">
<li class="dropdown-header">Data structure</li>
<li><a class="dropdown-item" href="dsa.html">DSA</a></li>
</ul>
</div>
</div>
</ul>
</li>
<!-- databases -->
<li class="nav-item dropdown mx-1">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Design
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="figma.html">Figma</a></li>
<li><a class="dropdown-item" href="adobexd.html">AdobeXD</a></li>
</ul>
</li>
<!-- API & Authentication -->
<li class="nav-item dropdown mx-1">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
API & Auth
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="restfulapi.html">RESTful API</a></li>
<li><a class="dropdown-item" href="graphql.html">GraphQL</a></li>
<li><a class="dropdown-item" href="jwtauth.html">JWT Auth</a></li>
<li><a class="dropdown-item" href="apollo.html">Apollo</a></li>
</ul>
</li>
<!-- testing -->
<li class="nav-item dropdown mx-1">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Testing
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="jest.html">Jest</a></li>
</ul>
</li>
<!-- cloud services -->
<li class="nav-item dropdown mx-1">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Cloud
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="aws.html">AWS</a></li>
<li><a class="dropdown-item" href="azure.html">Azure</a></li>
<li><a class="dropdown-item" href="googlecloud.html">Google Cloud</a></li>
<li><a class="dropdown-item" href="cloudflare.html">Cloudflare</a></li>
</ul>
</li>
<!-- Mobile Development-->
<li class="nav-item dropdown mx-1">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Mobile Dev
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="android.html">Android</a></li>
<li><a class="dropdown-item" href="kotlin.html">Kotlin</a></li>
<li><a class="dropdown-item" href="reactnative.html">React Native</a></li>
<li><a class="dropdown-item" href="flutter.html">Flutter</a></li>
</ul>
</li>
<!-- Devops -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Devops
</a>
<ul class="dropdown-menu multi-column columns-2">
<div class="row">
<div class="col-sm-6">
<ul class="multi-column-dropdown">
<li class="dropdown-header">CI/CD</li>
<li><a class="dropdown-item" href="docker.html">Docker</a></li>
<li><a class="dropdown-item" href="jenkins.html">jenkins</a></li>
<li><a class="dropdown-item" href="kubernetes.html">kubernetes</a></li>
<li><a class="dropdown-item" href="maven.html">Maven</a></li>
<li><a class="dropdown-item" href="git.html">Git</a> </li>
<li><a class="dropdown-item" href="github_action.html">Github Actions</a></li>
<li><a class="dropdown-item" href="Terraform.html">Terraform</a></li>
<li><a class="dropdown-item" href="ansible.html">Ansible</a></li>
<li><hr class="dropdown-divider" /></li>
<li class="dropdown-header">Web Servers</li>
<li><a class="dropdown-item" href="languages/devops/nginx.html">Nginx</a>
</li>
</ul>
</div>
<div class="col-sm-6">
<ul class="multi-column-dropdown">
<hr class="dropdown-divider" />
</li>
<li class="dropdown-header">Operating System</li>
<li><a class="dropdown-item" href="windows.html">Windows</a>
</li>
<li><a class="dropdown-item" href="linux.html">Linux</a>
</li>
<li><a class="dropdown-item" href="macos.html">Macos</a>
</li>
<li>
<hr class="dropdown-divider" />
</li>
<li class="dropdown-header">Scripting</li>
<li><a class="dropdown-item" href="bashscript.html">Bash Scripting</a>
</li>
<li>
<hr class="dropdown-divider" />
</li>
<li class="dropdown-header">Monitoring</li>
<li><a class="dropdown-item" href="monit.html">Monit</a>
</ul>
</div>
</div>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="about.html">About Us</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Tools
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="tools/shadowpicker/index.html">Shadow Picker</a></li>
<li><a class="dropdown-item" href="tools/readmemaker/index.html">Github Project Readme</a>
</li>
<li><a class="dropdown-item" href="tools/profilereadme/index.html">Github Profile Readme</a>
</li>
<li><a class="dropdown-item" href="tools/gradientcolorpicker.html">Gradient Colour
Picker</a></li>
<li><a class="dropdown-item" href="tools/colourbook/colorpiceker.html">Colour Picker</a>
</li>
<li><a class="dropdown-item" href="tools/codereview/index.html">Simple Code Editor</a> </li>
<li><a class="dropdown-item" href="tools/banner/index.html">Banner Maker</a> </li>
<li><a class="dropdown-item" href="tools/logomaker/index.html">Logo & Favicon Maker</a>
</li>
<li><a class="dropdown-item" href="tools/paraiso-colors-main/index.html">colour plates</a>
</li>
</ul>
</li>
</ul>
<a href="myDesigns/index.html">
<div class="button btn1 mx-1" style="font-size: 1em;">My Designs</div>
</a>
</div>
</div>
</nav> <!-- mid part -->
<nav class="mt-5 p-2 headline" style="background:linear-gradient(to top right, #fb5475 0%, #f77b50 59%);">
<div class="text-center " style="margin-top:5vh;"><img style="margin-right:2vh;"
src="../../assets/img/java-icon.svg" alt="" /> Java cheatsheet
</div>
</nav>
<div class="container">
<div class="p-5 mb-4 bg-light rounded-3 jumbo mt-2">
<div class="container-fluid py-3">
<h1 class="display-5 fw-bold">Java</h1>
<div class="row">
<div class="col-md-6">
<p class="fs-4">
Java is a popular programming language, created in 1995.
<br> It is owned by Oracle, and more than 3 billion devices run Java.
<br> It is used for:
<br>
<ul>
<li>
Mobile applications (specially Android apps)</li>
<li> Desktop applications</li>
<li> Web applications</li>
<li> Web servers and application servers</li>
</ul>
</p>
</div>
<div class="col-md-6 text-center">
<img src="../../assets/img/java-icon.svg" alt="" style="height:100%;width:100%;" />
</div>
</div>
<button class="btn btn1" type="button" data-bs-toggle="offcanvas" data-bs-target="#o1"
aria-controls="o1">
Read More...
</button>
<a href="https://docs.oracle.com/en/java/javase/11/docs/api/index.html">
<div class="button btn1 mx-1 text-center" style="font-size: 1em;width:5em;">Docs</div>
</a>
<div class="offcanvas offcanvas-start" data-bs-scroll="true" tabindex="-1" id="o1"
aria-labelledby="offcanvasWithBothOptionsLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasWithBothOptionsLabel">
Java
</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<ol type="a">
<li>Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.)</li>
<li>It is one of the most popular programming language in the world</li>
<li> It has a large demand in the current job market</li>
<li> It is easy to learn and simple to use</li>
<li> It is open-source and free</li>
<li>It is secure, fast and powerful</li>
<li>It has a huge community support (tens of millions of developers)</li>
<li>Java is an object oriented language which gives a clear structure to programs and allows
code to be reused, lowering development costs</li>
<li>As Java is close to C++ and C#, it makes it easy for programmers to switch to Java or
vice versa</li>
</ol>
</div>
</div>
</div>
</div>
<ol>
<!-- offcanvas -->
<li>
Java Syntax<button class="btn btn1" type="button" data-bs-toggle="offcanvas"
data-bs-target="#offcanvasBottom2" aria-controls="offcanvasBottom">Read more...</button>
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasBottom2"
aria-labelledby="offcanvasBottomLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasBottomLabel">Java Syntax</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body small">
The curly braces {} marks the beginning and the end of a block of code.
<br><br> System is a built-in Java class that contains useful members, such as out, which is
short for "output". The println() method, short for "print line", is used to print a value to
the screen (or a file).
<br><br> Don't worry too much about System, out and println(). Just know that you need them
together to print stuff to the screen.
<br><br> You should also note that each code statement must end with a semicolon (;).
</div>
</div>
<pre class="language-java">
<code>
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
</code>
</pre>
</li>
<li>Convert .java file to .class byte code file
<pre class="language-sh">
<code>
javac Main.java
</code>
</pre>
</li>
<li>Run .class byte code file
<pre class="language-sh">
<code>
java Main
</code>
</pre>
</li>
<li>
Print Text<button class="btn btn1" type="button" data-bs-toggle="offcanvas"
data-bs-target="#offcanvasBottom3" aria-controls="offcanvasBottom">Read more...</button>
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasBottom3"
aria-labelledby="offcanvasBottomLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasBottomLabel">Print Text</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body small">
1) The Print() Method<br> There is also a print() method, which is similar to println(). <br>
The only difference is that it does not insert a new line at the end of the output
<br><br><br>2) Println() <br> You can add as many println() methods as you want. Note that it
will add a new line for each method
</div>
</div>
<h3>Print()</h3>
<pre class="language-java">
<code>
System.out.print("I will print on the same line.");
</code>
</pre>
<h3>Println()</h3>
<pre class="language-java">
<code>
System.out.println("Hello World!");
</code>
</pre>
</li>
<li>Take inputs
<pre class="language-java">
<code>
Scanner input=new Scanner(System.in);
float marks =input.nextFloat();
</code>
</pre>
</li>
<li>Java Comments
<button class="btn btn1" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasBottom4"
aria-controls="offcanvasBottom">Read more...</button>
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasBottom4"
aria-labelledby="offcanvasBottomLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasBottomLabel">Java Comments</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body small">
Comments can be used to explain Java code, and to make it more readable. It can also be used to
prevent execution when testing alternative code.
<br><br> Single-line Comments<br> Single-line comments start with two forward slashes (//).
<br> Any text between // and the end of the line is ignored by Java (will not be executed).
<br><br>Java Multi-line Comments<br> Multi-line comments start with /* and ends with */.
<br> Any text between /* and */ will be ignored by Java.
</div>
</div>
<h3>single linecomment</h3>
<pre class="language-java">
<code>
// This is a comment
</code>
</pre>
<h3>Multi-Line comments</h3>
<pre class="language-java">
<code>
/* The code below will print the words Hello World
to the screen, and it is amazing */
</code>
</pre>
</li>
<li>Java Variables<button class="btn btn1" type="button" data-bs-toggle="offcanvas"
data-bs-target="#offcanvasBottom5" aria-controls="offcanvasBottom">Read more...</button>
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasBottom5"
aria-labelledby="offcanvasBottomLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasBottomLabel">Java Variables</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body small">
Variables are containers for storing data values.
<br><br> In Java, there are different types of variables, for example:
<br>
<ol>
<li>String - stores text, such as "Hello". String values are surrounded by double quotes
</li>
<li>int - stores integers (whole numbers), without decimals, such as 123 or -123
</li>
<li>float - stores floating point numbers, with decimals, such as 19.99 or -19.99
</li>
<li>char - stores single characters, such as 'a' or 'B'. Char values are surrounded by
single quotes</li>
<li>boolean - stores values with two states: true or false
</li>
</ol><br><br> Final Variables <br> If you don't want others (or yourself) to overwrite existing
values, use the final keyword (this will declare the variable as "final" or "constant", which
means unchangeable and read-only)
</div>
</div>
<h3>Declaring (Creating) Variables (Syntax)</h3>
<pre class="language-java">
<code>
type variableName = value;
</code>
</pre>
<h3>Final Variables</h3>
<pre class="language-java">
<code>
final int myNum = 15;
</code>
</pre>
</li>
<li>
Identifiers<button class="btn btn1" type="button" data-bs-toggle="offcanvas"
data-bs-target="#offcanvas2" aria-controls="offcanvasBottom">Read more...</button>
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvas2"
aria-labelledby="offcanvasBottomLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasBottomLabel">Identifiers</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body small">
All Java variables must be identified with unique names.
<br> These unique names are called identifiers.
<br> Identifiers can be short names (like x and y) or more descriptive names (age, sum,
totalVolume).
<br><br> Note: It is recommended to use descriptive names in order to create understandable and
maintainable code
<br><br> The general rules for naming variables are:
<br> Names can contain letters, digits, underscores, and dollar signs<br> Names must begin with
a letter<br> Names should start with a lowercase letter and it cannot contain whitespace<br>
Names can also begin with $ and _ (but
we will not use it in this tutorial)<br> Names are case sensitive ("myVar" and "myvar" are
different variables)<br> Reserved words (like Java keywords, such as int or boolean) cannot be
used as names <br>
</div>
</div>
</li>
<li>Java Data Types
<button class="btn btn1" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasBottom9"
aria-controls="offcanvasBottom">Read more...</button>
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasBottom9"
aria-labelledby="offcanvasBottomLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasBottomLabel">Java Data Types</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body small">
Data types are divided into two groups:
<br> <br> 1)Primitive data types - includes byte, short, int, long, float, double, boolean and
char
<br> 2)Non-primitive data types - such as String, Arrays and Classes (you will learn more about
these in a later chapter) <br>Non-primitive data types are called reference types because they
refer to objects.
<br> The main difference between primitive and non-primitive data types are:
<br> Primitive types are predefined (already defined) in Java. Non-primitive types are created
by the programmer and is not defined by Java (except for String).
<br>Non-primitive types can be used to call methods to perform certain operations, while
primitive types cannot.<br> A primitive type has always a value, while non-primitive types can
be null.
<br>A primitive type starts with a lowercase letter, while non-primitive types starts with an
uppercase letter.<br> The size of a primitive type depends on the data type, while non-primitive
types have all the same size. <br> <br> 1) Primitive Data Types <br> A primitive data type
specifies the size and type of variable values, and it has no additional methods.
<br> There are eight primitive data types in Java: <br> <br>
<table class="ws-table-all notranslate table-bordered">
<tbody>
<tr>
<th style="width:20%">Data Type</th>
<th style="width:17%">Size</th>
<th style="width:63%">Description</th>
</tr>
<tr>
<td><code class="w3-codespan">byte</code></td>
<td>1 byte</td>
<td>Stores whole numbers from -128 to 127</td>
</tr>
<tr>
<td><code class="w3-codespan">short</code></td>
<td>2 bytes</td>
<td>Stores whole numbers from -32,768 to 32,767</td>
</tr>
<tr>
<td><code class="w3-codespan">int</code></td>
<td>4 bytes</td>
<td>Stores whole numbers from -2,147,483,648 to 2,147,483,647</td>
</tr>
<tr>
<td><code class="w3-codespan">long</code></td>
<td>8 bytes</td>
<td>Stores whole numbers from -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
</td>
</tr>
<tr>
<td><code class="w3-codespan">float</code></td>
<td>4 bytes</td>
<td>Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits</td>
</tr>
<tr>
<td><code class="w3-codespan">double</code></td>
<td>8 bytes</td>
<td>Stores fractional numbers. Sufficient for storing 15 decimal digits</td>
</tr>
<tr>
<td><code class="w3-codespan">boolean</code></td>
<td>1 bit</td>
<td>Stores true or false values</td>
</tr>
<tr>
<td><code class="w3-codespan">char</code></td>
<td>2 bytes</td>
<td>Stores a single character/letter or ASCII values</td>
</tr>
</tbody>
</table>
<br><br> Primitive number types are divided into two groups:
<br><br> A) Integer types stores whole numbers, positive or negative (such as 123 or -456),
without decimals. Valid types are byte, short, int and long. Which type you should use, depends
on the numeric value.
<br> <br><br> B) Floating point types represents numbers with a fractional part, containing one
or more decimals. There are two types: float and double.
<br><br>3)Boolean Types:Very often in programming, you will need a data type that can only have
one of two values, like:
<br><br> YES / NO<br> ON / OFF<br> TRUE / FALSE<br> For this, Java has a boolean data type,
which can only take the values true or false
<br><br> 4)Characters: <br> The char data type is used to store a single character. The
character must be surrounded by single quotes, like 'A' or 'c' <br><br> 5)Strings: <br> The
String data type is used to store a sequence of
characters (text). String values must be surrounded by double quotes
</div>
</div>
<h3>Premitive number type : Integer type</h3>
<div class="accordion" id="accordionExample">
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseOne1" aria-expanded="false" aria-controls="collapseOne">
byte
</button>
</h2>
<div id="collapseOne1" class="accordion-collapse collapse" aria-labelledby="headingOne"
data-bs-parent="#accordionExample">
<div class="accordion-body">
<pre class="language-java">
<code>
byte myNum = 100;
</code>
</pre>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingTwo">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseTwo1" aria-expanded="false" aria-controls="collapseTwo">
short
</button>
</h2>
<div id="collapseTwo1" class="accordion-collapse collapse" aria-labelledby="headingTwo"
data-bs-parent="#accordionExample">
<div class="accordion-body">
<pre class="language-java">
<code>
short myNum = 5000;
</code>
</pre>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingThree">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseThree1" aria-expanded="false" aria-controls="collapseThree">
int
</button>
</h2>
<div id="collapseThree1" class="accordion-collapse collapse" aria-labelledby="headingThree"
data-bs-parent="#accordionExample">
<div class="accordion-body">
<pre class="language-java">
<code>
int myNum = 100000;
</code>
</pre>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingThree">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#collapsefour1" aria-expanded="false" aria-controls="collapseThree">
long
</button>
</h2>
<div id="collapsefour1" class="accordion-collapse collapse" aria-labelledby="headingThree"
data-bs-parent="#accordionExample">
<div class="accordion-body">
<pre class="language-java">
<code>
long myNum = 15000000000L;
</code>
</pre>
</div>
</div>
</div>
</div>
<br><br>
<h3>Premitive number type : Floating Point Types</h3>
<div class="accordion" id="accordionExample">
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseOne2" aria-expanded="false" aria-controls="collapseOne">
float
</button>
</h2>
<div id="collapseOne2" class="accordion-collapse collapse" aria-labelledby="headingOne"
data-bs-parent="#accordionExample">
<div class="accordion-body">
<pre class="language-java">
<code>
float myNum = 5.75f;
</code>
</pre>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingTwo">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseTwo2" aria-expanded="false" aria-controls="collapseTwo">
double
</button>
</h2>
<div id="collapseTwo2" class="accordion-collapse collapse" aria-labelledby="headingTwo"
data-bs-parent="#accordionExample">
<div class="accordion-body">
<pre class="language-java">
<code>
double d1 = 12E4d;
</code>
</pre>
</div>
</div>
</div>
</div>
<br><br>
<h3>Boolean Types</h3>
<pre class="language-java">
<code>
boolean isJavaFun = true;
</code>
</pre>
<br>
<h3>Characters</h3>
<pre class="language-java">
<code>
char myGrade = 'B';
</code>
</pre>
<br>
<h3>Strings</h3>
<pre class="language-java">
<code>
String greeting = "Hello World";
</code>
</pre>
</li>
<li>
Java Type Casting<button class="btn btn1" type="button" data-bs-toggle="offcanvas"
data-bs-target="#offcanvasBottom10" aria-controls="offcanvasBottom">Read more...</button>
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasBottom10"
aria-labelledby="offcanvasBottomLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasBottomLabel">Java Type Casting</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body small">
Type casting is when you assign a value of one primitive data type to another type.
<br> In Java, there are two types of casting:
<br> Widening Casting (automatically) - converting a smaller type to a larger type size byte ->
short -> char -> int -> long -> float -> double
<br><br> Narrowing Casting (manually) - converting a larger type to a smaller size type double
-> float -> long -> int -> char -> short -> byte
</div>
</div>
<h3>Widening Casting</h3>
<pre class="language-java">
<code>
int myInt = 9;
double myDouble = myInt; // Automatic casting: int to double
</code>
</pre>
<h3>Narrowing Casting</h3>
<pre class="language-java">
<code>
double myDouble = 9.78d;
int myInt = (int) myDouble; // Manual casting: double to int
</code>
</pre>
</li>
<li>Java Operators<button class="btn btn1" type="button" data-bs-toggle="offcanvas"
data-bs-target="#offcanvasBottom12" aria-controls="offcanvasBottom">Read more...</button>
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasBottom12"
aria-labelledby="offcanvasBottomLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasBottomLabel">Java Operators</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body small">
Operators are used to perform operations on variables and values.
<br><br> Java divides the operators into the following groups:
<br> 1) Arithmetic operators<br> 2) Assignment operators<br> 3) Comparison operators<br> 4)
Logical operators<br> 5) Bitwise operators <br><br><br> 1)Arithmetic Operators <br> Arithmetic
operators are used to perform common mathematical
operations.
<table class="ws-table-all notranslate table-bordered">
<tbody>
<tr>
<th style="width:15%">Operator</th>
<th style="width:18%">Name</th>
<th style="width:50%">Description</th>
<th style="width:17%;">Example</th>
</tr>
<tr>
<td>+</td>
<td>Addition</td>
<td>Adds together two values</td>
<td>x + y</td>
</tr>
<tr>
<td>-</td>
<td>Subtraction</td>
<td>Subtracts one value from another</td>
<td>x - y</td>
</tr>
<tr>
<td>*</td>
<td>Multiplication</td>
<td>Multiplies two values</td>
<td>x * y</td>
</tr>
<tr>
<td>/</td>
<td>Division</td>
<td>Divides one value by another</td>
<td>x / y</td>
</tr>
<tr>
<td>%</td>
<td>Modulus</td>
<td>Returns the division remainder</td>
<td>x % y</td>
</tr>
<tr>
<td>++</td>
<td>Increment</td>
<td>Increases the value of a variable by 1</td>
<td>++x</td>
</tr>
<tr>
<td>--</td>
<td>Decrement</td>
<td>Decreases the value of a variable by 1</td>
<td>--x</td>
</tr>
</tbody>
</table>
<br><br> 2) Java Assignment Operators <br> Assignment operators are used to assign values to
variables. <br><br>
<table class="ws-table-all notranslate table-bordered">
<tbody>
<tr>
<th style="width:30%">Operator</th>
<th style="width:35%">Example</th>
<th style="width:35%">Same As</th>
</tr>
<tr>
<td>=</td>
<td>x = 5</td>
<td>x = 5</td>
</tr>
<tr>
<td>+=</td>
<td>x += 3</td>
<td>x = x + 3</td>
</tr>
<tr>
<td>-=</td>
<td>x -= 3</td>
<td>x = x - 3</td>
</tr>
<tr>
<td>*=</td>
<td>x *= 3</td>
<td>x = x * 3</td>
</tr>
<tr>
<td>/=</td>
<td>x /= 3</td>
<td>x = x / 3</td>
</tr>
<tr>
<td>%=</td>
<td>x %= 3</td>
<td>x = x % 3</td>
</tr>
<tr>
<td>&=</td>
<td>x &= 3</td>
<td>x = x & 3</td>
</tr>
<tr>
<td>|=</td>
<td>x |= 3</td>
<td>x = x | 3</td>
</tr>
<tr>
<td>^=</td>
<td>x ^= 3</td>
<td>x = x ^ 3</td>
</tr>
<tr>
<td>>>=</td>
<td>x >>= 3</td>
<td>x = x >> 3</td>
</tr>
<tr>
<td><<=</td>
<td>x <<= 3</td>
<td>x = x << 3</td>
</tr>
</tbody>