Java Basics Guide: Create Your Own Programs
===========================================
Environment Setup
-----------------
1. Download JDK from [Link]/java (JDK 21+).
2. Install and verify: Open Command Prompt/Terminal, run `java -version` and `javac -version`.
3. Add JDK bin to PATH if needed.[web:27][web:28]
Basic Syntax
------------
public class HelloWorld {
public static void main(String[] args) {
[Link]("Hello, World!");
}
}
Save as [Link]. Statements end with ;, use {} for blocks.[web:28][web:29]
Variables and Data Types
------------------------
int age = 25;
double price = 19.99;
String name = "User";
boolean isActive = true;
char grade = 'A';[web:4][web:11]
Control Flow
------------
If-else:
if (age >= 18) {
[Link]("Adult");
} else {
[Link]("Minor");
}
Loops:
for (int i = 0; i < 5; i++) {
[Link](i);
}[web:11]
Compiling and Running Step-by-Step
----------------------------------
1. Write code, save as [Link].
2. Terminal: cd to folder (e.g., cd Desktop/Java).
3. Compile: javac [Link] (creates .class).
4. Run: java Filename.
Troubleshoot: Check PATH, fix compiler errors.[web:27][web:29][web:31]
Practice: Simple Calculator
---------------------------
import [Link];
public class Calculator {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter two numbers: ");
int a = [Link](), b = [Link]();
[Link]("Sum: " + (a + b));
[Link]();
}
}
Compile and run to test input/output.[web:31]
Next Steps
----------
Practice loops, arrays, methods. Align with your study catch-up plan.[web:1]