0% found this document useful (0 votes)
4 views10 pages

04 Java Programming 10 Pages

The document provides an overview of Java programming fundamentals, covering topics such as variables, conditions, loops, arrays, methods, classes, inheritance, exceptions, and collections. Each section includes example code and encourages practice through modifications and testing of edge cases. Additionally, it concludes with a mini project to create a console-based student manager using an ArrayList.

Uploaded by

micasahomes24
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)
4 views10 pages

04 Java Programming 10 Pages

The document provides an overview of Java programming fundamentals, covering topics such as variables, conditions, loops, arrays, methods, classes, inheritance, exceptions, and collections. Each section includes example code and encourages practice through modifications and testing of edge cases. Additionally, it concludes with a mini project to create a console-based student manager using an ArrayList.

Uploaded by

micasahomes24
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

Java Programming

Page 1 of 10 — Java Fundamentals


Java is a strongly typed, object-oriented language commonly used for enterprise software,
Android-related development, backend services, and desktop applications.

Example Code
public class Main {
public static void main(String[] args) {
[Link]("Hello Java");
}
}

Practice: Modify the example, test edge cases, and explain what each line does.
Java Programming
Page 2 of 10 — Variables & Types
Java uses explicit types such as int, double, boolean, char, and String. Use final for values that should
not be reassigned.

Example Code
int age = 25;
double price = 99.5;
boolean active = true;
String name = "Deepak";
[Link](name);

Practice: Modify the example, test edge cases, and explain what each line does.
Java Programming
Page 3 of 10 — Conditions
if, else if, and else control decisions. switch is useful when comparing one value against multiple
cases.

Example Code
int marks = 75;
if (marks >= 60) {
[Link]("Pass");
} else {
[Link]("Try again");
}

Practice: Modify the example, test edge cases, and explain what each line does.
Java Programming
Page 4 of 10 — Loops
for, while, and do-while loops repeat operations. Enhanced for loops are convenient for arrays and
collections.

Example Code
for (int i = 1; i <= 5; i++) {
[Link](i);
}

Practice: Modify the example, test edge cases, and explain what each line does.
Java Programming
Page 5 of 10 — Arrays & Strings
Arrays hold a fixed number of values of one type. String provides methods for working with text.

Example Code
int[] nums = {10, 20, 30};
[Link](nums[0]);
String text = "Coding";
[Link]([Link]());

Practice: Modify the example, test edge cases, and explain what each line does.
Java Programming
Page 6 of 10 — Methods
Methods organize reusable behavior. Parameters provide input and a return type describes the result.

Example Code
static int add(int a, int b) {
return a + b;
}
[Link](add(5, 7));

Practice: Modify the example, test edge cases, and explain what each line does.
Java Programming
Page 7 of 10 — Classes & Objects
A class defines fields and methods. An object is an instance created from a class.

Example Code
class User {
String name;
User(String name) { [Link] = name; }
}
User u = new User("Deepak");

Practice: Modify the example, test edge cases, and explain what each line does.
Java Programming
Page 8 of 10 — Inheritance
Inheritance allows a class to extend another class. Interfaces define contracts that classes can
implement.

Example Code
class Animal {
void sound() { [Link]("Sound"); }
}
class Dog extends Animal {
void bark() { [Link]("Bark"); }
}

Practice: Modify the example, test edge cases, and explain what each line does.
Java Programming
Page 9 of 10 — Exceptions & Collections
Exceptions represent problems during execution. Collections such as ArrayList and HashMap provide
flexible data structures.

Example Code
try {
int x = [Link]("100");
[Link](x);
} catch (NumberFormatException e) {
[Link]("Invalid number");
}

Practice: Modify the example, test edge cases, and explain what each line does.
Java Programming
Page 10 of 10 — Mini Project
Create a console-based student manager. Store students in an ArrayList, calculate marks, search by
name, and print a simple report.

Example Code
ArrayList<String> students = new ArrayList<>();
[Link]("Deepak");
[Link]("Rahul");
for (String s : students) {
[Link](s);
}

Practice: Modify the example, test edge cases, and explain what each line does.

You might also like