Java Programming As a Beginner

3 min read
Here are basic but detailed notes for Java, including description, syntax, examples, and output/results. These are beginner-friendly and essential for understanding Java fundamentals.
๐ 1. Introduction to Java
Java is a high-level, class-based, object-oriented programming language developed by James Gosling at Sun Microsystems in 1995.
It follows the WORA principle: Write Once, Run Anywhere using the Java Virtual Machine (JVM).
๐ 2. Basic Java Structure
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
โ Output:
Hello, Java!
๐งฑ 3. Data Types
Type | Description | Example |
int | Integer values | int x = 10; |
float | Decimal (4 bytes) | float y = 3.14f; |
double | Larger decimal | double z = 9.81; |
char | Single character | char c = 'A'; |
boolean | True/false | boolean b = true; |
String | Sequence of chars | String s = "Hi"; |
๐งฎ 4. Variables and Operators
int a = 5;
int b = 3;
int sum = a + b;
System.out.println("Sum is: " + sum);
โ Output:
Sum is: 8
๐ 5. Conditional Statements
int age = 18;
if (age >= 18) {
System.out.println("Adult");
} else {
System.out.println("Minor");
}
โ Output:
Adult
๐ 6. Loops
โค For Loop
for (int i = 1; i <= 5; i++) {
System.out.println("Number: " + i);
}
โ Output:
Number: 1
Number: 2
Number: 3
Number: 4
Number: 5
โค While Loop
int i = 1;
while (i <= 3) {
System.out.println("i = " + i);
i++;
}
๐ฆ 7. Arrays
int[] nums = {10, 20, 30};
System.out.println(nums[1]);
โ Output:
20
๐งฐ 8. Methods (Functions)
public class Main {
static void greet() {
System.out.println("Hello from a method!");
}
public static void main(String[] args) {
greet();
}
}
โ Output:
Hello from a method!
๐งฑ 9. Object-Oriented Programming
โค Class and Object
class Car {
String model = "Tesla";
}
public class Main {
public static void main(String[] args) {
Car myCar = new Car();
System.out.println(myCar.model);
}
}
โ Output:
Tesla
๐งฉ 10. Inheritance
class Animal {
void sound() {
System.out.println("Animal sound");
}
}
class Dog extends Animal {
void sound() {
System.out.println("Dog barks");
}
}
public class Main {
public static void main(String[] args) {
Dog d = new Dog();
d.sound();
}
}
โ Output:
Dog barks
1
Subscribe to my newsletter
Read articles from Himanshi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
