0% found this document useful (0 votes)
0 views5 pages

Core Java Syntax Examples

The document outlines a 15-day learning plan for Core Java, covering essential topics such as Java basics, variables, operators, control structures, methods, OOP concepts, exception handling, and collections. Each day includes code examples to illustrate the concepts being taught. The plan is structured to gradually build knowledge and skills in Java programming.

Uploaded by

eliassannu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views5 pages

Core Java Syntax Examples

The document outlines a 15-day learning plan for Core Java, covering essential topics such as Java basics, variables, operators, control structures, methods, OOP concepts, exception handling, and collections. Each day includes code examples to illustrate the concepts being taught. The plan is structured to gradually build knowledge and skills in Java programming.

Uploaded by

eliassannu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Easy Core Java Learning Plan

Day 1: Java Basics

public class HelloWorld {


public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
// Single-line comment
/* Multi-line comment */

Day 2: Variables & Data Types

int age = 25;


float pi = 3.14f;
double salary = 55000.50;
char grade = 'A';
boolean isJavaFun = true;
String name = "John";

Day 3: Operators

int a = 10, b = 5;
System.out.println(a + b); // Arithmetic
System.out.println(a > b); // Relational
System.out.println(a > 5 && b < 10); // Logical
a += 5; // Assignment

Day 4: if-else, else-if

int num = 10;


if (num > 0) {
System.out.println("Positive");
} else if (num < 0) {
System.out.println("Negative");
} else {
System.out.println("Zero");
}
Easy Core Java Learning Plan

Day 5: switch-case

int day = 2;
switch(day) {
case 1: System.out.println("Sunday"); break;
case 2: System.out.println("Monday"); break;
default: System.out.println("Other Day");
}

Day 6: while & do-while

int i = 1;
while(i <= 5) {
System.out.println(i);
i++;
}

int j = 1;
do {
System.out.println(j);
j++;
} while(j <= 5);

Day 7: for loop

for(int i = 1; i <= 5; i++) {


System.out.println("Value: " + i);
}

Day 8: Arrays

int[] numbers = {1, 2, 3, 4, 5};


for(int num : numbers) {
System.out.println(num);
}

Day 9: Strings
Easy Core Java Learning Plan

String str = "Java";


System.out.println(str.length());
System.out.println(str.charAt(0));
System.out.println(str.substring(1));
System.out.println(str.equals("Java"));

Day 10: Methods (Functions)

public class Demo {


public static int add(int a, int b) {
return a + b;
}
public static void main(String[] args) {
System.out.println(add(5, 3));
}
}

Day 11: static & non-static

public class Test {


static void staticMethod() {
System.out.println("Static method");
}

void nonStaticMethod() {
System.out.println("Non-static method");
}

public static void main(String[] args) {


staticMethod();
Test obj = new Test();
obj.nonStaticMethod();
}
}

Day 12: OOP - Class, Objects, Constructors

class Person {
Easy Core Java Learning Plan

String name;
Person(String n) {
name = n;
}
void display() {
System.out.println("Name: " + name);
}
}

public class Main {


public static void main(String[] args) {
Person p = new Person("Alice");
p.display();
}
}

Day 13: Inheritance & Polymorphism

class Animal {
void sound() {
System.out.println("Animal makes sound");
}
}

class Dog extends Animal {


void sound() {
System.out.println("Dog barks");
}
}

public class Main {


public static void main(String[] args) {
Animal a = new Dog();
a.sound();
}
}

Day 14: Exception Handling

try {
Easy Core Java Learning Plan

int a = 5 / 0;
} catch(ArithmeticException e) {
System.out.println("Can't divide by zero");
} finally {
System.out.println("Always executed");
}

Day 15: Collections - List & Map

import java.util.*;

public class Demo {


public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("Apple");
list.add("Banana");

for(String fruit : list) {


System.out.println(fruit);
}

Map<Integer, String> map = new HashMap<>();


map.put(1, "One");
map.put(2, "Two");

for(Map.Entry<Integer, String> entry : map.entrySet()) {


System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
}

You might also like