-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql_queries.sql
3661 lines (3434 loc) · 135 KB
/
sql_queries.sql
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
CREATE TABLE exam(
exercise TEXT NOT NULL,
answer1 TEXT NOT NULL,
answer2 TEXT NOT NULL,
answer3 TEXT NOT NULL,
answer4 TEXT NOT NULL,
answer5 TEXT NOT NULL,
answer6 TEXT NOT NULL,
answer7 TEXT NOT NULL,
answer8 TEXT NOT NULL,
answer9 TEXT NOT NULL,
answer10 TEXT NOT NULL
);
insert into exam (exercise,answer1,answer2,answer3,answer4,answer5,answer6,answer7,answer8,answer9,answer10) values ('Συμπληρώστε τα κενά σύμφωνα με τα σχόλια του κώδικα.
<br>
<figure>
<figcaption>Τελική άσκηση</figcaption>
<pre>
<code>
public class MyClass {
//δημιούργησε μια μέθοδο που να επιστρέφει αληθής ή ψευδής τιμές με μια μεταβλητή τύπου int
static <input type="text" name="answer1"> checkAge(<input type="text" name="answer2"> age){
//αν η μεταβλητή age είναι μεγαλύτερη ή ίση από 18
<input type="text" name="answer3"> (<input type="text" name="answer4"> <input type="text" name="answer5"> 18){
//θα εκτυπώνεται η ηλικία
<input type="text" name="answer6">(age);
//θα επιστρέφεται η τιμή αληθής
<input type="text" name="answer7"> true;
}
else
return false;
}
public static void main(<input type="text" name="answer8">) {
int myAge = 22;
/* καλέστε την μέθοδο checkAge και περάστε την μεταβλητή myAge
και εκχωρήστε το αποτέλεσμα σε μια άλλη μεταβλητή */
<input type="text" name="answer9"> aboveLimit = checkAge(<input type="text" name="answer10">);
}
}
</code>
</pre>
</figure>
<br>','boolean','int','if','age','>=','System.out.println','return','String[] args','boolean','myAge');
insert into exam (exercise,answer1,answer2,answer3,answer4,answer5,answer6,answer7,answer8,answer9,answer10) values ('Συμπληρώστε τα κενά σύμφωνα με τα σχόλια του κώδικα.
<br>
<figure>
<figcaption>Τελική άσκηση</figcaption>
<pre>
<code>
public class MyClass {
public static void main(String[] args) {
//δημιουργήστε έναν δισδιάστατο πίνακα με τον σωστό τύπο σύμφωνα με τις εκχωρημένες τιμές του
<input type="text" name="answer11"> myNumbers = {{1,2},{3,4}};
/* δημιουργήστε έναν βρόγχο for με σωστές δηλώσεις,
όπου να εκτελείται για το μήκος του πίνακα και να έχει βήμα 1 */
for (int i = 0; i < myNumbers.<input type="text" name="answer12">; i<input type="text" name="answer13">){
/*δημιουργήστε έναν εμφωλευμένο βρόγχο for που να τρέχει
για το μήκος του κάθε υποπίνακα */
<input type="text" name="answer14">(int j = 0; myNumbers<input type="text" name="answer15">.length; j++){
//θα εκτυπώνει την τιμή του πίνακα στο συγκεκριμένο σημείο
System.out.println(myNumbers[<input type="text" name="answer16">][<input type="text" name="answer17">])
}
}
int[] nums = {1,2,3,4,5};
//δημιουργήστε έναν βρόγχο for... each που να εκτυπώνει όλα τα στοιχεία του πίνακα nums
for (<input type="text" name="answer18"> n <input type="text" name="answer18"> nums){
<input type="text" name="answer20">(n);
}
}
}
</code>
</pre>
</figure>
<br>','int[][]','length','++','for','[i]','i','j','int',':','System.out.println');
create table statistics (
u_email TEXT NOT NULL PRIMARY KEY,
score1 TEXT NOT NULL,
score2 TEXT NOT NULL,
scoref TEXT NOT NULL,
FOREIGN KEY(u_email) references users(u_email)
);
create table users(
u_name TEXT NOT NULL,
u_email TEXT NOT NULL PRIMARY KEY,
u_pass TEXT NOT NULL,
chapter TEXT NOT NULL,
page TEXT NOT NULL,
test TEXT NOT NULL,
cur_chapter TEXT NOT NULL,
cur_page TEXT NOT NULL
);
create table mooc_info (
id INTEGER NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
n_chapters TEXT NOT NULL
);
insert into mooc_info values(1,'Java Tutorial','19');
CREATE TABLE weekly(
u_email TEXT NOT NULL,
weekofyear int NOT NULL,
counter int NOT NULL
);
insert into weekly (u_email,weekofyear,counter) values ('pete@mail.com',25,'1');
CREATE TABLE monthly(
u_email TEXT NOT NULL,
counter1 int NOT NULL,
counter2 int NOT NULL,
counter3 int NOT NULL,
counter4 int NOT NULL,
counter5 int NOT NULL,
counter6 int NOT NULL,
counter7 int NOT NULL,
counter8 int NOT NULL,
counter9 int NOT NULL,
counter10 int NOT NULL,
counter11 int NOT NULL,
counter12 int NOT NULL
);
insert into monthly (u_email,counter1,counter2,counter3,counter4,counter5,counter6,counter7,counter8,counter9,counter10,counter11,counter12) values ('pete@mail.com','0','0','0','0','0','1','0','0','0','0','0','0');
CREATE TABLE chapter8(
pages TEXT NOT NULL,
page1 TEXT NOT NULL,
page2 TEXT NOT NULL,
page3 TEXT NOT NULL
);
insert into chapter8 (pages,page1,page2,page3) values('3','<h3><b>Κεφάλαιο 8 - Operators</b></h3>
<h4><i>Java Operators</i></h4>
Οι operators χρησιμοποιούνται για την εκτέλεση εργασιών σε μεταβλητές και τιμές.
<br>
Η τιμή ονομάζεται operand, ενώ η λειτουργία (που πρέπει να πραγματοποιηθεί μεταξύ των δύο τελεστών) ορίζεται από έναν operator:
<br>
Στο παρακάτω παράδειγμα, οι αριθμοί 100 και 50 είναι operands και το σύμβολο + είναι operator:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
int x = 100 + 50;
</code>
</pre>
</figure><br>
Παρόλο που ο operator ‘+’ χρησιμοποιείται συχνά για να προσθέσει δύο τιμές, όπως στο παραπάνω παράδειγμα, μπορεί επίσης να χρησιμοποιηθεί για να προσθέσει μαζί μια μεταβλητή και μία τιμή ή μια μεταβλητή και μια άλλη μεταβλητή:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
int sum1 = 100 + 50; // 150 (100 + 50)
int sum2 = sum1 + 250; // 400 (150 + 250)
int sum3 = sum2 + sum2; // 800 (400 + 400)
</code>
</pre>
</figure><br>
Η Java διαιρεί τους operators στις ακόλουθες ομάδες:<ul>
<li>Αριθμητικοί operators</li>
<li>Εκχωρητικοί operators</li>
<li>Συγκριτικοί operators</li>
<li>Λογικοί operators</li>
<li>Bitwise operators</li>
</ul><br>
<small>σελίδα 1</small>','<h3><b>Κεφάλαιο 8 - Operators</b></h3>
<h4><i>Αριθμητικοί operators</i></h4>
Οι αριθμητικοί operators χρησιμοποιούνται για την εκτέλεση κοινών μαθηματικών πράξεων.
<table>
<tr>
<th>Σύμβολο χειριστή</th>
<th>Περιγραφή</th>
<th>Παράδειγμα</th>
</tr>
<tr>
<td>+</td>
<td>Πρόσθεση</td>
<td>Προσθέτει δύο τιμές x + y</td>
</tr>
<tr>
<td>-</td>
<td>Αφαίρεση</td>
<td>Αφαιρεί μία τιμή από άλλη x - y</td>
</tr>
<tr>
<td>*</td>
<td>Πολλαπλασιασμός</td>
<td>πολλαπλασιάζει δύο τιμές x * y</td>
</tr>
<tr>
<td>/</td>
<td>Διαίρεση</td>
<td>Διαιρεί μία τιμή από άλλη x / y</td>
</tr>
<tr>
<td>%</td>
<td>Modulus</td>
<td>Επιστρέφει το υπόλοιπο διαίρεσης x% y</td>
</tr>
<tr>
<td>++</td>
<td>Increment</td>
<td>Αυξάνει την τιμή μιας μεταβλητής κατά 1 ++ x</td>
</tr>
<tr>
<td>--</td>
<td>Decrement</td>
<td>Μειώνει την τιμή μιας μεταβλητής κατά 1 – x</td>
</tr>
</table>
<h5><i>Java Assignment Operators</i></h5>
Οι τελεστές εκχώρησης χρησιμοποιούνται για την εκχώρηση τιμών σε μεταβλητές.
Στο παρακάτω παράδειγμα, χρησιμοποιούμε τον τελεστή εκχώρησης (=) για να εκχωρήσουμε την τιμή 10 σε μια μεταβλητή που ονομάζεται x:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
int x = 10;
</code>
</pre>
</figure><br>
Ο χειριστής εκχώρησης πρόσθεσης (+ =) προσθέτει μια τιμή σε μια μεταβλητή:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
int x = 10;
x += 5;
</code>
</pre>
</figure><br>
Λίστα όλων των χειριστών εκχώρησης:
<table>
<tr>
<th>Operator</th>
<th>Παράδειγμα</th>
<th>Όμοιο με</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><<= x</td>
<td><<= 3</td>
<td>x = x << 3</td>
</tr>
</table>
<small>σελίδα 2</small>','<h3><b>Κεφάλαιο 8 - Operators</b></h3>
<h4><i>Java Operators σύγκρισης</i></h4>
Οι συγκριτικοί χειριστές χρησιμοποιούνται για να συγκρίνουν δύο τιμές:
<table>
<tr>
<th>Operator</th>
<th>Όνομα</th>
<th>Παράδειγμα</th>
</tr>
<tr>
<td>==</td>
<td>Ίσο με το</td>
<td>x == y</td>
</tr>
<tr>
<td>! =</td>
<td>Δεν είναι ίσο</td>
<td>x ! = Y</td>
</tr>
<tr>
<td>></td>
<td>Μεγαλύτερο από</td>
<td>x > y</td>
</tr>
<tr>
<td><</td>
<td>Μικρότερο από</td>
<td> x < y</td>
</tr>
<tr>
<td>> =</td>
<td>Μεγαλύτερο από ή ίσο με το</td>
<td>x> = y</td>
</tr>
<tr>
<td>< =</td>
<td>Μικρότερο από ή ίσο με το</td>
<td>x <= y</td>
</tr>
</table>
<h5><i>Λογικοί Java Operators</i></h5>
Οι λογικοί τελεστές χρησιμοποιούνται για τον προσδιορισμό της λογικής μεταξύ μεταβλητών ή τιμών:
<table>
<tr>
<th>Operator</th>
<th>Όνομα</th>
<th>Περιγραφή</th>
<th>Παράδειγμα</th>
</tr>
<tr>
<td>&&</td>
<td>Logical και</td>
<td>Επιστρέφει true αν και οι δύο δηλώσεις είναι αληθείς</td>
<td>x <5 && x <10</td>
</tr>
<tr>
<td>||</td>
<td>Logical ή</td>
<td>Επιστρέφει true αν μία από τις δηλώσεις είναι αληθής</td>
<td>x <5 || x <4</td>
</tr>
<tr>
<td>!</td>
<td>Logical δεν</td>
<td>Αντίστροφο από το αποτέλεσμα, επιστρέφει ψευδές αν το αποτέλεσμα είναι αληθές!</td>
<td>!(X <5 && x <10)</td>
</tr>
</table>
<small>σελίδα 3</small>');
CREATE TABLE chapter1(
pages TEXT NOT NULL,
page1 TEXT NOT NULL
);
insert into chapter1 (pages,page1) values('1','<h3><b>Κεφάλαιο 1 -Εισαγωγή στην Γλώσσα Προγραμματισμού JAVA</b></h3>
<h4><i>Τι είναι η Java;</i></h4>
Η Java είναι μια δημοφιλής γλώσσα προγραμματισμού, που δημιουργήθηκε το 1995. Η Java είναι μια γενικού σκοπού γλώσσα προγραμματισμού που είναι βασισμένη σε κλάσεις, αντικειμενοστραφής και έχει σχεδιαστεί έτσι ώστε να έχει όσο το δυνατόν λιγότερες εξαρτήσεις κατά την εκτέλεση. Δηλαδή οι προγραμματιστές μπορούν να τρέξουν κώδικα Java σε όλες τις πλατφόρμες που την υποστηρίζουν χωρίς να χρειάζεται να ξανά-συνταχθεί.<br>Χρησιμοποιείται για:<ul>
<li>Κινητές εφαρμογές (ειδικά εφαρμογές Android)</li>
<li>Εφαρμογές επιφάνειας εργασίας</li>
<li>Εφαρμογές Web</li>
<li>Διακομιστές Web και διακομιστές εφαρμογών</li>
<li>Παιχνίδια</li><li>Σύνδεση βάσης δεδομένων</li>
<li>Και πολλά ακόμη!</li>
</ul>Γιατί να χρησιμοποιήσετε τη Java;<ul>
<li>Η Java λειτουργεί σε διαφορετικές πλατφόρμες (Windows, Mac, Linux, Raspberry Pi κ.λπ.)</li>
<li>Είναι μια από τις πιο δημοφιλείς γλώσσες προγραμματισμού στον κόσμο</li>
<li>Είναι εύκολο να την μάθει κάποιος και να την χρησιμοποιήσει</li>
<li>Είναι ανοιχτού κώδικα και δωρεάν</li><li>Είναι ασφαλής, γρήγορη και ισχυρή</li>
<li>Έχει τεράστια υποστήριξη από την κοινότητα (δεκάδες εκατομμύρια προγραμματιστών)</li></ul>
<br><small>σελίδα 1</small>');
CREATE TABLE chapter2(
pages TEXT NOT NULL,
page1 TEXT NOT NULL,
page2 TEXT NOT NULL
);
insert into chapter2 (pages,page1,page2) values('2','<h3><b>Κεφάλαιο 2 - Γρήγορη εκκίνηση με την Java</b></h3>
<h4><i>Εισαγωγή στην Java</i></h4>
Σε περίπτωση που δεν είστε σίγουροι αν έχετε στο μηχάνημά σας Java, τρέξτε στην Γραμμή εντολών την εξής εντολή “java -version” για να δείτε ποια έκδοση της Java έχετε (Η εντολή λειτουργεί και σε Windows και Linux). Διαφορετικά κατεβάστε την από την σελίδα https://www.java.com .
Μετά από αυτό σας προτείνουμε να κατεβάσετε μια εφαρμογή integrated development environment (IDE) για την Java, όπου μπορείτε εύκολα να γράψετε και να εκτελέσετε κώδικα Java. Από τα πιο διάσημα εργαλεία προγραμματισμού τέτοιου τύπου είναι το Eclipse, IntelliJ IDEA, NetBeans, Codenvy και Visual Studio Code.
<br>
<small>σελίδα 1</small>','<h3><b>Κεφάλαιο 2 - Γρήγορη εκκίνηση με την Java</b></h3>
<h4><i>Εισαγωγή στον προγραμματισμό με Java</i></h4>
Στην Java, κάθε εφαρμογή αρχίζει με ένα όνομα κλάσης και αυτή η κλάση πρέπει να ταιριάζει με το όνομα αρχείου.
<br>
Ας δημιουργήσουμε το πρώτο αρχείο Java που ονομάζεται MyClass.java. Το αρχείο πρέπει να περιέχει ένα μήνυμα "Hello World", το οποίο είναι γραμμένο με τον ακόλουθο κώδικα:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
public class MyClass {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
</code>
</pre>
</figure>
<br>
Μην ανησυχείτε αν δεν καταλαβαίνετε τον παραπάνω κώδικα - θα τον αναλύσουμε λεπτομερώς σε επόμενα κεφάλαια.
<br>
<small>σελίδα 2</small>');
CREATE TABLE chapter3(
pages TEXT NOT NULL,
page1 TEXT NOT NULL,
page2 TEXT NOT NULL
);
insert into chapter3 (pages,page1,page2) values('2','<h3><b>Κεφάλαιο 3 – Σύνταξη στην Java</b></h3>
<h4><i>Σύνταξη</i></h4>
Στο προηγούμενο κεφάλαιο δημιουργήσαμε ένα αρχείο Java που ονομάζεται MyClass.java και χρησιμοποιήσαμε τον ακόλουθο κώδικα για να εκτυπώσετε την οθόνη "Hello World" στην οθόνη:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
public class MyClass {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
</code>
</pre>
</figure>
<br>
<h4><i>Επεξήγηση του παραδείγματος</i></h4>
Κάθε γραμμή κώδικα που τρέχει σε Java πρέπει να είναι μέσα σε μια τάξη. Στο παράδειγμά μας, ονομάσαμε την κλάση MyClass. Μια κλάση πρέπει πάντα να ξεκινά με ένα πρώτο κεφαλαίο γράμμα.
<br>
Σημείωση: Η Java κάνει διάκριση πεζών-κεφαλαίων: "MyClass" και "myclass" έχουν διαφορετική σημασία.
<br>
Το όνομα του αρχείου java πρέπει να ταιριάζει με το όνομα της κλάσης. Κατά την αποθήκευση του αρχείου, αποθηκεύστε το χρησιμοποιώντας το όνομα της κλάσης και προσθέστε το ".java" στο τέλος του ονόματος αρχείου. Για να εκτελέσετε το παραπάνω παράδειγμα στον υπολογιστή σας, βεβαιωθείτε ότι η Java έχει εγκατασταθεί σωστά: Μεταβείτε στο κεφάλαιο Γρήγορη Εκκίνηση για τον τρόπο εγκατάστασης της Java. Η έξοδος πρέπει να είναι: Hello World
<br>
<small>σελίδα 1</small>','<h3><b>Κεφάλαιο 3 – Σύνταξη στην Java</b></h3>
<h4><i>Η κύρια μέθοδος</i></h4>
Απαιτείται η κύρια μέθοδος main() και θα την δείτε σε κάθε πρόγραμμα Java:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
public static void main(String[] args)
</code>
</pre>
</figure>
<br>
Θα εκτελεστεί οποιοσδήποτε κώδικας μέσα στη μέθοδο main (). Δεν χρειάζεται να καταλάβετε τις λέξεις-κλειδιά πριν και μετά την κύρια ακόμη.
<br>
Προς το παρόν, να θυμάστε ότι κάθε πρόγραμμα Java έχει ένα όνομα κλάσης το οποίο πρέπει να ταιριάζει με το όνομα αρχείου και ότι κάθε πρόγραμμα πρέπει να περιέχει τη μέθοδο main ().
<br>
<h4><i>Εντολή System.out.println ()</i></h4>
Μέσα στη μέθοδο main (), μπορούμε να χρησιμοποιήσουμε τη μέθοδο println () για να εκτυπώσουμε μια γραμμή κειμένου στην οθόνη:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
public static void main(String[] args) {
System.out.println("Hello World");
}
</code>
</pre>
</figure>
<br>
<small>σελίδα 2</small>');
CREATE TABLE chapter4(
pages TEXT NOT NULL,
page1 TEXT NOT NULL,
page2 TEXT NOT NULL
);
insert into chapter4 (pages,page1,page2) values('2','<h3><b>Κεφάλαιο 4 - Σχολιασμός στην Java</b></h3>
<h4><i>Σχολιασμός στην Java</i></h4>
Τα σχόλια μπορούν να χρησιμοποιηθούν για να εξηγήσουν τον κώδικα Java και να το κάνουν πιο ευανάγνωστο. Μπορούν επίσης να χρησιμοποιηθούν για την αποτροπή εκτέλεσης κατά τον έλεγχο εναλλακτικού κώδικα.
<br>
Τα σχόλια μιας γραμμής ξεκινούν με δύο εμπρόσθια πτερύγια (//).
<br>
Κάθε κείμενο μεταξύ // και το τέλος της γραμμής αγνοείται από την Java (δεν θα εκτελεστεί).
<br>
Αυτό το παράδειγμα χρησιμοποιεί ένα σχόλιο μιας γραμμής πριν από μια γραμμή κώδικα:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
// This is a comment
System.out.println("Hello World");
</code>
</pre>
</figure>
<br>
Αυτό το παράδειγμα χρησιμοποιεί ένα σχόλιο μιας γραμμής στο τέλος μιας γραμμής κώδικα:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
System.out.println("Hello World"); // This is a comment
</code>
</pre>
</figure>
<br>
<small>σελίδα 1</small>','<h3><b>Κεφάλαιο 4 - Σχολιασμός στην Java</b></h3>
<h4><i>Σχολιασμός πολλών γραμμών στην Java</i></h4>
Τα σχόλια πολλών γραμμών αρχίζουν με /* και τελειώνουν με */.
<br>
Οποιοδήποτε κείμενο μεταξύ /* και */ θα αγνοηθεί από την Java
<br>
Αυτό το παράδειγμα χρησιμοποιεί ένα σχόλιο πολλών γραμμών (ένα μπλοκ σχολίων) για να εξηγήσει τον κώδικα:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
/* The code below will print the words Hello World
to the screen, and it is amazing */
System.out.println("Hello World");
</code>
</pre>
</figure>
<br>
<small>σελίδα 2</small>');
CREATE TABLE chapter5(
pages TEXT NOT NULL,
page1 TEXT NOT NULL,
page2 TEXT NOT NULL,
page3 TEXT NOT NULL,
page4 TEXT NOT NULL
);
insert into chapter5 (pages,page1,page2,page3,page4) values('4','<h3><b>Κεφάλαιο 5 - Μεταβλητές Java</b></h3>
<h4><i>Οι μεταβλητές είναι δοχεία για την αποθήκευση δεδομένων</i></h4>
Στην Java, υπάρχουν διάφοροι τύποι μεταβλητών, για παράδειγμα:<br><ul>
<li>String - αποθηκεύει κείμενο, όπως "Hello". Οι τιμές των συμβολοσειρών περιβάλλονται από διπλά εισαγωγικά</li>
<li>int - αποθηκεύει ακέραιους (ολόκληρους αριθμούς), χωρίς δεκαδικά ψηφία, όπως 123 ή -123</li>
<li>float - αποθηκεύει αριθμούς κινητού σημείου, με δεκαδικά ψηφία, όπως 19.99 ή -19.99</li>
<li>char - αποθηκεύει μεμονωμένους χαρακτήρες, όπως ΄a΄ ή ΄B΄. Οι τιμές Char περιβάλλονται από μοναδικά εισαγωγικά</li>
<li>boolean - αποθηκεύει τιμές με δύο καταστάσεις: true ή false</li>
<br>
<small>σελίδα 1</small>','<h3><b>Κεφάλαιο 5 - Μεταβλητές Java</b></h3>
<h4><i>Δηλώσεις (Δημιουργία) μεταβλητών</i></h4>
Για να δημιουργήσετε μια μεταβλητή, πρέπει να καθορίσετε τον τύπο και να τον εκχωρήσετε μια τιμή:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
type variable = value;
</code>
</pre>
</figure>
<br>
Όπου ο τύπος είναι ένας από τους τύπους της Java (όπως int ή String), και μεταβλητή είναι το όνομα της μεταβλητής (όπως x ή όνομα). Το ίση σημάδι χρησιμοποιείται για την εκχώρηση τιμών στη μεταβλητή.
Για να δημιουργήσετε μια μεταβλητή που θα πρέπει να αποθηκεύει κείμενο, ανατρέξτε στο ακόλουθο παράδειγμα:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
String name = "John";
System.out.println(name);
</code>
</pre>
</figure>
<br>
Για να δημιουργήσετε μια μεταβλητή που θα πρέπει να αποθηκεύει έναν αριθμό, εξετάστε το ακόλουθο παράδειγμα:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
int myNum = 15;
System.out.println(myNum);
</code>
</pre>
</figure>
<br>
Μπορείτε επίσης να δηλώσετε μια μεταβλητή χωρίς να εκχωρήσετε την τιμή και να εκχωρήσετε την τιμή αργότερα :
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
int myNum;
myNum = 15;
System.out.println(myNum);
</code>
</pre>
</figure>
<br>
Μια επίδειξη για τον τρόπο δήλωσης μεταβλητών άλλων τύπων:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
int myNum = 5;
float myFloatNum = 5.99f;
char myLetter = ΄D΄;
boolean myBool = true;
String myText = "Hello";
</code>
</pre>
</figure>
<br>
<small>σελίδα 2</small>','<h3><b>Κεφάλαιο 5 - Μεταβλητές Java</b></h3>
<h4><i>Προβολή μεταβλητών</i></h4>
Η μέθοδος println () χρησιμοποιείται συχνά για την εμφάνιση μεταβλητών.
<br>
Για να συνδυάσετε κείμενο και μεταβλητή, χρησιμοποιήστε το χαρακτήρα +:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
String name = "John";
System.out.println("Hello " + name);
</code>
</pre>
</figure>
<br>
Μπορείτε επίσης να χρησιμοποιήσετε το χαρακτήρα + για να προσθέσετε μια μεταβλητή σε μια άλλη μεταβλητή:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
String firstName = "John ";
String lastName = "Doe";
String fullName = firstName + lastName;
System.out.println(fullName);
</code>
</pre>
</figure>
<br>
Για αριθμητικές τιμές, ο χαρακτήρας + λειτουργεί ως μαθηματικός χειριστής (παρατηρήστε ότι εδώ χρησιμοποιούμε μεταβλητές int (integer)):
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
int x = 5;
int y = 6;
System.out.println(x + y); // Print the value of x + y
</code>
</pre>
</figure>
<br>
Από το παραπάνω παράδειγμα, μπορείτε να περιμένετε:<br><ul>
<li>x αποθηκεύει την τιμή 5</li>
<li>y αποθηκεύει την τιμή 6</li>
<li>Στη συνέχεια, χρησιμοποιούμε τη μέθοδο println () για να εμφανιστεί η τιμή x + y, η οποία είναι 11</li></ul>
<br>
<h4><i>Δηλώστε πολλές μεταβλητές</i></h4>
<br>
Για να δηλώσετε περισσότερες από μία μεταβλητές του ίδιου τύπου, χρησιμοποιήστε μια λίστα χωρισμένη με κόμματα:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
int x = 5, y = 6, z = 50;
System.out.println(x + y + z);
</code>
</pre>
</figure>
<br>
<small>σελίδα 3</small>','<h3><b>Κεφάλαιο 5 - Μεταβλητές Java</b></h3>
<h4><i>Αναγνωριστές Java</i></h4>
Όλες οι μεταβλητές Java πρέπει να αναγνωρίζονται με μοναδικά ονόματα.
Αυτά τα μοναδικά ονόματα ονομάζονται αναγνωριστικά.
<br>
Τα αναγνωριστικά μπορούν να είναι σύντομα ονόματα (όπως το x και y) ή περισσότερα περιγραφικά ονόματα (ηλικία, άθροισμα, σύνολοVolume).
<br>
Οι γενικοί κανόνες για την κατασκευή ονομάτων για μεταβλητές (μοναδικά αναγνωριστικά) είναι:<ul>
<li>Τα ονόματα μπορούν να περιέχουν γράμματα, ψηφία, υπογράμμιση και δολάριο</li>
<li>Τα ονόματα θα πρέπει να αρχίζουν με ένα γράμμα</li>
<li>Τα ονόματα μπορούν επίσης να αρχίσουν με $ και _ (αλλά δεν θα τα χρησιμοποιήσουμε σε αυτό το σεμινάριο)</li>
<li>Τα ονόματα είναι ευαίσθητα σε πεζά ("myVar" και "myvar" είναι διαφορετικές μεταβλητές)</li>
<li>Τα ονόματα πρέπει να ξεκινούν με πεζά γράμματα και δεν μπορούν να περιέχουν κενό διάστημα</li>
<li>Οι δεσμευμένες λέξεις (όπως λέξεις-κλειδιά Java, όπως int ή String) δεν μπορούν να χρησιμοποιηθούν ως ονόματα</li>
</ul><br>
<small>σελίδα 4</small>');
CREATE TABLE chapter6(
pages TEXT NOT NULL,
page1 TEXT NOT NULL,
page2 TEXT NOT NULL,
page3 TEXT NOT NULL,
page4 TEXT NOT NULL,
page5 TEXT NOT NULL
);
insert into chapter6 (pages,page1,page2,page3,page4,page5) values('5','<h3><b>Κεφάλαιο 6 - Τύποι δεδομένων Java</b></h3>
<h4><i>Τύποι δεδομένων</i></h4>
Όπως εξηγείται στο προηγούμενο κεφάλαιο, μια μεταβλητή Java πρέπει να είναι ένας συγκεκριμένος τύπος δεδομένων:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
int myNum = 5; // Integer (whole number)
float myFloatNum = 5.99f; // Floating point number
char myLetter = ΄D΄; // Character
boolean myBool = true; // Boolean
String myText = "Hello"; // String
</code>
</pre>
</figure>
<br>
Οι τύποι δεδομένων χωρίζονται σε δύο ομάδες:<ul><br>
<li>Πρωταρχικοί τύποι δεδομένων - περιλαμβάνουν byte, short, int, long, float, double, boolean και char</li>
<li>Μη πρωταρχικοί τύποι δεδομένων - όπως String, Arrays and Classes (θα μάθετε περισσότερα για αυτά σε ένα επόμενο κεφάλαιο)</li>
</ul><br>
<small>σελίδα 1</small>','<h3><b>Κεφάλαιο 6 - Τύποι δεδομένων Java</b></h3>
<h4><i>Πρωταρχικοί τύποι δεδομένων</i></h4>
Ένας πρωταρχικός τύπος δεδομένων καθορίζει το μέγεθος και τον τύπο των μεταβλητών τιμών και δεν έχει άλλες μεθόδους.
<br>
Υπάρχουν οκτώ πρωταρχικοί τύποι δεδομένων στη Java:
<table>
<tr>
<th>Τύπος δεδομένων</th>
<th>Μέγεθος</th>
<th>Περιγραφή</th>
</tr>
<tr>
<td>byte 1 </td>
<td>byte</td>
<td>Αποθηκεύει ολόκληρους αριθμούς από -128 έως 127</td>
</tr>
<tr>
<td>short</td>
<td>2 bytes</td>
<td>Αποθηκεύει ολόκληρους αριθμούς από -32.768 έως 32.767</td>
</tr>
<tr>
<td>int</td>
<td>4 byte</td>
<td>Αποθηκεύει ολόκληρους αριθμούς από -2,147,483,648 έως 2,147,483,647</td>
</tr>
<tr>
<td>long</td>
<td>8 bytes</td>
<td>Αποθηκεύει ολόκληρους αριθμούς από -9,223,372,036,854,775,808 έως 9,223,372,036,854,775,807</td>
</tr>
<tr>
<td>float</td>
<td>4 bytes</td>
<td>Αποθηκεύει κλασικούς αριθμούς από 3.4e-038 έως 3.4e + 038. Επαρκής για αποθήκευση 6 έως 7 δεκαδικών ψηφίων</td>
</tr>
<tr>
<td>double</td>
<td>8 bytes</td>
<td>Αποθηκεύει κλασικούς αριθμούς από 1.7e-308 έως 1.7e + 038. Αρκεί για την αποθήκευση 15 δεκαδικών ψηφίων</td>
</tr>
<tr>
<td>boolean</td>
<td>1 bit</td>
<td>Αποθηκεύει αληθείς ή ψευδείς τιμές</td>
</tr>
<tr>
<td>char</td>
<td>2 bytes</td>
<td>Αποθηκεύει ένα μοναδικό χαρακτήρα / γράμμα ή τιμές ASCII</td>
</tr>
</table>
<br>
<h4><i>Αριθμοί</i></h4>
Οι πρωταρχικοί τύποι αριθμών χωρίζονται σε δύο ομάδες:<ul>
<li>Οι τύποι ακεραίων αποθηκεύουν ολόκληρους αριθμούς, θετικούς ή αρνητικούς (όπως 123 ή -456), χωρίς δεκαδικά ψηφία. Οι έγκυροι τύποι είναι byte, short, int και long. Ο τύπος που πρέπει να χρησιμοποιήσετε εξαρτάται από την αριθμητική τιμή.</li>
<li>Οι τύποι κινητής υποδιαστολής αντιπροσωπεύουν αριθμούς με κλασματικό τμήμα, που περιέχουν ένα ή περισσότερα δεκαδικά ψηφία. Υπάρχουν δύο τύποι: float και double.</li>
<ul><br>
<small>σελίδα 2</small>','<h3><b>Κεφάλαιο 6 - Τύποι δεδομένων Java</b></h3>
<h4><i>Ακέραιοι τύποι</i></h4>
<h5><i>Byte</i></h5>
Ο τύπος δεδομένων byte μπορεί να αποθηκεύσει ολόκληρους αριθμούς από -128 έως 127. Αυτό μπορεί να χρησιμοποιηθεί αντί για int ή άλλους τύπους ακέραιων αριθμών για εξοικονόμηση μνήμης όταν είστε βέβαιοι ότι η τιμή θα είναι εντός -128 και 127:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
byte myNum = 100;
System.out.println(myNum);
</code>
</pre>
</figure>
<br>
<h5><i>Short</i></h5>
Ο short τύπος δεδομένων μπορεί να αποθηκεύσει ολόκληρους αριθμούς από -32768 έως 32767:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
short myNum = 5000;
System.out.println(myNum);
</code>
</pre>
</figure>
<br>
<h5><i>Int</i></h5>
Ο τύπος δεδομένων int μπορεί να αποθηκεύσει ολόκληρους αριθμούς από -2147483648 έως 2147483647. Γενικά, και στο tutorial μας, ο τύπος δεδομένων int είναι ο προτιμώμενος τύπος δεδομένων όταν δημιουργούμε μεταβλητές με αριθμητική τιμή.
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
int myNum = 100000;
System.out.println(myNum);
</code>
</pre>
</figure>
<br>
<h5><i>Long</i></h5>
Ο long τύπος δεδομένων μπορεί να αποθηκεύσει ολόκληρους αριθμούς από -9223372036854775808 έως 9223372036854775807. Αυτό χρησιμοποιείται όταν το int δεν είναι αρκετά μεγάλο για να αποθηκεύσει την τιμή. Σημειώστε ότι πρέπει να τερματίσετε την τιμή με ένα "L":
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
long myNum = 15000000000L;
System.out.println(myNum);
</code>
</pre>
</figure>
<br><small>σελίδα 3</small>','<h3><b>Κεφάλαιο 6 - Τύποι δεδομένων Java</b></h3>
<h4><i>Τύποι κινητής υποδιαστολής </i></h4>
Θα πρέπει να χρησιμοποιείτε τύπο κινητής υποδιαστολής κάθε φορά που χρειάζεστε έναν αριθμό με δεκαδικό αριθμό, όπως το 9.99 ή το 3.14515.
<h5><i>Float</i></h5>
Ο τύπος δεδομένων float μπορεί να αποθηκεύσει κλασματικούς αριθμούς από 3.4e-038 σε 3.4e + 038. Σημειώστε ότι πρέπει να τερματίσετε την τιμή με ένα "f":
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
float myNum = 5.75f;
System.out.println(myNum);
</code>
</pre>
</figure><br>
<h5><i>Double</i></h5>
Ο double τύπος δεδομένων μπορεί να αποθηκεύσει κλασικούς αριθμούς από 1.7e-308 έως 1.7e + 038. Σημειώστε ότι πρέπει να τερματίσετε την τιμή με "d":
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
double myNum = 19.99d;
System.out.println(myNum);
</code>
</pre>
</figure><br>
<h5><i>Επιστημονικοί αριθμοί</i></h5>
Ένας αριθμός κινητής υποδιαστολής μπορεί επίσης να είναι ένας επιστημονικός αριθμός με ένα "e" για να δηλώσει τη δύναμη του 10:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
float f1 = 35e3f;
double d1 = 12E4d;
System.out.println(f1);
System.out.println(d1);
</code>
</pre>
</figure><br>
<small>σελίδα 4</small>','<h3><b>Κεφάλαιο 6 - Τύποι δεδομένων Java</b></h3>
<h4><i>Τύποι κινητής υποδιαστολής </i></h4>
<h5><i>Boolean</i></h5>
Ένας τύπος δεδομένων boolean δηλώνεται με τη λέξη-κλειδί boolean και μπορεί να λάβει μόνο τις αξίες true ή false:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
boolean isJavaFun = true;
boolean isFishTasty = false;
System.out.println(isJavaFun); // Outputs true
System.out.println(isFishTasty); // Outputs false
</code>
</pre>
</figure><br>
Οι τιμές Boolean χρησιμοποιούνται κυρίως για δοκιμές υπό όρους, τις οποίες θα μάθετε περισσότερα σε ένα επόμενο κεφάλαιο.
<h5><i>Χαρακτήρες</i></h5>
Ο τύπος δεδομένων char χρησιμοποιείται για την αποθήκευση ενός μόνο χαρακτήρα. Ο χαρακτήρας πρέπει να περιβάλλεται από μεμονωμένα εισαγωγικά, όπως ΄Α΄ ή ΄c΄:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
char myGrade = ΄B΄;
System.out.println(myGrade);
</code>
</pre>
</figure><br>
Εναλλακτικά, μπορείτε να χρησιμοποιήσετε τις τιμές ASCII για να εμφανίσετε ορισμένους χαρακτήρες:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
char a = 65, b = 66, c = 67;
System.out.println(a);
System.out.println(b);
System.out.println(c);
</code>
</pre>
</figure><br>
<h5><i>Strings</i></h5>
Ο τύπος δεδομένων String χρησιμοποιείται για την αποθήκευση μιας σειράς χαρακτήρων (κειμένου). Οι τιμές των συμβολοσειρών πρέπει να περιβάλλεται από διπλά εισαγωγικά:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
String greeting = "Hello World";
System.out.println(greeting);
</code>
</pre>
</figure><br>
<small>σελίδα 5</small>');
CREATE TABLE chapter7(
pages TEXT NOT NULL,
page1 TEXT NOT NULL
);
insert into chapter7 (pages,page1) values('1','<h3><b>Κεφάλαιο 7 - Java Type Casting</b></h3>
<h4><i>Java Type Casting</i></h4>
Η type casting είναι όταν εκχωρείτε μια τιμή ενός πρωτόγονου τύπου δεδομένων σε άλλο τύπο.
<br>
Στην Java, υπάρχουν δύο τύποι type casting:
<br>
Διευρυμένο casting (αυτόματα) - μετατροπή ενός μικρότερου τύπου σε μεγαλύτερο μέγεθος τύπου
byte -> short -> char -> int -> long -> float -> διπλό
<br>
Περιορισμένο casting (χειροκίνητα) - μετατροπή μεγαλύτερου τύπου σε μικρότερο μέγεθος
διπλό -> float -> long -> int -> char -> short -> byte
<br>
<h5><i>Διευρυμένο casting</i></h5>
Το Διευρυμένο casting πραγματοποιείται αυτόματα όταν μεταβιβάζεται ένας τύπος μικρότερου μεγέθους σε έναν τύπο μεγαλύτερου μεγέθους:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
public class MyClass {
public static void main(String[] args) {
int myInt = 9;
double myDouble = myInt; // Automatic casting: int to double
System.out.println(myInt); // Outputs 9
System.out.println(myDouble); // Outputs 9.0
}
}
</code>
</pre>
</figure><br>
<h5><i>Περιορισμένο casting</i></h5>
Το περιορισμένο casting πρέπει να γίνει χειροκίνητα τοποθετώντας τον τύπο σε παρενθέσεις μπροστά από την τιμή:
<br>
<figure>
<figcaption>Παράδειγμα</figcaption>
<pre>
<code>
public class MyClass {