CC103 Computer Programming 1 – Units 1 to 3: Introduction to Programming, Program Logic Formulation, and Java Basics
Unit 1: Introduction to Programming
Lesson 1: Basic Programming Concepts
Data Processing Cycle (Information Processing Cycle): a set of steps the computer follows to receive data, process the data according to instructions from a program, display the resulting information to the user, and store the results.
Often summarized as input → process → output → store.
Emphasizes that data is transformed into meaningful information via a program.
Program Development Process (4–6 steps as presented):
1) Understanding the Problem: get a clear idea of what you want to do; identify input types, processing required, and output requirements.Input, Process, Output framework.
2) Develop the Solution: create detailed plans and logic before coding.Tools: Algorithm / pseudocode, Flowcharts, Structure charts.
3) Implementation: write the source code given the detailed design.
4) Testing: find and correct errors (debugging).Bug refers to an error; process includes tracing where and how information was processed.
5) Documentation: add necessary information about requirements (operating system, hardware) for distribution.
6) Maintenance: keep the program running smoothly and updated with changes in the field.
Problem-solving stages (as per Program Development Process slides):
Understanding the Problem (input, processing, output)
Develop the Solution (Algorithm / Pseudocode, Flowcharts, Structure charts)
Implementation
Testing (Debugging; tracing the flow of data through the program)
Documentation
Maintenance
Programming Languages: a programming language is a vocabulary and set of grammatical rules for instructing a computer. Each language has:
a unique set of keywords (words it understands)
a syntax for organizing program instructions
examples of keywords and syntax vary by language.
Syntax vs. Semantics (Language Theory):
Syntax: set of grammatical rules for writing statements in a language.
Semantics: the meaning associated with statements/code.
Compilers and Interpreters:
Compiler: translates a program written in a high-level language into machine-readable (binary) code before execution.
Interpreter: translates high-level instructions into machine-understandable instructions at runtime.
Source Program vs Object Program:
Source Program: original program written in a high-level language.
Object Program: machine language version of the program (binary).
A compiler converts source code into an object file (machine language module).
Programming Paradigms:
Procedural / Imperative Programming (top-down): a list of instructions and procedures to perform tasks.
Object-Oriented Programming (OOP): computations are carried out using objects as the basic unit; objects have attributes (data) and methods (functions).
Core OOP Concepts (as presented):
Object: an instance with state (attributes) and behavior (methods).
Class: a blueprint for creating objects; defines attributes and methods.
Method: a function defined within a class that operates on an object's data.
Flowcharting and Modeling Tools (from Flowcharting section):
Flowcharts are diagrams that represent the sequence of operations.
Symbols include: Terminal (Start/End), Input/Output, Process, Decision, Off-page Connector, On-page Connector, Predefined Process.
Flowcharting Guidelines:
1) A flowchart begins with START and ends with END.
2) Symbols are connected by arrows.
3) Use comma to separate data and semicolon to separate instructions.
4) Most symbols (except diamond/decision) have a single outgoing arrow; they may have multiple incoming arrows.
5) Use consistent symbols to improve readability.
6) When circles are used, the incoming/outgoing flow should connect to a matching circle.
7) The sequence of symbols indicates the logical steps.
8) A flowchart may reuse symbols; may be multiple steps for one problem.
9) The simplest, most efficient flowchart is often preferred.
Example Flowchart Snippets (from the notes):
Flowchart showing initialization, input, processing, and output with start and end; variables like s, num1, num2.
Flowchart traces show how to compute sums and averages using flowchart steps.
Practice Problems and Algorithm Design (sample problems given in the transcript):
Problem 1: Design an algorithm that computes the sum of two numbers.
Algorithm steps:
get(input/read) two numbers.
compute sum
output sum
Problem 2: Design an algorithm that computes the average of two numbers.
Algorithm steps:
get(input/read) two numbers.
compute average
output average
Average formula: \text{ave} = \frac{\text{num1} + \text{num2}}{2}
Problem 3: Create an algorithm to compute the bonus of an employee. Bonus is 25% of salary; Salary is hours worked times rate per hour.
Variables: hours worked (h), rate per hour (r), salary (s), bonus (b).
Formulas: s = h \times r;\quad b = 0.25 \times s
Summary of Key Data/Compute Concepts:
Sum of two numbers: s = \text{num1} + \text{num2}
Average of two numbers: \text{ave} = \dfrac{\text{num1} + \text{num2}}{2}
Bonus example: \text{salary} = h \times r; \quad \text{bonus} = 0.25 \times \text{salary}
Modular/Procedural vs. Reuse (Modular/Procedural):
Divide and conquer approach; large tasks broken into smaller, reusable tasks (predefined processes).
Unit 2: JAVA BASICS
Lesson 1: Overview of Java Language
Java is an object-oriented programming language originally developed by Sun Microsystems and released in 1995 as part of the Java platform.
Syntax derives from C and C++, but Java has a simpler object model and fewer low-level facilities.
Kinds of Java Programs:
Standalone Applications (Desktop): Console-based programs run without a web browser or server.
Enterprise Applications: Programs that run on a web server and are accessed via a web browser.
Web Applications: Large-scale, distributed, secure apps designed for organizations.
Mobile Applications: Apps designed for smartphones and tablets.
Java Program Execution (Java Program Lifecycle):
Compiling the program uses a Just-In-Time (JIT) compiler to translate Java into bytecode.
Running the program uses a bytecode interpreter to translate each bytecode instruction to machine language.
Java bytecode is platform independent and runs on the Java Virtual Machine (JVM).
Java Bytecode and JVM:
Bytecode is the machine language for the Java Virtual Machine (JVM).
The JVM is a software tool that behaves like a high-level computer and executes Java bytecode programs on any hardware/software platform.
A class file contains JVM instructions (bytecodes) and a symbol table, among other metadata.
The JVM knows nothing about the Java language itself; it operates on a binary class file format.
Bytecode interpretation by the JVM allows platform independence.
Phases in Processing a Java Program:
1) Editing (Edit) – write the source in a file named .java.
2) Compiling (Compile) – use the Java compiler to produce bytecode; the compiler is invoked with a command like: \texttt{javac Welcome.java}.
3) Loading (Load) – the class loader loads the compiled bytecode into memory.
4) Bytecode Verification (Verify) – the JVM verifies bytecode validity.
5) Execution (Execute) – the JVM runs the program.Creating a Java Program:
Use a text editor to create the source file named .java.
An Integrated Development Environment (IDE) provides a code editor, compiler, debugger, and GUI builder.
Compilation produces a .class file containing bytecode.
Java Program Execution Details:
After compilation, the class loader loads the .class file into memory.
The bytecode verifier checks validity before execution.
The JVM executes the program regardless of the underlying hardware/software platform.
Key Terms:
Java Virtual Machine (JVM): software that runs Java bytecode.
Java Bytecode: intermediate representation; platform independent.
Class File (.class): compiled bytecode file.
Typical Workflow (Phases Diagram in Practice):
Edit → Compile → Load → Verify → Execute.
More on Lifecycle (Notable Details):
A program source is saved as .java.
Compilation produces a .class file with bytecode.
The class loader and verifier prepare the program for execution by the JVM.
Lesson 2: Basic Elements of a Java Program
Symbols and Punctuation:
Commas are used to separate items in a list.
Semicolons end statements.
Arithmetic operators: +, -, *, /, \%
Relational operators: <, >, <=, >=, ==, !=
Comments:
Single-line:
// This is my first program
Multi-line:
/* This is my first program in Java Language */
Reserved Words (Keywords):
Examples include:
public
,class
,static
,void
,String
,int
,char
, etc. These have special predefined meanings and cannot be used as identifiers.
Identifiers:
Rules:
Valid characters: A–Z, a–z, digits 0–9, and underscore (_).
The first character cannot be a digit or underscore.
Examples:
Valid:
grade
,area1
,_area
(note: leading underscore is prohibited by some teaching materials; in Java, leading underscore is allowed, but the transcript notes restrict the first character to not be a digit or underscore; prefer to follow the transcript):Valid:
grade
,area1
,area_of_triangle
Invalid: starting with a digit or starting with a space
Variables and Data Types:
A variable holds a value and is stored in memory.
Must be declared with a data type before use.
Data Types in Java (high-level summary):
Boolean:
boolean
(true, false)Character:
char
(e.g.,'A'
,'+'
)Integer:
int
(e.g., 10, 200, 1000)Floating point (single precision):
float
(e.g., 2.5, 10.55)Floating point (double precision):
double
(e.g., 3.141592653589793)Valueless:
void
(used for methods that do not return a value)
Variable Declaration (syntax):
Basic form:
datatype identifier;
e.g.,Code:
int x;
Operators:
Assignment Operator:
=
(e.g.,y = 5;
)Arithmetic Operators:
*
(multiplication),/
(division),%
(modulus),+
(addition),-
(subtraction),++
(increment),--
(decrement)Unary Operators:
+x
(unary plus),-x
(unary minus)Compound Assignment:
+=
,-=
,*=
,/=
,%=
, e.g.,y = y + 5
ory += 5
Operator Precedence (arithmetic):
Multiplicative operators
*
,/
,%
have higher precedence than additive operators+
,-
.When operators have the same level, evaluation is from left to right.
Expressed formally: (*, /, \%) > (+, -) \text{ with left-to-right associativity}.
Relational and Logical Operators:
Relational:
<, >, <=, >=, ==, !=
Logical:
&&
(AND),||
(OR),!
(NOT)
Expressions and Their Types:
Boolean Expression: any expression that evaluates to
true
orfalse
.Arithmetic Expression: expressions used for computations.
Example snippet (conditional):
The transcript includes an example:
if (learning) { System.out.println("Java programmer"); }
(note: shown with Java syntax for a simple conditional output; ensure semicolons and braces are correctly placed in real code).
Summary of Key Java Basics:
Learn the distinction between syntax (structure) and semantics (meaning).
Know how to declare variables, choose appropriate data types, and apply operators and expressions.
Understand how Java programs are written, compiled to bytecode, and executed on the JVM.
Key Formulas and Examples (Summary)
Salary and bonus example:
Salary: s = h \times r
Bonus (25%): b = 0.25 \times s
Sum of two numbers:
s = \text{num1} + \text{num2}
Average of two numbers:
\text{ave} = \dfrac{\text{num1} + \text{num2}}{2}
Conditional: grade passing example (threshold 75):
If grade is >= 75, then Passed; else Failed.
Pseudo-logic: if (grade \ge 75) then print("passed") else print("failed");
Java operator precedence (summary):
(*, \/, \%) > (+, -)\text{, left-to-right associativity}
Example code ideas (not full programs):
Conditional print:
if (learning) { System.out.println("Java programmer"); }
Declaration:
int x;
Assignment and arithmetic:
x = a + b;
orx += 5;
Unit 2: JAVA BASICS (continued)
Phase-by-Phase: Java Program Processing (condensed)
Edit: write source in a file named .java using a text editor or IDE.
Compile: use
javac <ClassName>.java
to generate<ClassName>.class
(bytecode).Load: class loader loads the .class file into memory.
Verify: bytecode verifier checks validity.
Execute: the JVM executes the bytecode.
Additional Java Essentials (Reference)
Identifiers and Keywords:
Keywords:
public
,class
,static
,void
,String
,int
,char
, etc.Identifiers may use letters, digits, and underscore, but cannot start with a digit.
Data Types, Variables, and Declarations (brief recap):
Variables hold values and require declaration with a datatype.
Common datatypes:
boolean
,char
,int
,float
,double
,void
(for methods without return).
Example Identifier Validity (from transcript):
Valid:
grade
,area1
,area_of_triangle
.Invalid: identifiers that start with a digit or spaces (as noted in the transcript).
Flow and Trace: The material includes flowchart tracing exercises where you trace the values of variables (A, B, C, D) as a flowchart executes. Use these to practice understanding control flow.
Practice Problem Concepts (recalled from the transcript):
Problem 4: Conditional pass/fail based on grade >= 75.
Problem 5 & 6: Employee bonus with different rules based on salary thresholds (e.g., 50% vs 25% depending on salary, with a special case for exactly 10,000).
These problems emphasize combining control structures with arithmetic operations.
Summary: The Java content covers the journey from writing source code to running bytecode on the JVM, and establishes the foundational elements of Java syntax, data types, variables, operators, and control flow.
Quick Reference (Cheat Sheet)
Data types: boolean, char, int, float, double, void
Variable declaration:
datatype identifier;
(e.g.,int x;
)Operators: =, +, -, *, /, \%, ++, --, +=, -=, *=, /=, %=
Precedence: (*, /, \%) > (+, -) ; left-to-right associativity
Relational: <, >, <=, >=, ==, !=
Logical: &&, ||, !
Comments:
// ...
and/* ... */
Flowchart symbols: Start/End, Input/Output, Process, Decision, Connectors, Predefined Process
If you need the notes organized under different or more granular headings, I can restructure them into tighter subsections or expand any of the example problems with step-by-step solutions and small code samples.