Foundational Computer Science Concepts with Java - Student Handout
1. Procedures (Methods in Java)
Definition: A set of reusable instructions that perform a specific task.
Purpose: Avoid code repetition and improve modularity.
Java Example:
public class Example {
static void greet() {
System.out.println("Hello, Student!");
}
public static void main(String[] args) {
greet();
}
}
2. Abstraction
Definition: Hiding complex implementation details and exposing only
essential parts.
Java Mechanism: Abstract classes and interfaces.
Java Example:
abstract class Animal {
abstract void makeSound();
}
class Dog extends Animal {
void makeSound() {
System.out.println("Bark");
}
}
3. Conditions and Iterations
Definition: Conditions make decisions; iterations (loops) repeat code
blocks.
Java Example:
for (int i = 1; i <= 5; i++) {
if (i % 2 == 0) {
System.out.println(i + " is even");
} else {
System.out.println(i + " is odd");
}
}
4. Boolean Tests
Definition: Expressions that evaluate to true or false.
Java Example:
boolean isAdult(int age) {
return age >= 18;
}
5. If-Then-Else
Definition: Executes code based on condition outcomes.
Java Example:
int score = 85;
if (score >= 90) {
System.out.println("Grade: A");
} else if (score >= 75) {
System.out.println("Grade: B");
} else {
System.out.println("Grade: C");
}
6. Database Tables and Queries
Concept: Tables hold structured data (like Excel). Queries
extract/modify data.
Java + SQL Example:
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost/school",
"user", "pass");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM students WHERE
grade = 'A'");
while (rs.next()) {
System.out.println(rs.getString("name"));
}
7. Modeling and Simulation
Definition: Imitating real-world systems to study behavior.
Java Example:
int roll = (int)(Math.random() * 6) + 1;
System.out.println("Dice roll: " + roll);
8. Algorithms and Linear Arrays
Definition: Algorithms are step-by-step solutions. Arrays are linear
collections.
Java Example:
int[] arr = {5, 8, 2, 10, 3};
int max = arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
System.out.println("Max: " + max);
9. Flowcharts
Definition: Visual diagrams representing steps and decisions in
algorithms.
Symbols:
- Oval: Start/End
- Rectangle: Process
- Diamond: Decision
Example Flow:
Start -> [Input Number] -> (Is Even?)
/ \
Yes No
/ \
Print "Even" Print "Odd"
10. Algorithms as Pseudocode
Definition: Plain language step-by-step plan to solve problems.
Example:
1. Set max = first element
2. For each element in array
a. If element > max
i. Set max = element
3. Print max
Prepared By: Your Instructor
Topic: Computational Thinking and Problem Solving in Java