-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava.html
More file actions
2325 lines (2161 loc) · 133 KB
/
Copy pathjava.html
File metadata and controls
2325 lines (2161 loc) · 133 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>
<head runat="server">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" href="images/logo/favicon.png" type="image/png">
<link href="https://fonts.googleapis.com/css2?family=Raleway:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="fonts/icomoon/style.css">
<link rel="stylesheet" href="fonts/brand/style.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-datepicker.css">
<link rel="stylesheet" href="css/jquery.fancybox.min.css">
<link rel="stylesheet" href="css/owl.carousel.min.css">
<link rel="stylesheet" href="css/owl.theme.default.min.css">
<link rel="stylesheet" href="css/aos.css">
<link href="css/slider.css" rel="stylesheet" />
<link href="css/side-nav.css" rel="stylesheet" />
<!-- MAIN CSS -->
<link rel="stylesheet" href="css/style.css">
<title>Java Tutorial</title>
<style type="text/css">
.flex {
display:flex;
justify-content: space-between;
}
.divBg {
background-color:#C0C0C0;
border:none;
width:100%;
}
.divBg:hover {
background-color:gray;
color:white;
}
.divBg:after {
background-color:gray;
color:white;
}
div#mySidenav a:hover {
background-color: white;
color: #0779E4;
font-weight: bold;
}
div#mySidenav a.active {
background-color: #0779E4;
color: white;
}
.spnblack {
color:black;
font-weight:bold;
}
.spn-clr1 {
background-color:lightgray;
color:mediumvioletred;
}
.divpad {
background-color:lightgray;
padding: 20px 20px 20px 20px;
}
.divpad1 {
background-color:black;
font-family:Consolas;
color:white;
padding: 5px 20px 5px 20px;
}
.divblack {
background-color:black;
border-left:3px solid;
border-left-color:#0779E4;
font-family:Consolas;
color:white;
padding: 5px 20px 5px 20px;
}
.exercise {
background-color: darkslategray;
padding: 20px 20px 20px 20px;
}
.exercise-in1 {
background-color: white;
padding: 20px 20px 20px 20px;
}
.exercise-in2 {
background-color: lightgray;
border-left:3px solid;
border-left-color:#0779E4;
padding: 20px 20px 20px 20px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="site-wrap" id="home-section">
<div class="site-mobile-menu site-navbar-target">
<div class="site-mobile-menu-header">
<div class="site-mobile-menu-close mt-3">
<span class="icon-close2 js-menu-toggle"></span>
</div>
</div>
<div class="site-mobile-menu-body"></div>
</div>
<header class="site-navbar light site-navbar-target" role="banner" id="myHeader">
<div class="container">
<div class="row align-items-center position-relative">
<div class="col-3">
<div class="site-logo">
<a href="index.html"><strong>WeTeachIT</strong></a>
</div>
</div>
<div class="col-9 text-right">
<span class="d-inline-block d-lg-none"><a href="#" class=" site-menu-toggle js-menu-toggle py-5 "><span class="icon-menu h3 text-black"></span></a></span>
<nav class="site-navigation text-right ml-auto d-none d-lg-block" role="navigation" id="nav">
<ul class="site-menu main-menu js-clone-nav ml-auto ">
<li><a href="index.html" class="nav-link">Home</a></li>
<li><a href="about.html" class="nav-link">About</a></li>
<li><a href="tutorials.html" class="nav-link">Tutorials</a></li>
<li><a href="testimonials.html" class="nav-link">Testimonials</a></li>
<li><a href="contact.html" class="nav-link">Contact</a></li>
</ul>
</nav>
</div>
</div>
</div>
</header>
<div>
<div id="mySidenav" class="sidenav">
<br /><br /><br /><br />
<h5>Java Tutorial</h5>
<a id="a1">Java HOME</a>
<a id="a2">Java Intro</a>
<a id="a3">Java Get Started</a>
<a id="a4">Java Syntax</a>
<a id="a5">Java Comments</a>
<a id="a6">Java Variables</a>
<a id="a7">Java Data Types</a>
<a id="a8">Java Type Casting</a>
<a id="a9">Java Operators</a>
<a id="a10">Java strings</a>
<a id="a11">Java Math</a>
<a id="a12">Java Booleans</a>
<a id="a13">Java If...Else</a>
<a id="a14">Java Switch</a>
<a id="a15">Java While Loop</a>
<a id="a16">Java For Loop</a>
<a id="a17">Java Break/Continuue</a>
<a id="a18">Java Arrays</a>
<br />
<h5>Java Methods</h5>
<a id="a19">Java Methods</a>
<a id="a20">Java Method Parameters</a>
<a id="a21">Java Method Overloading</a>
<a id="a22">Java Scope</a>
<a id="a23">Java Recursion</a>
<br />
<h5>Java Classes</h5>
<a id="a24">Java OOP</a>
<a id="a25">Java Classes/Objects</a>
<a id="a26">Java Class Attributes</a>
<a id="a27">Java Class Methods</a>
<a id="a28">Java Constructors</a>
<a id="a29">Java Modifiers</a>
<a id="a30">Java Encapsulation</a>
<a id="a31">Java Packages/API</a>
<a id="a32">Java Inheritance</a>
<a id="a33">Java Polymorphism</a>
<a id="a34">Java Inner Classes</a>
<a id="a35">Java Abstraction</a>
<a id="a36">Java Interference</a>
<a id="a37">Java Enuns</a>
<a id="a38">Java User Input</a>
<a id="a39">Java Data</a>
<a id="a40">Java ArrayList</a>
<a id="a41">Java LinkedList</a>
<a id="a42">Java HashMap</a>
<a id="a43">Java HashSet</a>
<a id="a44">Java Iterator</a>
<a id="a45">Java Wrapper Class</a>
<a id="a46">Java Exceptions</a>
<a id="a47">Java RegEx</a>
<a id="a48">Java Threads</a>
<a id="a49">Java Lambda</a>
<br />
<h5>Java File Handling</h5>
<a id="a50">Java Files</a>
<a id="a51">Java Create/Write Files</a>
<a id="a52">Java Read Files</a>
<a id="a53">Java Delete Files</a>
<br />
<h5>Java Refrence</h5>
<a id="a54">Java Keywords</a>
<a id="a55">Java String Methods</a>
<a id="a56">Java Math Methods</a>
<br />
<h5>Java How To</h5>
<a id="a57">Add/Sub Two Numbers</a>
<a id="a58">Factorial/Reverse</a>
<br />
<h5>Java Examples</h5>
<a id="a59">Java Exercises</a>
<a id="a60">Java Quiz</a>
<br /><br /><br />
</div>
<div id="start" class="site-section-cover overlay" style="background-image: url('images/hero_bg.jpg');">
<div class="container">
<div class="row align-items-center justify-content-center">
<div class="col-lg-10 text-center">
<h1><strong>Java</strong></h1>
</div>
</div>
</div>
</div>
<div id="fst" class="main">
<br /><br />
<div class="col-lg-12">
<div class="slideshow-container">
<div class="text-center">
<img src="images/logo/java.png" style="height:215%; width:15%;" />
</div>
<div class="tutorial-item mb-4" id="div1">
<div class="heading mb-4">
<h2>Java Tutorial</h2>
</div>
<div>
<br />
<div style="background-color:lightcyan; color:black; padding: 20px 20px 20px 20px;">
<p>Java is a programming language.</p>
<p>Java is used to develop mobile apps, web apps, desktop apps, games and much more.</p>
<input type="button" class="btn btn-primary px-4" id="nxt1" value="Start learning Java now »" />
</div>
<hr />
<div>
<h2>Examples in Each Chapter</h2>
<br />
<p>Our "Show Java" tool makes it easy to learn Java, it shows both the code and the result.</p>
<div data-pym-src="https://www.jdoodle.com/embed/v0/2cUk"></div>
<p style="font-weight: bold; padding: 10px 20px 10px 20px;">Click on the "Execute" button to see how it works.</p>
</div>
<br />
<div style="background-color: #FFFACD; color:black; padding: 20px 20px 20px 20px;">
<p>We recommend reading this tutorial, in the sequence listed in the left menu.</p>
<p>Java is an object oriented language and some concepts may be new. Take breaks when needed, and go over the examples as many times as needed.</p>
</div>
<hr />
<div>
<h2>Java Exercises</h2>
<br />
<div class="exercise">
<br />
<h2 style="color:white;">Test Yourself With Exercises</h2>
<div class="exercise-in1">
<h2>Exercise:</h2>
<p>Insert the missing part of the code below to output "Hello World".</p>
<div class="exercise-in2">
<p><span style="color:#0779E4;">public class</span><span style="color:palevioletred"> MyClass</span> {<br />
<span style="color:#0779E4;"> public static void</span><span style="color:palevioletred"> main</span>(<span style="color:palevioletred">String</span>[ ] <span style="color:black">args</span>) {<br />
<input id="txt1" type="text" style="color:blue; border:none; width:80px;" /> . <input id="txt2" type="text" style="color:blue; border:none; width:50px;" /> . <input id="txt3" type="text" style="color:blue; border:none; width:90px;" /> ("<span style="color:forestgreen">Hello World</span>");<br />
}<br />
}
</p>
<br />
<div id="showDiv" style="border:2px solid; padding: 20px 20px 20px 20px;">
<h5>Correct Answer :</h5><br />
<p> <input type="text" placeholder="System" readonly="readonly" style="border:none; width:80px;" /> . <input type="text" placeholder="out" readonly="readonly" style="border:none; width:50px;" /> . <input type="text" placeholder="println" readonly="readonly" style="border:none; width:90px;" /> ("<span style="color:forestgreen">Hello World</span>");</p>
</div>
</div>
<div id="DIV1">
<br />
<input type="button" id="show" class="btn btn-primary px-4" style="height:60px; width:150px;" value="Show Answer" />
</div>
<div id="DIV2">
<br />
<input type="button" id="hide" class="btn btn-primary px-4" style="height:60px; width:150px;" value="Hide Answer" />
</div>
</div>
</div>
</div>
<hr />
<br />
<div>
<h2>Learn by Examples</h2>
<br />
<p>Learn by examples! This tutorial supplements all explanations with clarifying examples.</p>
</div>
<hr />
<br />
<div>
<h2>Java Quiz</h2>
<br />
<p>Learn by taking a quiz! This quiz will give you a signal of how much you know, or do not know, about Java.</p>
<input id="div60" type="button" class="btn btn-primary px-4"" value="Start Java Quiz" />
</div>
<hr />
<br />
<div>
<h2>Download Java</h2>
<br />
<p>Download Java from the official Java web site: <a href="https://www.oracle.com/java/">https://www.oracle.com</a></p>
</div>
<hr />
<br />
</div>
<div class="text-right">
<input type="button" class="btn btn-primary px-4" id="nxt1" value="Next →" />
</div>
<br />
<hr />
</div>
<div class="tutorial-item mb-4" id="div2">
<div class="heading mb-4">
<h2>Java Introduction</h2>
</div>
<div>
<br />
<h2>What is Java?</h2>
<br />
<p>Java is a popular programming language, created in 1995.</p>
<p>It is owned by Oracle, and more than <span style="font-weight:bold;">3 billion</span> devices run Java.</p>
<p>It is used for:</p>
<ul>
<li>Mobile applications (specially Android apps)</li>
<li>Desktop applications</li>
<li>Web applications</li>
<li>Web servers and application servers</li>
<li>Games</li>
<li>Database connection</li>
<li>And much, much more!</li>
</ul>
</div>
<hr />
<br />
<div>
<h2>Why Use Java?</h2>
<br />
<ul>
<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 is easy to learn and simple to use</li>
<li>Web servers and application servers</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>
</ul>
</div>
<hr />
<br />
<div>
<h2>Get Started</h2>
<br />
<p>This tutorial will teach you the basics of Java.</p>
<p>It is not necessary to have any prior programming experience.</p>
<br />
<input id="nxt2" type="button" style="background-color:transparent; color:#0779E4; border-color:#0779E4; height:40px; border-radius:5px 5px;" value="Get Started »"/>
</div>
<hr />
<br />
<div class="flex">
<input type="button" class="btn btn-primary px-4" id="pre2" value="← Previous" />
<input type="button" class="btn btn-primary px-4" id="nxt2" value="Next →" />
</div>
<br />
<hr />
</div>
<div class="tutorial-item mb-4" id="div3">
<div class="heading mb-4">
<h2>Java Getting Started</h2>
</div>
<div>
<br />
<h2>Java Install</h2>
<br />
<p>Some PCs might have Java already installed.</p>
<p>To check if you have Java installed on a Windows PC, search in the start bar for Java or type the following in Command Prompt (cmd.exe):</p>
<div class="divpad">
<div class="divpad1">
<p>C:\Users\<span style="font-style:italic;">Your Name</span>>java -version</p>
</div>
</div>
<br />
<p>If Java is installed, you will see something like this (depending on version):</p>
<div class="divpad">
<div class="divpad1">
<p>java version "11.0.1" 2018-10-16 LTS<br />
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)<br />
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
</p>
</div>
</div>
<br />
<p>If you do not have Java installed on your computer, you can download it for free from <a href="https://www.oracle.com/java/">oracle.com</a>.</p>
<p><span style="font-weight:bold;">Note: </span>In this tutorial, we will write Java code in a text editor.
However, it is possible to write Java in an Integrated Development Environment, such as IntelliJ IDEA, Netbeans or Eclipse, which are particularly useful when managing larger collections of Java files.</p>
</div>
<hr />
<br />
<div>
<h2>Setup for Windows</h2>
<br />
<p>To install Java on Windows:</p>
<ol type="1">
<li>Go to "System Properties" (Can be found on Control Panel > System and Security > System > Advanced System Settings)</li>
<li>Click on the "Environment variables" button under the "Advanced" tab</li>
<li>Then, select the "Path" variable in System variables and click on the "Edit" button</li>
<li>Click on the "New" button and add the path where Java is installed, followed by \bin.
By default, Java is installed in C:\Program Files\Java\jdk-11.0.1 (If nothing else was specified when you installed it).
In that case, You will have to add a new path with: <span style="font-weight:bold;">C:\Program Files\Java\jdk-11.0.1\bin</span> Then, click "OK", and save the settings</li>
<li>At last, open Command Prompt (cmd.exe) and type <span style="font-weight:bold;">java -version</span> to see if Java is running on your machine</li>
</ol>
</div>
<div>
<br />
<div>
<h3>How to install Java step-by-step with images »</h3>
</div>
<br />
<div>
<input type="button" class="divBg" id="btn1" value="Step 1 »" />
<div id="pop1" style="background-color:#DCDCDC; padding: 20px 20px 20px 20px;">
<h2>Step 1</h2>
<br />
<img src="images/system.png" style="width:800px;" />
</div>
<input type="button" class="divBg" id="btn2" value="Step 2 »" />
<div id="pop2" style="background-color:#DCDCDC; padding: 20px 20px 20px 20px;">
<h2>Step 2</h2>
<br />
<img src="images/system1.png" />
</div>
<input type="button" class="divBg" id="btn3" value="Step 3 »" />
<div id="pop3" style="background-color:#DCDCDC; padding: 20px 20px 20px 20px;">
<h2>Step 3</h2>
<br />
<img src="images/path1.png" />
</div>
<input type="button" class="divBg" id="btn4" value="Step 4 »" />
<div id="pop4" style="background-color:#DCDCDC; padding: 20px 20px 20px 20px;">
<h2>Step 4</h2>
<br />
<img src="images/path2.png" />
</div>
<input type="button" class="divBg" id="btn5" value="Step 5 »" />
<div id="pop5" style="background-color:#DCDCDC; padding: 20px 20px 20px 20px;">
<h2>Step 5</h2>
<br />
<p>Write the following in the command line (cmd.exe):</p>
<div class="divpad">
<div class="divblack"">
<p>C:\Users\<span style="font-style:italic;">Your Name</span>>java -version</p>
</div>
</div>
<br />
<p>If Java was successfully installed, you will see something like this (depending on version):</p>
<div class="divpad">
<div class="divblack"">
<p>java version "11.0.1" 2018-10-16 LTS<br />
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)<br />
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
</p>
</div>
</div>
</div>
</div>
</div>
<hr />
<br /><br /><br />
<hr />
<div>
<h2>Java Quickstart</h2>
<br />
<p>In Java, every application begins with a class name, and that class must match the filename.,br/>
Let's create our first Java file, called MyClass.java, which can be done in any text editor (like Notepad).<br />
The file should contain a "Hello World" message, which is written with the following code:
</p>
<div style="background-color:lightgray; padding:25px 25px 25px 25px;">
<h6>MyClass.java</h6>
<br />
<div data-pym-src="https://www.jdoodle.com/embed/v0/2cEL"></div>
</div>
<br />
<p>Don't worry if you don't understand the code above - we will discuss it in detail in later chapters. For now, focus on <span style="font-weight:bold;">how</span> to run the code above.</p>
<p>Save the code in Notepad as "MyClass.java". Open Command Prompt (cmd.exe), navigate to the directory where you saved your file, and type "javac MyClass.java":</p>
<div class="divpad">
<div class="divblack"">
<p>C:\Users\<span style="font-style:italic;">Your Name</span>>javac MyClass.java</p>
</div>
</div>
<br />
<p>This will compile your code. If there are no errors in the code, the command prompt will take you to the next line. Now, type "java MyClass" to run the file:</p
<br />
<div class="divpad">
<div class="divblack"">
<p>C:\Users\<span style="font-style:italic;">Your Name</span>>java MyClass</p>
</div>
</div>
<br />
<p>The output should read:</p>
<div class="divpad">
<div class="divpad1">
<p>Hello World</p>
</div>
</div>
<br />
<p><span style="font-weight:bold;">Congratulations!</span> You have written and executed your first Java program.</p>
</div>Congratulations
<br />
<div class="flex">
<input type="button" class="btn btn-primary px-4" id="pre3" value="← Previous" />
<input type="button" class="btn btn-primary px-4" id="nxt3" value="Next →" />
</div>
<br />
<hr />
</div>
<div class="tutorial-item mb-4" id="div4">
<div class="heading mb-4">
<h2>Java Syntax</h2>
</div>
<div>
<h4>Java Syntax</h4>
<br />
<p>In the previous chapter, we created a Java file called MyClass.java, and we used the following code to print "Hello World" to the screen:</p>
<div style="background-color:lightgray; padding:25px 25px 25px 25px;">
<h6>MyClass.java</h6>
<br />
<div data-pym-src="https://www.jdoodle.com/embed/v0/2cEL"></div>
</div>
<br />
<div>
<h4>Example explained</h4>
<br />
<p>Every line of code that runs in Java must be inside a <span class="spn-clr1">class</span>. In our example, we named the class <span style="font-weight:bold;">MyClass</span>
. A class should always start with an uppercase first letter.</p>
<p><span style="font-weight:bold;">Note:</span> Java is case-sensitive: "MyClass" and "myclass" has different meaning.</p>
<p>The name of the java file <span style="font-weight:bold;">must match</span> the class name. When saving the file, save it using the class name and add ".java" to the end of the filename.
To run the example above on your computer, make sure that Java is properly installed: Go to the <a id="a3" style="text-decoration:underline; cursor:pointer;">Get Started Chapter</a> for how to install Java.
The output should be:</p>
<div class="divpad">
<div class="divblack"">
<p>Hello World</p>
</div>
</div>
</div>
</div>
<hr /><br />
<div>
<h2>The main Method</h2>
<br />
<p>The <span class="spn-clr1">main( )</span> method is required and you will see it in every Java program:</p>
<div class="divpad">
<div style="background-color:white; border-left:3px solid; border-left-color:#0779E4; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p><span style="color:#0779E4;"> public static void</span><span style="color:palevioletred"> main</span><span style="color:gray">(</span><span style="color:palevioletred">String</span><span style="color:gray">[ ]</span> <span style="color:black">args</span><span style="color:gray">)</span></p>
</div>
</div>
<br />
<p>Any code inside the <span class="spn-clr1">main( )</span> method will be executed. You don't have to understand the keywords before and after main. You will get to know them bit by bit while reading this tutorial.</p>
<p>For now, just remember that every Java program has a <span class="spn-clr1">class</span> name which must match the filename, and that every program must contain the <span class="spn-clr1">main( )</span> method.</p>
</div>
<hr />
<br />
<div>
<h2>System.out.println()</h2>
<br />
<p>Inside the <span class="spn-clr1">main( )</span> method, we can use the <span class="spn-clr1">println( )</span> method to print a line of text to the screen:</p>
<div class="divpad">
<div style="background-color:white; border-left:3px solid; border-left-color:#0779E4; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p><span style="color:#0779E4;"> public static void</span><span style="color:palevioletred"> main</span><span style="color:gray">(</span><span style="color:palevioletred">String</span><span style="color:gray">[ ]</span> <span style="color:black">args</span><span style="color:gray">) {</span><br />
<span style="font-weight:bold; color:mediumvioletred;">System</span> <span style="color:gray">.</span> <span style="font-weight:bold; color:black;">out</span> <span style="color:gray">.</span>
<span style="font-weight:bold; color:mediumvioletred;">println</span> <span style="color:gray">("</span><span style="color:forestgreen; font-weight:bold;">Hello World</span><span style="color:gray">");</span><br />
<span style="color:gray">}</span>
</p>
</div>
</div>
<br />
<div style="background-color: #FFFACD; color:black; padding: 20px 20px 20px 20px;">
<p><span style="font-weight:bold;">Note:</span> The curly braces <span class="spn-clr1">{ }</span> marks the beginning and the end of a block of code.</p>
<p><span style="font-weight:bold;">Note:</span> Each code statement must end with a semicolon.</p>
</div>
</div>
<hr />
<br />
<div class="exercise">
<br />
<h2 style="color:white;">Test Yourself With Exercises</h2>
<div class="exercise-in1">
<h2>Exercise:</h2>
<p>Insert the missing part of the code below to output "Hello World".</p>
<div class="exercise-in2">
<p><span style="color:#0779E4;">public class</span><span style="color:palevioletred"> MyClass</span> {<br />
<span style="color:#0779E4;"> public static void</span><span style="color:palevioletred"> main</span>(<span style="color:palevioletred">String</span>[ ] <span style="color:black">args</span>) {<br />
<input id="txt1" type="text" style="color:blue; border:none; width:80px;" /> . <input id="txt2" type="text" style="color:blue; border:none; width:50px;" /> . <input id="txt3" type="text" style="color:blue; border:none; width:90px;" /> ("<span style="color:forestgreen">Hello World</span>");<br />
}<br />
}
</p>
<br />
<div id="showDiv1" style="border:2px solid; padding: 20px 20px 20px 20px;">
<h5>Correct Answer :</h5><br />
<p> <input type="text" placeholder="System" readonly="readonly" style="border:none; width:80px;" /> . <input type="text" placeholder="out" readonly="readonly" style="border:none; width:50px;" /> . <input type="text" placeholder="println" readonly="readonly" style="border:none; width:90px;" /> ("<span style="color:forestgreen">Hello World</span>");</p>
</div>
</div>
<div id="DIV3">
<br />
<input type="button" id="show1" class="btn btn-primary px-4" style="height:60px; width:150px;" value="Show Answer" />
</div>
<div id="DIV4">
<br />
<input type="button" id="hide1" class="btn btn-primary px-4" style="height:60px; width:150px;" value="Hide Answer" />
</div>
</div>
</div>
<hr />
<br />
<div class="flex">
<input type="button" class="btn btn-primary px-4" id="pre4" value="← Previous" />
<input type="button" class="btn btn-primary px-4" id="nxt4" value="Next →" />
</div>
<br />
<hr />
</div>
<div class="tutorial-item mb-4" id="div5">
<div class="heading mb-4">
<h2>Java Comments</h2>
</div>
<div>
<h4>Java Comments</h4>
<br />
<p>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.</p>
<p>Single-line comments start with two forward slashes (<span class="spn-clr1"> / / </span>).</p>
<p>Any text between <span class="spn-clr1"> / /</span> and the end of the line is ignored by Java (will not be executed).</p>
<p>This example uses a single-line comment before a line of code:</p>
<div class="divpad">
<h5>Example</h5>
<p></p>
<div style="background-color:white; border-left:3px solid; border-left-color:#0779E4; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p><span style="color:darkslateblue;">// This is a comment</span><br />
<span style="font-weight:bold; color:mediumvioletred;">System</span><span style="color:gray">.</span><span style="font-weight:bold; color:black;">out</span><span style="color:gray">.</span><span style="font-weight:bold; color:mediumvioletred;">println</span><span style="color:gray">("</span><span style="color:forestgreen; font-weight:bold;">Hello World</span><span style="color:gray">");</span>
</p>
</div>
</div>
<br />
<p>This example uses a single-line comment at the end of a line of code:</p>
<div class="divpad">
<h5>Example</h5>
<p></p>
<div style="background-color:white; border-left:3px solid; border-left-color:#0779E4; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p><span style="font-weight:bold; color:mediumvioletred;">System</span><span style="color:gray">.</span><span style="font-weight:bold; color:black;">out</span><span style="color:gray">.</span><span style="font-weight:bold; color:mediumvioletred;">println</span><span style="color:gray">("</span><span style="color:forestgreen; font-weight:bold;">Hello World</span><span style="color:gray">");</span> <span style="color:darkslateblue;">// This is a comment</span>
</p>
</div>
</div>
</div>
<hr />
<br />
<div>
<h2>Java Multi-line Comments</h2>
<br />
<p>Multi-line comments start with <span style="background-color:lightgray; color:palevioletred; font-family:'Segoe UI'"> /* </span> and ends with <span style="background-color:lightgray; color:palevioletred; font-family:'Segoe UI'"> */ </span>.</p>
<p>Any text between <span style="background-color:lightgray; color:palevioletred; font-family:'Segoe UI'"> /* </span> and <span style="background-color:lightgray; color:palevioletred; font-family:'Segoe UI'"> */ </span> will be ignored by Java.</p>
<p>This example uses a multi-line comment (a comment block) to explain the code:</p>
<div class="divpad">
<h5>Example</h5>
<p></p>
<div style="background-color:white; border-left:3px solid; border-left-color:#0779E4; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p><span style="color:darkslateblue; font-family:'Segoe UI'">/*</span><span style="color:darkslateblue;"> The code below will print the words Hello World<br />
to the screen, and it is amazing </span><span style="color:darkslateblue; font-family:'Segoe UI'">*/</span><br />
<span style="font-weight:bold; color:mediumvioletred;">System</span><span style="color:gray">.</span><span style="font-weight:bold; color:black;">out</span><span style="color:gray">.</span><span style="font-weight:bold; color:mediumvioletred;">println</span><span style="color:gray">("</span><span style="color:forestgreen; font-weight:bold;">Hello World</span><span style="color:gray">");</span>
</p>
</div>
</div>
</div>
<br />
<div style="background-color: #FFFACD; color:black; padding: 20px 20px 20px 20px;">
<h5>Single or multi-line comments?</h5>
<p>It is up to you which you want to use. Normally, we use <span class="spn-clr1"> / /</span> for short comments, and <span class="spn-clr1"> /* */</span> for longer.</p>
</div>
<hr />
<br />
<div class="exercise">
<br />
<h2 style="color:white;">Test Yourself With Exercises</h2>
<div class="exercise-in1">
<h2>Exercise:</h2>
<p>Insert the missing part to create two types of comments.</p>
<div class="exercise-in2">
<p>
<input id="txt1" type="text" style="color:blue; border:none; height:20px; width:20px;" /> This is a single-line comment<br />
<input id="txt2" type="text" style="color:blue; border:none; height:20px; width:20px;" /> This is a multi-line comment <input id="txt3" type="text" style="color:blue; height:20px; border:none; width:20px;" />
</p>
<br />
<div id="showDiv2" style="border:2px solid; padding: 20px 20px 20px 20px;">
<h5>Correct Answer :</h5><br />
<input id="txt1" type="text" readonly="readonly" style="color:blue; border:none; height:20px; width:20px;" placeholder=" // " /> This is a single-line comment<br />
<input id="txt2" type="text" readonly="readonly" style="color:blue; border:none; height:20px; width:20px;" placeholder=" /*" /> This is a multi-line comment <input id="txt3" readonly="readonly" type="text" style="color:blue; height:20px; border:none; width:20px;" placeholder=" */" />
</div>
</div>
<div id="DIV5">
<br />
<input type="button" id="show2" class="btn btn-primary px-4" style="height:60px; width:150px;" value="Show Answer" />
</div>
<div id="DIV6">
<br />
<input type="button" id="hide2" class="btn btn-primary px-4" style="height:60px; width:150px;" value="Hide Answer" />
</div>
</div>
</div>
<hr />
<br />
<div class="flex">
<input type="button" class="btn btn-primary px-4" id="pre5" value="← Previous" />
<input type="button" class="btn btn-primary px-4" id="nxt5" value="Next →" />
</div>
<br />
<hr />
</div>
<div class="tutorial-item mb-4" id="div6">
<div class="heading mb-4">
<h2>Java Variables</h2>
</div>
<div>
<h4>Java Variables</h4>
<br />
<p>Variables are containers for storing data values.</p>
<p>In Java, there are different types of variables, for example:</p>
<ul>
<li><span class="spn-clr1"> String </span> - stores text, such as "Hello". String values are surrounded by double quotes</li>
<li><span class="spn-clr1"> int </span> - stores text, such as "Hello". String values are surrounded by double quotes</li>
<li><span class="spn-clr1"> float </span> - stores floating point numbers, with decimals, such as 19.99 or -19.99</li>
<li><span class="spn-clr1"> char </span> - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes</li>
<li><span class="spn-clr1"> boolean </span> - stores values with two states: true or false</li>
</ul>
</div>
<hr />
<br />
<div>
<h2>Declaring (Creating) Variables</h2>
<br />
<p>To create a variable, you must specify the type and assign it a value:</p>
<div class="divpad">
<h5>Syntax</h5>
<p></p>
<div style="background-color:white; border-left:3px solid; font-style:italic; border-left-color:#0779E4; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p>type variable = value;</p>
</div>
</div>
<br />
<p>Where type is one of Java's types (such as <span class="spn-clr1"> int </span> or <span class="spn-clr1"> String </span>), and variable is the name of the variable
(such as <span class="spnblack">x</span> or <span class="spnblack">name</span>).
The <span class="spnblack">equal sign</span> is used to assign values to the variable.</p>
<p>To create a variable that should store text, look at the following example:</p>
<div class="divpad">
<h5>Example</h5>
<p>Create a variable called <span class="spnblack">name</span> of type <span class="spn-clr1"> String </span> and assign it the value "<span class="spnblack">John</span>":</p>
<div style="background-color:white; border-left:3px solid; border-left-color:#0779E4; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p>String name = <span style="color:gray">"</span><span style="color:forestgreen;">John</span><span style="color:gray">";</span><br />
<span style="color:mediumvioletred;">System</span><span style="color:gray">.</span><span style="color:black;">out</span><span style="color:gray">.</span><span style="color:mediumvioletred;">println</span><span style="color:gray">(</span><span style="color:black;">name</span><span style="color:gray">);</span>
</p>
</div>
</div>
<br />
<p>To create a variable that should store a number, look at the following example:</p>
<div class="divpad">
<h5>Example</h5>
<p>Create a variable called <span class="spnblack">myNum </span> of type <span class="spn-clr1"> int </span> and assign it the value "<span class="spnblack">15</span>":</p>
<div style="background-color:white; border-left:3px solid; border-left-color:#0779E4; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p><span style="color:#0779E4;">int </span><span style="color:black;">myNum</span><span style="color:gray"> = </span><span style="color:#990000;">15</span><span style="color:gray">;</span><br />
<span style="color:mediumvioletred;">System</span><span style="color:gray">.</span><span style="color:black;">out</span><span style="color:gray">.</span><span style="color:mediumvioletred;">println</span><span style="color:gray">(</span><span style="color:black;">myNum</span><span style="color:gray">);</span>
</p>
</div>
</div>
<br />
<p>You can also declare a variable without assigning the value, and assign the value later:</p>
<div class="divpad">
<h5>Example</h5>
<p></p>
<div style="background-color:white; border-left:3px solid; border-left-color:#0779E4; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p><span style="color:#0779E4;">int </span><span style="color:black;">myNum</span><span style="color:gray">;</span><br />
<span style="color:black;">myNum</span><span style="color:gray"> = </span><span style="color:#990000;">15</span><span style="color:gray">;</span><br />
<span style="color:mediumvioletred;">System</span><span style="color:gray">.</span><span style="color:black;">out</span><span style="color:gray">.</span><span style="color:mediumvioletred;">println</span><span style="color:gray">(</span><span style="color:black;">myNum</span><span style="color:gray">);</span>
</p>
</div>
</div>
<br />
<p>Note that if you assign a new value to an existing variable, it will overwrite the previous value:</p>
<div class="divpad">
<h5>Example</h5>
<p>Change the value of <span class="spn-clr1"> myNum </span> from <span class="spn-clr1"> 15 </span> to <span class="spn-clr1"> 20 </span>:</p>
<div style="background-color:white; border-left:3px solid; border-left-color:#0779E4; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p><span style="color:#0779E4;">int </span><span style="color:black;">myNum</span><span style="color:gray"> = </span><span style="color:#990000;">15</span><span style="color:gray">;</span><br />
<span style="color:black;">myNum</span><span style="color:gray"> = </span><span style="color:#990000;">20</span><span style="color:gray">;</span> <span style="color:darkslateblue;">// This is a comment</span><br />
<span style="color:mediumvioletred;">System</span><span style="color:gray">.</span><span style="color:black;">out</span><span style="color:gray">.</span><span style="color:mediumvioletred;">println</span><span style="color:gray">(</span><span style="color:black;">myNum</span><span style="color:gray">);</span>
</p>
</div>
</div>
</div>
<hr />
<br />
<div>
<h4>Final Variables</h4>
<br />
<p>However, you can add the <span class="spn-clr1"> final </span> keyword if you don't want others (or yourself) to overwrite existing values (this will declare the variable as "final" or "constant", which means unchangeable and read-only):</p>
<div style="background-color:#ffe6ff; padding: 20px 20px 20px 20px;">
<h5>Example</h5>
<p></p>
<div style="background-color:white; border-left:3px solid; border-left-color:red; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p><span style="color:#0779E4;">final int </span><span style="color:black;">myNum</span><span style="color:gray"> = </span><span style="color:#990000;">15</span><span style="color:gray">;</span><br />
<span style="color:black;">myNum</span><span style="color:gray"> = </span><span style="color:#990000;">20</span><span style="color:gray">;</span> <span style="color:darkslateblue;">// will generate an error: cannot assign a value to a final variable</span>
</p>
</div>
</div>
</div>
<hr />
<br />
<div>
<h2>Other Types</h2>
<br />
<p>A demonstration of how to declare variables of other types:</p>
<div class="divpad">
<h5>Example</h5>
<p></p>
<div style="background-color:white; border-left:3px solid; border-left-color:#0779E4; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p><span style="color:#0779E4;">int </span><span style="color:black;">myNum</span><span style="color:gray"> = </span><span style="color:#990000;">5</span><span style="color:gray">;</span><br />
<span style="color:#0779E4;">float </span><span style="color:black;">myFloatNum</span><span style="color:gray"> = </span><span style="color:#990000;">5.99f</span><span style="color:gray">;</span><br />
<span style="color:#0779E4;">char </span><span style="color:black;">myLetter</span><span style="color:gray"> = </span><span style="color:forestgreen;">'D'</span><span style="color:gray">;</span><br />
<span style="color:#0779E4;">boolean </span><span style="color:black;">myBool</span><span style="color:gray"> = </span><span style="color:#990000;">true</span><span style="color:gray">;</span><br />
<span style="color:mediumvioletred;">String </span><span style="color:black;">myText</span><span style="color:gray">.</span><span style="color:forestgreen;">"Hello"</span><span style="color:gray">;</span>
</p>
</div>
</div>
</div>
<br />
<div style="background-color: #FFFACD; color:black; padding: 20px 20px 20px 20px;">
<p>You will learn more about <a id="a7" style="text-decoration:underline; cursor:pointer;">data types</a> in the next chapter.</p>
</div>
<hr />
<br /><br /><br />
<hr />
<div>
<h2>Display Variables</h2>
<p>The <span style="color:mediumvioletred;"> println() </span>method is often used to display variables.</p>
<p>To combine both text and a variable, use the <span style="color:mediumvioletred; font-family:'Segoe UI'"> + </span> method is often used to display variablcharacter:</p>
<div class="divpad">
<h5>Example</h5>
<p></p>
<div style="background-color:white; border-left:3px solid; border-left-color:#0779E4; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p>
<span style="color:mediumvioletred;">String </span><span style="color:black;">name</span><span style="color:gray">.</span><span style="color:forestgreen;">"John"</span><span style="color:gray">;</span><br />
<span style="color:mediumvioletred;">System</span><span style="color:gray">.</span><span style="color:black;">out</span><span style="color:gray">.</span><span style="color:mediumvioletred;">println</span><span style="color:gray">("</span>
<span style="color:forestgreen;">Hello </span><span style="color:gray">" + </span><span style="color:black;">name</span><span style="color:gray">);</span>
</p>
</div>
</div>
<br />
<p>You can also use the <span style="color:mediumvioletred; font-family:'Segoe UI'"> + </span> character to add a variable to another variable:</p>
<div style="background-color:lightgray; padding:25px 25px 25px 25px;">
<h5>Example</h5>
<br />
<div data-pym-src="https://www.jdoodle.com/embed/v0/2cPL"></div>
</div>
<br />
<p>For numeric values, the <span style="color:mediumvioletred; font-family:'Segoe UI'"> + </span> character works as a mathematical operator (notice that we use <span style="color:mediumvioletred; font-family:'Segoe UI'"> int </span> (integer) variables here):</p>
<div class="divpad">
<h5>Example</h5>
<p></p>
<div style="background-color:white; border-left:3px solid; border-left-color:#0779E4; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p><span style="color:#0779E4;">int </span><span style="color:black;">x</span><span style="color:gray"> = </span><span style="color:#990000;">5</span><span style="color:gray">;</span><br />
<span style="color:#0779E4;">int </span><span style="color:black;">y</span><span style="color:gray"> = </span><span style="color:#990000;">6</span><span style="color:gray">;</span><br />
<span style="color:mediumvioletred;">System</span><span style="color:gray">.</span><span style="color:black;">out</span><span style="color:gray">.</span><span style="color:mediumvioletred;">println</span><span style="color:gray">(</span>
<span style="color:black;">x</span><span style="color:gray"> + </span><span style="color:black;">y</span><span style="color:gray">);</span> <span style="color:darkslateblue;">// Print the value of x + y</span>
</p>
</div>
</div>
<p>From the example above, you can expect:</p>
<ul>
<li>x stores the value 5</li>
<li>y stores the value 6</li>
<li>Then we use the <span style="color:mediumvioletred;"> println() </span> method to display the value of x + y, which is <span style="color:black;"> 11 </span></li>
</ul>
</div>
<hr />
<br />
<div>
<h2>Declare Many Variables</h2>
<br />
<p>To declare more than one variable of the <span style="color:black;"> same type </span>, use a comma-separated list:</p>
<div class="divpad">
<h5>Example</h5>
<p></p>
<div style="background-color:white; border-left:3px solid; border-left-color:#0779E4; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p><span style="color:#0779E4;">int </span><span style="color:black;">x</span><span style="color:gray"> = </span><span style="color:#990000;">5</span><span style="color:gray">, </span>
<span style="color:black;">y</span><span style="color:gray"> = </span><span style="color:#990000;">6</span><span style="color:gray">, </span>
<span style="color:black;">z</span><span style="color:gray"> = </span><span style="color:#990000;">50</span><span style="color:gray">;</span><br />
<span style="color:mediumvioletred;">System</span><span style="color:gray">.</span><span style="color:black;">out</span><span style="color:gray">.</span><span style="color:mediumvioletred;">println</span><span style="color:gray">(</span>
<span style="color:black;">x</span><span style="color:gray"> + </span><span style="color:black;">y</span><span style="color:gray"> + </span><span style="color:black;">z</span><span style="color:gray">);</span>
</p>
</div>
</div>
</div>
<hr />
<br />
<div>
<h2>Java Identifiers</h2>
<p>All Java <span style="color:black;"> variables </span> must be <span style="color:black;"> identified </span> with <span style="color:black;"> unique names </span>.</p>
<p>These unique names are called<span style="color:black;"> identifiers </span>.</p>
<p>Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume).</p>
<p><span style="color:black;">Note:</span> It is recommended to use descriptive names in order to create understandable and maintainable code:</p>
<div class="divpad">
<h5>Example</h5>
<p></p>
<div style="background-color:white; border-left:3px solid; border-left-color:#0779E4; font-family:Consolas; padding: 5px 20px 5px 20px;">
<p><span style="color:darkslateblue;">// Good</span><br />
<span style="color:#0779E4;">int </span><span style="color:black;">minutesPerHour</span><span style="color:gray"> = </span><span style="color:#990000;">60</span><span style="color:gray">;</span><br />
<span style="color:darkslateblue;">// OK, but not so easy to understand what m actually is</span><br />
<span style="color:#0779E4;">int </span><span style="color:black;">m</span><span style="color:gray"> = </span><span style="color:#990000;">60</span><span style="color:gray">;</span>
</p>
</div>
</div>
<br />
<p>The general rules for constructing names for variables (unique identifiers) are:</p>
<ul>
<li>Names can contain letters, digits, underscores, and dollar signs</li>
<li>Names must begin with a letter</li>
<li>Names should start with a lowercase letter and it cannot contain whitespace</li>
<li>Names can also begin with $ and _ (but we will not use it in this tutorial)</li>
<li>Names are case sensitive ("myVar" and "myvar" are different variables)</li>
<li>Reserved words (like Java keywords, such as <span style="color:mediumvioletred;"> int </span> or <span style="color:mediumvioletred;"> boolean </span>) cannot be used as names</li>
</ul>
</div>
<hr />
<br />
<div class="exercise">
<br />
<h2 style="color:white;">Test Yourself With Exercises</h2>
<div class="exercise-in1">
<h2>Exercise:</h2>
<p>Create a variable named <span style="color:mediumvioletred;"> carName </span> and assign the value <span style="color:mediumvioletred;"> Volvo </span> to it.</p>
<div class="exercise-in2">
<p>
<input id="txt1" type="text" style="color:blue; border:none; width:50px;" /> <input id="txt2" type="text" style="color:blue; border:none; width:80px;" /> <span style="color:gray"> = "</span> <input id="txt3" type="text" style="color:blue; border:none; width:50px;" /> <span style="color:gray">";</span>
</p>
<br />
<div id="showDiv3" style="border:2px solid; padding: 20px 20px 20px 20px;">
<h5>Correct Answer :</h5><br />
<input id="txt1" type="text" style="color:blue; border:none; width:50px;" placeholder="String" /> <input id="txt2" type="text" style="color:blue; border:none; width:80px;" placeholder="carName" /> <span style="color:gray"> = "</span> <input id="txt3" type="text" style="color:blue; border:none; width:50px;" placeholder="Volvo"/> <span style="color:gray">";</span>
</div>
</div>
<div id="DIV7">
<br />
<input type="button" id="show3" class="btn btn-primary px-4" style="height:60px; width:150px;" value="Show Answer" />
</div>
<div id="DIV8">
<br />
<input type="button" id="hide3" class="btn btn-primary px-4" style="height:60px; width:150px;" value="Hide Answer" />
</div>
</div>
</div>
<hr />
<br />