Programming and Java Fundamentals

Introduction to Programming

ReadingPreview

আপনি একটি free preview lesson দেখছেন।

Lesson Overview

Programming is the process of giving a computer clear and specific instructions to perform a task or solve a problem.

A computer can process data very quickly, but the programmer must define what it should do. Those instructions are written using a programming language.

In this lesson, we will learn:

  • What programming and source code are
  • How a programming language expresses instructions
  • How programs solve problems
  • Algorithms and the Input–Processing–Output model
  • The difference between a program and an application
  • A common programming workflow
  • Syntax, runtime, and logical errors

Learning Objectives

After completing this lesson, you will be able to:

  • Explain programming and source code
  • Understand what an algorithm is
  • Think about a problem in terms of Input, Processing, and Output
  • Understand the difference between a program and an application
  • Explain a common programming workflow
  • Distinguish between syntax, runtime, and logical errors

What Is Programming?

Programming is the process of designing and writing instructions for a computer.

Programming can be used to make a computer perform many different types of tasks, such as:

  • Performing calculations
  • Saving or searching data
  • Processing user input
  • Processing payments
  • Sending emails or notifications
  • Communicating with other systems

The human-readable instructions written by a programmer using a programming language are called source code.

Example:

System.out.println("Welcome to Java");

Output:

Welcome to Java

This is Java source code.

A developer can read this code, but the processor does not directly execute Java source code. We will discuss how Java source code is transformed into executable instructions in the next lesson.

What Is a Programming Language?

A programming language is a structured language used to write instructions for a computer.

Some well-known programming languages include:

  • Java
  • Python
  • JavaScript
  • Go
  • C
  • C++
  • C#
  • Rust
  • Kotlin

Each language has its own syntax, keywords, data types, and code structure.

Java:

System.out.println("Hello");

Python:

print("Hello")

Both instructions perform a similar task, but their syntax is different.

Programming and Problem Solving

Programming is not just about writing syntax. First, you need to understand the problem. Then, you need to break it into smaller steps that a computer can follow.

Suppose we need to calculate a student's average mark.

One possible solution is:

  1. Receive the student's marks
  2. Add the marks together
  3. Determine the number of subjects
  4. Divide the total by the number of subjects
  5. Display the average

This ordered sequence of steps is called an algorithm.

What Is an Algorithm?

An algorithm is a clear, specific, and correctly ordered sequence of steps used to solve a problem or complete a task.

An algorithm does not depend on a programming language. The same algorithm can be implemented in Java, Python, or another language.

The steps of a good algorithm should be:

  • Clear
  • Complete
  • Arranged in the correct order
  • Possible to perform in practice

Input, Processing, and Output

Many programming problems can be thought of in three parts:

  1. Input
  2. Processing
  3. Output

Input

Information received by a program.

Examples:

  • Student marks
  • Product price
  • User email
  • Account balance
  • Data received from another system

Processing

Operations that a program performs on the input.

Examples:

  • Adding two values
  • Calculating an average
  • Comparing a password
  • Searching for a product
  • Checking a condition

Output

The result produced by a program after processing.

Examples:

  • Calculated total
  • Search result
  • Error message
  • Confirmation
  • Generated report

Example: Area of a Rectangle

Suppose we need to calculate the area of a rectangle.

Formula:

area = length × width

Input

  • length
  • width

Processing

Multiply length and width.

Output

The calculated area.

Algorithm:

  1. Receive the length
  2. Receive the width
  3. Multiply the length and width
  4. Display the result

Java implementation:

int length = 10;
int width = 5;

int area = length * width;

System.out.println(area);

Output:

50

At this point, understanding the problem's input, calculation, and expected output clearly is more important than understanding the Java syntax.

Program and Application

Program and application are related concepts, but they are not exactly the same.

Program

A program is a collection of instructions that performs a specific task.

For example:

  • Grade calculator
  • Temperature converter
  • File rename tool

A program can be very small.

Application

An application is usually larger software in which multiple features and components work together.

For example:

  • Banking application
  • Web browser
  • Learning platform
  • Food delivery application
  • E-commerce application

An application may contain:

  • User interface
  • Backend service
  • Database
  • Authentication
  • External integration
  • Payment or notification system

A small program may perform one specific task. An application generally solves multiple related tasks together.

Source Code

Source code is human-readable instructions written using a programming language.

Java source code is generally stored in files with the .java extension.

Examples:

Main.java
GradeCalculator.java
BankAccount.java
Student.java

A Java source file may contain classes, methods, variables, conditions, loops, and object-related code.

Example:

public class Main {

    public static void main(String[] args) {
        System.out.println("My first Java program");
    }
}

You do not need to understand every part of this code yet. We will learn these concepts step by step in the following lessons.

A Common Programming Workflow

Programming is an iterative process in practice. However, as a beginner, it can be understood as a series of steps.

1. Understand the Problem

Before writing code, you need to clarify:

  • What should the program do?
  • What input is required?
  • What output is expected?
  • What rules must be followed?
  • Which situations may be invalid?

If you misunderstand the problem, technically correct code can still produce the wrong solution.

2. Determine the Input, Output, and Rules

You need to determine what data the program will receive and what result it should produce.

For example, the input for a grade calculator could be:

  • Mathematics mark
  • English mark
  • Science mark

The output could be:

  • Total
  • Average
  • Grade

3. Create an Algorithm

Determine the steps required to produce the expected output from the input.

For example:

  1. Receive the marks
  2. Validate the marks
  3. Calculate the total
  4. Calculate the average
  5. Display the result

4. Write the Code

The algorithm is implemented using a programming language.

Example:

int mathematics = 80;
int english = 90;
int science = 85;

int total = mathematics + english + science;

System.out.println(total);

5. Run, Test, and Debug

After writing the code, execute the program and check:

  • Whether the code compiles
  • Whether the program behaves as expected
  • Whether the correct result is produced
  • Whether unexpected input can be handled

When testing a grade calculator, you may consider not only ordinary values but also boundary and invalid values:

  • 0
  • Maximum allowed mark
  • Negative mark
  • A mark greater than the maximum

A program working for one input does not mean that it is correct in every situation.

6. Improve the Solution

After the program works, the code can be improved further.

For example:

  • Use better variable names
  • Reduce duplicate code
  • Improve validation
  • Make the code more readable
  • Break large logic into smaller parts

Debugging

The process of finding an error in a program, understanding its cause, and fixing it is called debugging.

During debugging, a developer generally:

  1. Observes the error or unexpected behavior
  2. Identifies the relevant code
  3. Finds possible causes
  4. Tests a hypothesis
  5. Applies a fix
  6. Runs and tests the program again

Errors are a normal part of programming. An important skill is being able to systematically identify the cause of an error.

Common Types of Programming Errors

Three important categories are:

  1. Syntax error
  2. Runtime error
  3. Logical error

Syntax Error

A syntax error occurs when code does not follow the rules of the programming language.

Example:

System.out.println("Hello")

The semicolon at the end of the statement is missing.

Correct:

System.out.println("Hello");

Another example:

int age = ;

There is no valid value here.

Syntax errors can generally be detected by the compiler before the program runs.

Runtime Error

A runtime error occurs while a program is executing.

Example:

int result = 10 / 0;

Dividing an integer value by zero will cause the program to fail at runtime.

Runtime failures may also occur because of:

  • Missing file
  • Invalid input
  • Missing data
  • Network failure
  • Unexpected system state

We will learn about Java exceptions and error handling in detail in a later lesson.

Logical Error

With a logical error, the program runs, but the result is incorrect.

Example:

int mathematics = 80;
int english = 90;

int total = mathematics + english;
int average = total / 3;

System.out.println(average);

There are two subjects, but the total is divided by 3.

Correct calculation:

int average = total / 2;

Logical errors can be comparatively difficult to identify because:

  • The program may not crash
  • There may be no error message
  • The result may appear reasonable

This is why testing is important.

Programming Means Precise Problem Solving

A programming language is a tool.

Good programming requires:

  • Understanding the problem clearly
  • Breaking the problem into smaller parts
  • Determining the input and expected output
  • Creating a logical solution
  • Implementing the solution in code
  • Testing the result
  • Fixing errors

Memorizing syntax may allow you to write familiar examples. But to solve new problems, you need to understand the underlying logic.

Important Terms

Programming

The process of designing and writing instructions for a computer.

Programming Language

A structured language used to write instructions for a computer.

Source Code

Human-readable code written by a programmer using a programming language.

Program

A collection of instructions used to perform a specific task.

Application

Software made up of multiple related features and components.

Algorithm

An ordered sequence of steps used to solve a problem.

Input

Information received by a program.

Processing

Operations performed by a program on input.

Output

The result produced by a program.

Debugging

The process of finding the cause of an error in a program and fixing it.

Syntax Error

An error caused by breaking the syntax rules of a programming language.

Runtime Error

An error that occurs while a program is executing.

Logical Error

An error in which the program runs but produces an incorrect result.

Practice Exercise 1: Algorithm and Input–Processing–Output

Write a solution for calculating the area of a rectangle.

Formula:

area = length × width

Write the following separately:

  • Input
  • Processing
  • Output
  • Algorithm

You do not need to write Java code.

Practice Exercise 2: Identify the Error Type

Determine whether each example contains a syntax error, runtime error, or logical error.

Example 1

System.out.println("Java")

Example 2

int result = 100 / 0;

Example 3

int price = 500;
int quantity = 2;

int total = price + quantity;

Example 4

int age = ;

Practice Exercise 3: Break Down a Problem

Choose any one of the following systems:

  • Library management system
  • Food delivery application
  • Student management system
  • Online shopping application
  • Learning platform

Write:

  1. What problem the system solves
  2. Three possible inputs
  3. Three processing operations
  4. Three possible outputs

You do not need to write Java code.

Knowledge Check

Question 1

What is programming?

Question 2

What is source code?

Question 3

What is an algorithm?

Question 4

What do Input, Processing, and Output mean?

Question 5

What is the difference between a program and an application?

Question 6

What is the difference between a syntax error, runtime error, and logical error?

Question 7

What is debugging?

Knowledge Check Answers

Answer 1

Programming is the process of designing and writing instructions for a computer.

Answer 2

Source code is human-readable code written by a programmer using a programming language.

Answer 3

An algorithm is an ordered sequence of steps used to solve a problem or complete a task.

Answer 4

Input is the information received by a program, Processing is the operation performed on that information, and Output is the result produced by the program.

Answer 5

A program generally performs a specific task. An application is generally larger software made up of multiple related features and components.

Answer 6

A syntax error breaks the syntax rules of the language. A runtime error occurs while the program is executing. With a logical error, the program runs but produces an incorrect result.

Answer 7

Debugging is the process of finding the cause of an error in a program and fixing it.

Lesson Summary

In this lesson, we learned:

  • Programming is the process of designing and writing instructions for a computer
  • Source code is written using a programming language
  • Programming is primarily a problem-solving process
  • An algorithm describes the steps used to solve a problem
  • Many problems can be thought of in terms of Input, Processing, and Output
  • Programs and applications can have different scopes
  • Programming involves problem analysis, implementation, testing, and improvement
  • Debugging is the process of finding and fixing errors
  • Syntax, runtime, and logical errors are different from one another