Meeting 2 – Java
Basics: Syntax,
Variables, and Data
Types
Understand the
structure of a basic
Java program
Identify and apply
Java syntax rules
Declare and use
variables, values,
and strings in Java
Every Java program must have a
class
The main() method is the entry
point of execution
Java [Link]() displays output
Example:
Program public class HelloJava {
Structur public static void main(String[]
args) {
e [Link]("Hello,
World!");
}
}
Basic Java Syntax Rules
Java is case- Every statement
sensitive (Main ≠ ends with a
main) semicolon ;
Code blocks are
Use meaningful
enclosed in curly
variable names
braces { }
Variables
in Java
A variable is a
named storage
location in
memory
Must be declared
with a data type
before use
Example: int age =
20;
int → whole numbers
double → decimal numbers
Java Data String → text
Types
Example:
String name = "Maria";
double gpa = 1.75;
Strings in Java
A SEQUENCE OF EXAMPLE: STRING SCHOOL = [Link]
CHARACTERS "MIT OZAMIZ"; N("I STUDY AT " +
ENCLOSED IN SCHOOL);
DOUBLE QUOTES " "
Sample Program –
Personal Information
public class PersonalInfo {
public static void main(String[] args) {
String name = "Juan Dela Cruz";
String course = "BSCS";
int year = 1;
String school = "MIT Ozamiz";
[Link]("Name: " + name);
[Link]("Course: " + course);
[Link]("Year Level: " + year);
[Link]("School: " + school);
}
}
Java programs follow a structure:
class → main method → statements
Summary Variables store values and must have
/ Key a data type
Strings allow us to work with text
Takeaways Writing and running simple programs
helps understand Java fundamentals
Hands-on: Write a Java program that
displays your name, course, year
level, and school
Activities Group Work: Analyze a short Java
code snippet and identify variables,
data types, and output statements