-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFundamentals.java
628 lines (625 loc) · 29.9 KB
/
Fundamentals.java
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
/**
* @NAME- APOORV SHARAT
* CLASS- 10 C
* ROLL NO. 11
*/
import java.util.*;
public class Fundamentals
{
/**
* function to display menu
*/
private void displayMenu()
{
System.out.println("@@@@@@@@ ** ** @@ @@ ** ** @@@@@@@@@ ** ** @@@@@@@@@@ ** ** @@@@@@@@@@@@ ********** @@ ***********");
System.out.println("@@@@@@@@ ** ** @@ @@ @@ ** ** @@ @@ ** ** ** ** @@@@@@@@@@ ** ** ** @@@@@@@@@@@@ ********** @@ ***********");
System.out.println("@@ ** ** @@ @@ @@ ** ** @@ @@ ** ** ** ** @@ ** ** ** @@ ** ** @@ ** ");
System.out.println("@@@@@@@@ ** ** @@ @@ @@ ** ** @@ @@ ** ** ** ** @@@@@@@@@@ ** ** ** @@ ** ** @@ ***********");
System.out.println("@@@@@@@@ ** ** @@ @@ @@ ** ** @@*****@@* ** ** ** ** @@@@@@@@@@ ** ** ** @@ **@@@@@@**@ @@ ***********");
System.out.println("@@ ** ** @@ @@ @@ ** ** @@*****@@* ** ** ** ** @@ ** ** ** @@ **@@@@@@**@ @@ **");
System.out.println("@@ ** ** @@ @@ @@ ** ** @@ @@ ** ** ** ** @@@@@@@@@@ ** ** ** @@ ** ** @@@@@@@@@ ***********");
System.out.println("@@ ******* @@ @@ ** ** @@ @@ ** ** ** @@@@@@@@@@ ** ** @@ ** ** @@@@@@@@@ ***********");
System.out.println();
System.out.println();
System.out.println("====================================================================================================================================================================================");
System.out.println("====================================================================================================================================================================================");
System.out.println();
System.out.println();
System.out.println();
System.out.println("MENU menu MENU menu menu menu MENU MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU menu menu menu MENU menu MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU MENU menu MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU MENU menu MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU menu menu menu MENU menu MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU menu menu menu MENU menu MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU MENU menu MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU MENU menu MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU menu menu menu MENU menu MENU MENU menu menu MENU");
System.out.println("MENU menu MENU MENU menu menu menu MENU menu MENU menu menu MENU");
System.out.println();
System.out.println();
System.out.println();
System.out.println("1.Advantages of java");
System.out.println("2.Types of java program");
System.out.println("3.Character set of java");
System.out.println("4.Tokens");
System.out.println("5.Statements");
System.out.println("6.keywords");
System.out.println("7.Identifiers");
System.out.println("8.Literals/constants");
System.out.println("9.operators");
System.out.println("10.Punctuators/seperators");
System.out.println("11.compiler");
System.out.println("12.Interpreter");
System.out.println("13.Rules for sellecting an identifier");
System.out.println("14. Types of constants");
System.out.println("15. Variables");
System.out.println("16. Format of declaring variable");
System.out.println("17. Meaning of variable declaration");
System.out.println("18. variable initialization(static initialization of a variable)");
System.out.println("19. Dynamic initialization of a variable");
System.out.println("20. Data types");
System.out.println("21. Classification of data types");
System.out.println("22. Primitive data types");
System.out.println("23. Comments in Java");
System.out.println("24. Output Statements");
System.out.println("25. Use of + operator in java");
System.out.println("26. Outline of writing a simple java program");
System.out.println("27. Expressions");
System.out.println("28. Arithmatic operators");
System.out.println("0. BACK TO MAIN MENU");
System.out.println();
System.out.println("ENTER YOUR CHOICE (0-28)");
}
/**
* function to display advantages of java
*/
private void advantages()
{
System.out.println(" ADVANTAGES OF JAVA ARE");
System.out.println();
System.out.println("i. Java is an object oriented programming language");
System.out.println("ii. Java programs are platform indipendent (Java programs are portable, WORA");
System.out.println("WORA- Write one run anywhere");
System.out.println("Java programs are platform indipendent means same java program can be executed on divices with different processors or operating systems");
}
/**
* function to display types of java program
*/
private void types()
{
System.out.println("Types of java program are");
System.out.println();
System.out.println("i. Java Application");
System.out.println("A java application is a general java program made to be executed on a stand-alone computer");
System.out.println("eg. A program to find sum of two numbers");
System.out.println("ii. Java Applet");
System.out.println("An applet is a java program that can be included in a webpage. When we open a webpage that contains an applet, the web bowser exicutes");
}
/**
* function to display character set of java
*/
private void character_set()
{
System.out.println(" Character set of java");
System.out.println();
System.out.println("Character set of java means a group of characters that can be used in a java program. It includes:");
System.out.println("i. Capital Letters (A-Z)");
System.out.println("ii. Small Letters (a-z)");
System.out.println("iii. Digits (0-9)");
System.out.println("iv. Special Characters/ Symbols (+,-,/,*,&,<,>....)");
}
/**
* function to display defination of tokens
*/
private void tokens()
{
System.out.println(" Tokens");
System.out.println();
System.out.println("- Tokens are the smallest individual of a java program.");
System.out.println("- A token may contain one or more characters fropm the characterset of java");
System.out.println("- Keywords, identifiers, Literals, Operators and seperators are various tokens of java");
}
/**
* function to display details of statements
*/
private void statements()
{
System.out.println(" Statements");
System.out.println();
System.out.println("- A statement is the smallest unit of exicution in a java program.");
System.out.println("- A statement in java may contain one or more tokens and is terminated by a semi column(;)");
System.out.println("- A ststement that contains only a semi column is known as a null statement");
System.out.println();
System.out.println();
System.out.println(" BLOCK OR COMPOUND STATEMENT");
System.out.println("One or more statements enclosed within a pair of curly brackets( {} ) is known as block or compound statement");
System.out.println("eg.");
System.out.println("{");
System.out.println(" int a=5;");
System.out.println(" int b=10;");
System.out.println(" int s=a+b");
System.out.println("}");
}
/**
* function to display details of keywords
*/
private void keywords()
{
System.out.println(" KEYWORDS/ RESERVED WORDS");
System.out.println();
System.out.println("Keywords are the reserved words that conveys a special meaning to the compiler. In java keywords are always written in small letters");
System.out.println("eg:");
System.out.println(" abstract");
System.out.println(" char");
System.out.println(" for");
System.out.println(" int");
System.out.println(" goto etc..");
}
/**
* function to display details of identifiers
*/
private void identifiers()
{
System.out.println(" IDENTIFIERS");
System.out.println();
System.out.println("Identifiers are the names given by the programmers to various programming elements.");
System.out.println("eg. Variable name is an identifier");
}
/**
* function to display details of constants
*/
private void literals()
{
System.out.println(" LITERALS/ CONSTANTS");
System.out.println();
System.out.println("Constants are the tokens whose values don't change during the execution of a program.");
System.out.println("eg. 100");
System.out.println(" 'a' ");
System.out.println(" 3.14 etc..");
}
/**
* function to display details of operators
*/
private void operators()
{
System.out.println(" OPERATORS");
System.out.println();
System.out.println("Operators are the tokens used in an operation to represent an expression");
System.out.println("eg. +,-,*,/,<,>....etc");
}
/**
* function to display details of punctuators/seperators
*/
private void seperators()
{
System.out.println(" PUNCTUATORS/ SEPERATORS");
System.out.println();
System.out.println("Seperators are the tokens used to seperate various programming elements.");
System.out.println("eg. , , ;, ., (), {}, []");
}
/**
* function to display details of compiler
*/
private void compiler()
{
System.out.println(" COMPILER");
System.out.println();
System.out.println(" A compiler is a system software that converts high lever language program to machine language as a whole");
}
/**
* function to display interpreter
*/
private void interpreter()
{
System.out.println(" INTERPRETER");
System.out.println();
System.out.println("Interpreter is a system software that translates high level language program into machine language line by line.");
}
/**
* function to display rules for sellecting identifier
*/
private void rules()
{
System.out.println(" RULES FOR SELLECTING AN IDENTIFIER");
System.out.println();
System.out.println("i. Keywords can not be used as an identifiers");
System.out.println("ii. An identifier may contain capital letters, small letters, digits and only two special characters ($ _)");
System.out.println("iii. An identifier should not start with a digit ");
}
/**
* function to display types of constants
*/
private void constant_types()
{
System.out.println(" TYPES OF CONSTANTS");
System.out.println();
System.out.println("i. Integer constant");
System.out.println("- Integer constant reffers to a sequence of digits without a decimal point.");
System.out.println("- It may contain an optional positive or negative sign and a sequence of digits");
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println("ii. Floating point/ real numeric constant");
System.out.println("They can be represented in two forms:");
System.out.println("* Decimal Notation- the decimal notation have 3 parts: the integer part, the decimal point and the fractional part.");
System.out.println();
System.out.println();
System.out.println("* scientific notation- the scientific or exponential notation is used to represent numbers and the following format");
System.out.println(" mantisa e/E exponent");
System.out.println("mantisa is either real number or an integer");
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println("iii. Character constant");
System.out.println("A single character enclosed within single quotes is called character constant");
System.out.println("eg: 'A' , 'S' ....etc ");
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println("iv. String constant");
System.out.println("One or more character enclosed within double quotes is called string constant");
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println("v. Boolean constant");
System.out.println("the boolean constant can have only two types of values i.e. true or false.");
System.out.println("- true and false are reserved words of java language.");
}
/**
* function to display details of variables
*/
private void variables()
{
System.out.println(" VARIABLES");
System.out.println();
System.out.println();
System.out.println("- Variables are the programming element whose value may change during the exicution of a program");
System.out.println("- a Variable is used in a program to represent a constant");
System.out.println("- Constants are stored in computers memory and the variable variable name identifies the memory location where a constant is stored");
System.out.println("- We can say a variable is a named memory location");
System.out.println("- We can use a variable in a program only after declaring it");
}
/**
* function to display format of variable declaration
*/
private void format_varDeclr()
{
System.out.println(" FORMAT OF VARIABLE DECLARATION");
System.out.println();
System.out.println(" DataType variable1[, variable2, ........., variable_n];");
System.out.println(" eg: int a;");
System.out.println(" int a,b,c;");
}
/**
* function to dispaly meaning of variable declaration
*/
private void variable_declaration()
{
System.out.println(" MEANING OF VARIABLE DECLARATION");
System.out.println();
System.out.println();
System.out.println(" Associating a variable name with a data type is known as variable declaration");
}
/**
* function to display details of variable initialization
* (Static initialization of a variable)
*/
private void var_initialization()
{
System.out.println(" VARIABLE INITIALIZATION (STATICINITIALIZATION OF A VARIABLE");
System.out.println();
System.out.println("- Storing a value in a variable along with variable declaration is known as variable initialization or static initialization of a variable");
System.out.println("- In static initialization of a variable its initial value is known during compilation");
System.out.println(" eg: int a=10;");
}
/**
* function to display details of dinamic initialization of a variable
*/
private void dynamic_initialization()
{
System.out.println(" DYNAMIC INITIALIZATION OF A VARIABLE");
System.out.println();
System.out.println("- Initializing a variable with an expression is called dynamic initialization.");
System.out.println("- In dynamic initialization, the initial value of the variable is known during the execution of the program.");
}
/**
* function to dispalay details of data types
*/
private void data_types()
{
System.out.println(" DATA TYPES");
System.out.println();
System.out.println("In a variable declaration statement, datatype is used to give the following information:");
System.out.println(" i. type of constant");
System.out.println(" ii. range of values that can be stored in variable");
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
}
/**
* function to display classification of datatypes
*/
private void classification_dataTypes()
{
System.out.println(" DATA TYPE");
System.out.println(" |");
System.out.println(" ________________________________________________________________");
System.out.println(" | |");
System.out.println(" primitive datatype non primitive datatype");
System.out.println(" | |");
System.out.println(" ___________________________ |");
System.out.println(" | | |- class");
System.out.println("numeric non-numeric---- |-array");
System.out.println(" | | |- interface");
System.out.println(" _______________ |_____________________");
System.out.println(" | | | |");
System.out.println(" integer floating point | |");
System.out.println(" | | ______________________________");
System.out.println(" |-byte |-float | |");
System.out.println(" |-short |-double character datatype logical");
System.out.println(" |-int | |");
System.out.println(" |-long char boolean");
}
/**
* function to display details of primitive datatypes
*/
private void primitive()
{
System.out.println(" PRIMITIVE DATATYPES");
System.out.println("- Primitive datatype or fundamental datatypes are predefined datatypes provided by a programming language to store data in variable");
System.out.println("- Java has 8 different primitive datatypes, all of which represent different kinds of values a variable can accept in a program.");
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println(" DIFFERENT PRIMITIVE DATATYPES");
System.out.println();
System.out.println("i. Integers");
System.out.println("* long");
System.out.println("* int");
System.out.println("* short");
System.out.println("* byte");
System.out.println();
System.out.println();
System.out.println("ii. Floating-point types");
System.out.println("* float");
System.out.println("* double");
System.out.println();
System.out.println();
System.out.println("iii. Character Datatypes");
System.out.println("* char");
System.out.println();
System.out.println();
System.out.println("iv. Boolean datatype");
System.out.println("* boolean");
}
/**
* function to display comments in java
*/
private void comments()
{
System.out.println(" COMMENTS IN JAVA");
System.out.println();
System.out.println("A comment is a non executable statement used in a program to give some information about the program.");
System.out.println();
System.out.println();
System.out.println("There are three types of comment statements in java");
System.out.println("i. Single line comment- it is a common statement that consists of only 1 line");
System.out.println(" - it starts with a symboll //");
System.out.println(" - example: // i am doing project");
System.out.println();
System.out.println("ii. Multiline comment- It is a comment statement that contains one or more lines.");
System.out.println(" - it starts with /* and ends with */");
System.out.println();
System.out.println("Documentation comment- It is a comment statement that may contains multiple lines and is useful for preparing a program documentation.");
System.out.println(" - It starts with /** and ends with */");
}
/**
* function to display output statements in java
*/
private void output()
{
System.out.println(" OUTPUT STATEMENTS IN JAVA");
System.out.println();
System.out.println();
System.out.println("There are two types of options to dispalay outputs in java program:");
System.out.println("i. System.out.print");
System.out.println("ii. System.out.println");
System.out.println();
System.out.println();
System.out.println();
System.out.println("i. System.out.print-");
System.out.println("The cursor will remain on the same line after displaying the output.");
System.out.println();
System.out.println("ii. System.out.println-");
System.out.println("The cursor will move to the next line after displaying the output.");
}
/**
* function to display use of + operator in java
*/
private void use_of_plus()
{
System.out.println(" USE OF + OPERATOR IN JAVA");
System.out.println();
System.out.println();
System.out.println("i. If both the operands are numbers then this performs arethmatic addition");
System.out.println("eg: 5+10 = 15");
System.out.println();
System.out.println("If atleast one of the operands is a string constant then this operator performs string concatenation");
System.out.println("(String concatenation means joining two operands to form a string constant)");
System.out.println();
}
/**
* function to display outline of writing a simple jav program
*/
private void outline()
{
System.out.println(" OUTLINE OF WRITING A SIMPLE JAVA PROGRAM");
System.out.println();
System.out.println();
System.out.println("class ClassName");
System.out.println("{");
System.out.println(" //include a comment");
System.out.println(" void functionName(Parameter list)");
System.out.println(" {");
System.out.println(" statement 1;");
System.out.println(" statement 2;");
System.out.println(" ::");
System.out.println(" ::");
System.out.println(" statement n;");
System.out.println(" }");
System.out.println("}");
}
/**
* function to display details of expression
*/
private void expression()
{
System.out.println(" EXPRESSIONS");
System.out.println();
System.out.println();
System.out.println("An expression is a valid combination of operators and opearands.");
System.out.println("for eg: a+b");
System.out.println("In the above expression, '+' is operator and 'a' & 'b' are the operands.");
}
/**
* function to display details of arithmatic operators
*/
private void arithmatic()
{
System.out.println(" ARITHMATIC OPERATORS");
System.out.println();
System.out.println();
System.out.println("There are 5 arithmatic operators injava that are used to perform various arithmatic forms.");
System.out.println("They are:");
System.out.println();
System.out.println();
System.out.println(" SIGN NAME/USE");
System.out.println(" + Addition");
System.out.println(" - Substraction");
System.out.println(" * Multiplication");
System.out.println(" / Division (div)");
System.out.println(" % Modulus or modulo or mod");
}
/**
* MAIN MENU
*/
public void main()
{
Scanner sc=new Scanner(System.in);
int ch;
do
{
displayMenu();
ch=sc.nextInt();
switch(ch)
{
case 1: System.out.println('\f');
advantages();
break;
case 2: System.out.println('\f');
types();
break;
case 3: System.out.println('\f');
character_set();
break;
case 4: System.out.println('\f');
tokens();
break;
case 5: System.out.println('\f');
statements();
break;
case 6: System.out.println('\f');
keywords();
break;
case 7: System.out.println('\f');
identifiers();
break;
case 8: System.out.println('\f');
literals();
break;
case 9: System.out.println('\f');
operators();
break;
case 10: System.out.println('\f');
seperators();
break;
case 11: System.out.println('\f');
compiler();
break;
case 12: System.out.println('\f');
interpreter();
break;
case 13: System.out.println('\f');
rules();
break;
case 14: System.out.println('\f');
constant_types();
break;
case 15: System.out.println('\f');
variables();
break;
case 16: System.out.println('\f');
format_varDeclr();
break;
case 17: System.out.println('\f');
variable_declaration();
break;
case 18: System.out.println('\f');
var_initialization();
break;
case 19: System.out.println('\f');
dynamic_initialization();
break;
case 20: System.out.println('\f');
data_types();
break;
case 21: System.out.println('\f');
classification_dataTypes();
break;
case 22: System.out.println('\f');
primitive();
break;
case 23: System.out.println('\f');
comments();
break;
case 24: System.out.println('\f');
output();
break;
case 25: System.out.println('\f');
use_of_plus();
break;
case 26: System.out.println('\f');
outline();
break;
case 27: System.out.println('\f');
expression();
break;
case 28: System.out.println('\f');
arithmatic();
break;
case 0: System.out.println('\f');
System.out.println("Going back to main menu");
Main m1=new Main();
m1.main_fn();
break;
default: System.out.println("Invalid choice");
}
if(ch!=0)
{
System.out.println();
System.out.println("Press any key to continue....");
sc.skip("\n");
String tmp=sc.nextLine();
}
}while(ch!=0);
}
}