Day 1 - Java Seminar Notes
Day 1 - Java Seminar Notes
K-Scheme
About Seminar -:
Throughout this seminar, participants will gain both theoretical knowledge and hands-
on experience, starting from the basics and progressing to advanced features like
object-oriented programming and file handling. Each day is structured to build upon
the previous one, ensuring a clear and logical learning path.
This seminar is ideal for beginners and intermediate learners who are eager to develop
practical programming skills in Java and lay the groundwork for future learning in
software development, mobile app creation, and competitive coding.
If you come with an open mind, a willingness to practice, and a genuine interest in
learning, this seminar will be a valuable experience for you.
✅ 7-Day Java Seminar Plan ( Based on MSBTE )
Practical:
Practical:
Unit II:
Practical:
Unit III:
Errors vs Exceptions
try-catch-finally, throw, throws
Creating Threads: Thread class & Runnable interface
Thread Life Cycle, Priority, Synchronization
Practical:
Practical:
Practical:
Unit V + VI:
Practical:
7. Wrapper Classes ☐
Practical:
Java -:
The Java programming environment refers to the setup and tools needed to write,
compile, and run Java programs on a computer. The Java environment consists of
several key components, each playing an important role in the development and
execution of Java applications.
The JDK is the core software development kit required for Java programming. It
includes everything you need to develop Java applications:
Java Compiler (javac): Converts Java source code into bytecode that the
Java Virtual Machine (JVM) can execute.
Java Runtime Environment (JRE): Provides the necessary libraries and
components to run Java programs. It includes the JVM.
Development Tools: Includes tools like javap (disassembler), javadoc
(documentation generator), and jar (tool to package files)
To get started with Java, you need to download and install the JDK from the
official Oracle website.
2. Java Runtime Environment (JRE)
The JRE is a part of the JDK but can also be installed separately. It provides the
environment for executing Java programs and includes:
Java Virtual Machine (JVM): The JVM is responsible for running Java
bytecode. It makes Java platform-independent by translating bytecode into
machine-specific instructions at runtime.
Java Class Libraries: A large set of pre-built classes that Java programs can
use, such as file I/O, networking, and utilities (e.g., java.util and java.io).
The JVM is the engine that enables Java's platform independence. It converts Java
bytecode (the compiled code) into machine code that the operating system can
execute.
Portability: The JVM allows the same Java program to run on any operating
system (Windows, Linux, macOS, etc.).
Garbage Collection: The JVM automatically manages memory by cleaning
up objects that are no longer in use.
An IDE is a software application that provides tools to write, test, and debug Java
code more efficiently. Some popular IDEs for Java development include:
IntelliJ IDEA: Known for its powerful features, excellent code suggestions,
and great integration with Java frameworks.
Eclipse: Open-source and widely used in Java development, particularly for
enterprise-level applications.
NetBeans: Another open-source IDE with good support for Java
development and excellent for beginners.
Documentation Session
The compiler ignores these comments during the time of execution and is solely
meant for improving the readability of the Java program.
There are three types of comments that Java supports
Example
Package Statement
There can be only one package statement in a java program and it has to be at
the beginning of the code before any class or interface declaration.
This statement is optional, for example, take a look at the statement below.
package student
This statement declares that all the classes and interfaces defined in this source file are
a part of the student package.
Many predefined classes are stored in packages in java, an import statement is used to
refer to the classes stored in other packages.
An important statement is always written after the package statement but it has to be
before any class declaration.
We can import a specific class or classes in an import statement. Take a look at the
example to understand how import statement works in java.
Interface Section
1 interface stack
2 {
3 void push(int item);
4 void pop();
5 }
Class Definition
A java program may contain several class definitions, classes are an essential part of
any java program.
This section is used to specify an interface in java.
An interface is a lot similar to a class in java but it contains only constants and
method declarations.
Every program in java will have at least one class with the main method.
The main method is from where the execution actually starts and follows the order
specified for the following statements.
In Java (and all object-oriented programming languages), class and object are two
fundamental building blocks.
What is a Class?
Real-life Example:
But the blueprint itself is not a car. It just describes how to build one.
Syntax of a Class:
Real-life Example:
Creating an Object:
1. Keywords
Examples:
Example in code:
2. Identifiers
These are names used for variables, methods, classes, etc.
You create these names yourself.
Rules:
Example:
int age;
String studentName;
MyClass obj;
3. Literals
Examples:
Example:
4. Operators
These are symbols used to perform operations like addition, comparison, etc.
Types of Operators:
Arithmetic: +, -, *, /
Relational: ==, !=, <, >
Assignment: =, +=, -=
Examples:
Example:
Type Casting
Type Casting in Java means converting one data type into another.
For example:
This is useful when you want to store a value of one type into a variable of another
type.
Two Types of Type Casting in Java:
Example:
You must manually convert larger data types to smaller data types.
Syntax:
Example:
Decision Making
Imagine this:
Similarly, in Java:
if (raining) {
takeUmbrella();
} else {
wearSunglasses();
}
Types of Decision-Making Statements in Java:
Statement Description
✅ 1. if Statement
Syntax:
if (condition) {
// Code to execute if condition is true
}
Example:
Output:
Here, the code inside the if block runs only if the condition (age >= 18) is true.
✅ 2. if-else Statement
➤ Purpose: Runs one block if condition is true, otherwise runs another.
Syntax:
if (condition) {
// Code if condition is true
} else {
// Code if condition is false
}
Example:
Output:
You Failed
✅ 3. else-if Ladder
Syntax:
if (condition1) {
// Code if condition1 is true
} else if (condition2) {
// Code if condition2 is true
} else {
// Code if all conditions are false
}
Example:
Output:
Grade B
✅ 4. Nested if Statement
Syntax:
if (condition1) {
if (condition2) {
// Code if both conditions are true
}
}
Example:
int age = 22;int weight = 58;
if (age >= 18) {
if (weight >= 50) {
System.out.println("You can donate blood.");
}
}
Output:
✅ 5. switch Statement
➤ Purpose: Useful when you have many fixed choices to select from.
Syntax:
switch (variable) {
case value1:
// Code
break;
case value2:
// Code
break;
...
default:
// Code if no match
}
Example:
int day = 2;
switch(day) {
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
default:
System.out.println("Invalid day");
}
Output:
Tuesday
switch is better than many if-else statements when checking a single variable against
many values.
Looping In Java
What is Looping?
Looping means repeating a block of code again and again — until a certain
condition is met.
It helps to avoid writing the same code multiple times.
for Loop
Syntax:
Example:
Output:
Java
Java
Java
Java
Java
while Loop
Syntax:
while (condition) {
// code to repeat
}
Example:
Output:
Hello
Hello
Hello
do-while Loop
Syntax:
do {
// code to repeat
} while (condition);
Example:
int i = 1;do {
System.out.println("Welcome");
i++;
} while (i <= 2);
Output:
Welcome
Welcome
Access Modifiers
private ✅ Yes ❌ No ❌ No ❌ No
(default)
✅ Yes ✅ Yes ❌ No ❌ No
✳
✅ Example:
class Student {
private int rollNo = 101;
void showRoll() {
System.out.println(rollNo);
}
}
✅ Example:
class Car {
String brand = "Honda"; // default access
}
This variable cannot be accessed from another package.
protected Modifier
✅ Example:
class Animal {
protected void sound() {
System.out.println("Animal Sound");
}
}
A class that extends Animal in another package can still access sound().
public Modifier
✅ Example:
1. Problem: Write a Java program that takes the age of a person as input and prints
whether the person is a Child (age < 12), Teenager (age between 12 and 19), or
Adult (age >= 20).
Concepts:
If-else statements
Age validation and classification
2. Problem: Write a Java program that accepts marks as input and prints the
corresponding grade:
3. Problem: Write a Java program that calculates the electricity bill using
the following logic:
4. Problem: Create a Java program that shows a basic ATM menu with
options
Withdraw
Deposit
Check Balance
Use a loop to keep the ATM running until the user chooses to exit.
5. Problem: Write a Java program to calculate the final bill amount after
applying a discount:
Else → No discount
1. Problem:
A number is called a Magic Number if the recursive sum of its digits is 1.
Example: 199
1 + 9 + 9 = 19 → 1 + 9 = 10 → 1 + 0 = 1 ✅
A security pin system allows only numbers that meet all the following
rules:
End of Day 1
See You Tomorrow !