Computer Programming 1 - Java Programming Language
Course Title: Computer Programming 1
Language Focus: Java Programming
Duration: 10 Hours
Mode: Theoretical (Definitions, Explanations, Examples, Discussions)
HOUR 1: Introduction to Programming, History, and Java
What is Programming?
Programming is the process of writing instructions (called code) that a
computer can understand and execute. It is how we tell a computer what to
do, step by step.
Example: Writing a program to calculate the total cost of items in a
shopping cart.
Algorithm:
A series of steps to solve a problem. It is like a recipe.
Program:
The complete set of coded instructions to perform a task.
Programming Language:
A set of syntax rules that define how we can write code. Examples: Java,
Python, C++.
How Programming Started: Programming dates back to the early 19th
century. The first concept of programming was introduced by Ada Lovelace,
who worked with Charles Babbage on the Analytical Engine, a mechanical
general-purpose computer. Ada wrote what is considered the first algorithm
intended for implementation on a machine, making her the first computer
programmer.
In the 1940s, electronic computers emerged. These early machines were
programmed using machine language (binary code made of 1s and 0s),
which was difficult and time-consuming. This led to the development of
assembly language, which used simple symbolic codes. As the need for
better human-computer communication grew, high-level programming
languages were developed.
1957 – FORTRAN: One of the first high-level languages, used for
scientific calculations.
1960s – COBOL: Used in business and government applications.
1970s – C: Gave more control over hardware and is the ancestor of
many modern languages.
1980s – C++: Introduced object-oriented programming concepts.
1990s – Java: Designed to be portable and secure for use in internet
applications.
Founder of Java:
Java was developed by James Gosling in 1995 at Sun Microsystems. It
was originally called Oak.
Why Java?
Platform Independent (Write once, run anywhere)
Object-Oriented
Secure and robust
Used in many fields: Android apps, web apps, enterprise systems
Java Program Structure:
public class Main {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
HOUR 2: Variables and Data Types
Variable:
A storage location in memory with a name. It can hold a value.
Data Types in Java:
int - whole numbers (e.g., 10)
double - decimal numbers (e.g., 3.14)
char - single characters (e.g., ‘A’)
boolean - true or false
String - sequence of characters (e.g., “Hello”)
Example:
int age = 21;
double gpa = 3.5;
char grade = 'A';
boolean passed = true;
String name = "Maria";
Type Conversion:
Implicit (automatic): int to double
Explicit (casting): double to int
HOUR 3: Operators and Expressions
Operator:
A symbol that performs an action.
Types of Operators:
Arithmetic: +, -, *, /, %
Relational: ==, !=, >, <, >=, <=
Logical: &&, ||, !
Assignment: =, +=, -=
Example:
int x = 10 + 5; // x = 15
boolean result = (x > 10) && (x < 20); // true
Expression:
A combination of variables and operators that returns a value.
HOUR 4: Input and Output
Output in Java:
System.out.print() - prints on same line
System.out.println() - prints with new line
Example:
System.out.println("Welcome to Java!");
Input in Java:
Using Scanner class
import java.util.Scanner;
Scanner sc = new Scanner(System.in);
int age = sc.nextInt();
String name = sc.nextLine();
HOUR 5: Conditional Statements
Conditional Statements:
Allows decision making
if Statement Example:
if (age >= 18) {
System.out.println("You are an adult.");
}
if-else Example:
if (score >= 75) {
System.out.println("Passed");
} else {
System.out.println("Failed");
}
switch Statement Example:
switch (grade) {
case 'A':
System.out.println("Excellent");
break;
default:
System.out.println("Unknown Grade");
}