Java Fundamentals & Object-Oriented
Programming
CSCE 145 Notes — Syntax, Control Flow, Classes & Objects
Computer Science • Active-Learning Edition
How to use this workbook
1. Read the concept explanation. 2. Study the worked example. 3. Try the practice problems yourself.
4. Check your work against the Answer Key. 5. Revisit anything you missed.
, 1. Program Basics
● Every Java file = one class. Execution always starts in the main method.
CODE
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
✏ TRY IT YOURSELF
1. Write a Main class that prints your name to the console.
2. Input & Output
Term Definition
System.out.println() Prints a message and moves to a new line.
System.out.print() Prints a message without a new line.
Scanner Used for reading user input: sc.nextInt(), sc.nextDouble(), sc.next(), sc.nextLine().
✏ TRY IT YOURSELF
1. Write code that asks the user for their age (an int) and prints "You are __ years old."
3. Variables & Data Types
Term Definition
byte Whole numbers, -128 to 127.
short Whole numbers, -32,768 to 32,767.
int Whole numbers, about ±2.1 billion.
long Very large whole numbers (±9.2 quintillion).
float Fractional numbers, ~6-7 decimal digits precision.
double Fractional numbers, ~15 decimal digits precision.
boolean true or false.
char A single character or Unicode value.
String / arrays / objects Reference types (not primitives).
WORKED EXAMPLE — Declaration vs Initialization
int age; // declare only
age = 20; // initialize
int year = 2025; // both at once
✏ TRY IT YOURSELF