javaintro.md
@@ -1,4 +1,4 @@ | |||
1 | - | # VERRY Basic Introduction to Java Programming | |
1 | + | # VERRRRRRY Basic Introduction to Java Programming | |
2 | 2 | ||
3 | 3 | ## 1. Basic Program Structure | |
4 | 4 | Every Java program starts with a class, and the main method is the entry point of the program. Here's a simple example: |
javaintro.md
@@ -1,4 +1,4 @@ | |||
1 | - | # Introduction to Java Programming | |
1 | + | # VERRY Basic Introduction to Java Programming | |
2 | 2 | ||
3 | 3 | ## 1. Basic Program Structure | |
4 | 4 | Every Java program starts with a class, and the main method is the entry point of the program. Here's a simple example: |
javaintro.md
@@ -118,6 +118,9 @@ public class ArrayExample { | |||
118 | 118 | Methods help you organize code into reusable blocks: | |
119 | 119 | ||
120 | 120 | ```java | |
121 | + | // | |
122 | + | // If you put all this into a filename `Methods.java` | |
123 | + | // | |
121 | 124 | public class Methods { | |
122 | 125 | public static void main(String[] args) { | |
123 | 126 | // Calling methods | |
@@ -140,7 +143,8 @@ public class Methods { | |||
140 | 143 | ||
141 | 144 | These examples cover the fundamental concepts you'll need to start programming in Java. Remember to: | |
142 | 145 | - Save each class in a separate file with the same name as the class | |
143 | - | - Compile your code using `javac FileName.java` | |
144 | - | - Run your program using `java FileName` | |
146 | + | - So to try `Methods.java` | |
147 | + | - Compile your code using `javac Methods.java` | |
148 | + | - Run your program using `java Methods` | |
145 | 149 | ||
146 | 150 | Practice with these examples and modify them to experiment with different values and behaviors. This hands-on experience will help solidify your understanding of Java basics. |
javaintro.md(файл создан)
@@ -0,0 +1,146 @@ | |||
1 | + | # Introduction to Java Programming | |
2 | + | ||
3 | + | ## 1. Basic Program Structure | |
4 | + | Every Java program starts with a class, and the main method is the entry point of the program. Here's a simple example: | |
5 | + | ||
6 | + | ```java | |
7 | + | public class HelloWorld { | |
8 | + | public static void main(String[] args) { | |
9 | + | System.out.println("Hello, World!"); | |
10 | + | } | |
11 | + | } | |
12 | + | ``` | |
13 | + | ||
14 | + | This structure is fundamental to Java: | |
15 | + | - `public class`: Declares a class that can be accessed from anywhere | |
16 | + | - `static void main(String[] args)`: The main method that runs when you execute the program | |
17 | + | - `System.out.println()`: Prints text to the console | |
18 | + | ||
19 | + | ## 2. Variables and Data Types | |
20 | + | Java is a strongly-typed language, meaning you must declare the type of each variable. Here are the basic data types: | |
21 | + | ||
22 | + | ```java | |
23 | + | public class Variables { | |
24 | + | public static void main(String[] args) { | |
25 | + | // Numeric types | |
26 | + | int age = 25; // Whole numbers | |
27 | + | double price = 19.99; // Decimal numbers | |
28 | + | ||
29 | + | // Text | |
30 | + | char grade = 'A'; // Single character | |
31 | + | String name = "John Doe"; // Text string | |
32 | + | ||
33 | + | // Boolean | |
34 | + | boolean isStudent = true; // true or false | |
35 | + | ||
36 | + | // Printing variables | |
37 | + | System.out.println("Name: " + name); | |
38 | + | System.out.println("Age: " + age); | |
39 | + | System.out.println("Grade: " + grade); | |
40 | + | } | |
41 | + | } | |
42 | + | ``` | |
43 | + | ||
44 | + | ## 3. Control Flow Statements | |
45 | + | Control flow statements help you make decisions and repeat actions in your code. | |
46 | + | ||
47 | + | ### If-Else Statements | |
48 | + | ```java | |
49 | + | public class ControlFlow { | |
50 | + | public static void main(String[] args) { | |
51 | + | int score = 85; | |
52 | + | ||
53 | + | if (score >= 90) { | |
54 | + | System.out.println("Excellent!"); | |
55 | + | } else if (score >= 80) { | |
56 | + | System.out.println("Good job!"); | |
57 | + | } else { | |
58 | + | System.out.println("Keep practicing!"); | |
59 | + | } | |
60 | + | } | |
61 | + | } | |
62 | + | ``` | |
63 | + | ||
64 | + | ### Loops | |
65 | + | ```java | |
66 | + | public class Loops { | |
67 | + | public static void main(String[] args) { | |
68 | + | // For loop | |
69 | + | System.out.println("Counting with for loop:"); | |
70 | + | for (int i = 1; i <= 5; i++) { | |
71 | + | System.out.println("Count: " + i); | |
72 | + | } | |
73 | + | ||
74 | + | // While loop | |
75 | + | System.out.println("\nCounting with while loop:"); | |
76 | + | int count = 1; | |
77 | + | while (count <= 5) { | |
78 | + | System.out.println("Count: " + count); | |
79 | + | count++; | |
80 | + | } | |
81 | + | } | |
82 | + | } | |
83 | + | ``` | |
84 | + | ||
85 | + | ## 4. Arrays | |
86 | + | Arrays allow you to store multiple values of the same type: | |
87 | + | ||
88 | + | ```java | |
89 | + | public class ArrayExample { | |
90 | + | public static void main(String[] args) { | |
91 | + | // Declaring and initializing an array | |
92 | + | int[] numbers = {1, 2, 3, 4, 5}; | |
93 | + | ||
94 | + | // Accessing array elements | |
95 | + | System.out.println("First number: " + numbers[0]); | |
96 | + | ||
97 | + | // Array iteration | |
98 | + | System.out.println("\nAll numbers:"); | |
99 | + | for (int number : numbers) { | |
100 | + | System.out.println(number); | |
101 | + | } | |
102 | + | ||
103 | + | // Creating an array of strings | |
104 | + | String[] fruits = new String[3]; | |
105 | + | fruits[0] = "Apple"; | |
106 | + | fruits[1] = "Banana"; | |
107 | + | fruits[2] = "Orange"; | |
108 | + | ||
109 | + | System.out.println("\nFruits:"); | |
110 | + | for (String fruit : fruits) { | |
111 | + | System.out.println(fruit); | |
112 | + | } | |
113 | + | } | |
114 | + | } | |
115 | + | ``` | |
116 | + | ||
117 | + | ## 5. Methods | |
118 | + | Methods help you organize code into reusable blocks: | |
119 | + | ||
120 | + | ```java | |
121 | + | public class Methods { | |
122 | + | public static void main(String[] args) { | |
123 | + | // Calling methods | |
124 | + | greet("Alice"); | |
125 | + | int sum = add(5, 3); | |
126 | + | System.out.println("Sum: " + sum); | |
127 | + | } | |
128 | + | ||
129 | + | // Method with no return value (void) | |
130 | + | public static void greet(String name) { | |
131 | + | System.out.println("Hello, " + name + "!"); | |
132 | + | } | |
133 | + | ||
134 | + | // Method that returns a value | |
135 | + | public static int add(int a, int b) { | |
136 | + | return a + b; | |
137 | + | } | |
138 | + | } | |
139 | + | ``` | |
140 | + | ||
141 | + | These examples cover the fundamental concepts you'll need to start programming in Java. Remember to: | |
142 | + | - Save each class in a separate file with the same name as the class | |
143 | + | - Compile your code using `javac FileName.java` | |
144 | + | - Run your program using `java FileName` | |
145 | + | ||
146 | + | Practice with these examples and modify them to experiment with different values and behaviors. This hands-on experience will help solidify your understanding of Java basics. |