Introduction to
Programming
Introduction to Programming
Central Theme: What is Programming? Key Takeaway: Programming is a
skill that enables you to create tools
and solve real-world problems.
Learn how to solve problems by writing Definition: The process of designing, writing,
programs. testing, and maintaining software.
Programming is about creating solutions Software: A set of instructions that tell a
using logical thinking and coding. computer what to do.
Examples:
• Word processors (e.g., Microsoft Word).
• Web browsers (e.g., Chrome, Firefox).
• Embedded systems (e.g., in cars, airplanes,
toasters).
Programming Languages
Tools used by developers to communicate with
Programming Languages: computers.
Examples: Java, Python, C++, JavaScript.
This book focuses on Java, a versatile and widely-used
language.
Java: Java is used for web applications, mobile apps (Android),
and enterprise systems.
Each language has strengths and weaknesses.
No "Best" Language: Java is great for cross-platform applications, while Python
is popular for data science.
Key Takeaway: Learn the principles of programming; switching
languages becomes easier with experience.
What is a Computer?
Definition: Components: Major Hardware Key Takeaway:
Components: Understanding hardware
helps you write efficient
CPU: Executes instructions. programs.
A computer is an electronic Hardware: Physical parts (e.g.,
device that stores and processes CPU, memory, disks). Memory: Stores data and
data. programs temporarily.
Software: Programs that control
hardware. Storage Devices: Save data
permanently (e.g., hard drives,
SSDs).
Input Devices: Allow data entry
(e.g., keyboard, mouse).
Output Devices: Display results
(e.g., monitor, printer).
Communication Devices:
Enable networking (e.g., modems,
NICs).
Central Processing Unit (CPU)
CPU: The brain of the computer.
• Functions:
• Fetches instructions from memory.
• Decodes and executes them.
• Components:
• Control Unit: Manages operations.
• Arithmetic/Logic Unit (ALU): Performs calculations.
Clock Speed:
• Measured in Hertz (Hz).
• Modern CPUs: ~3 GHz (3 billion cycles per second).
Multicore CPUs:
• Multiple cores allow parallel processing.
• Example: Quad-core CPUs can handle four tasks simultaneously.
Key Takeaway: Faster CPUs and more cores improve performance.
Bit: The smallest unit of data (0 or 1).
Can represent a character (e.g.,
Byte: 8 bits. ‘A’ = 01000001 in ASCII).
Bits and Kilobyte (KB): ~1,000 bytes.
Bytes Storage Units:
Megabyte (MB): ~1 million
bytes.
Gigabyte (GB): ~1 billion
bytes.
Terabyte (TB): ~1 trillion
bytes.
Rules for translating characters
into binary.
Encoding Schemes: Example: ASCII encodes ‘C’ as
01000011.
Key Takeaway: Computers use binary to
represent all data.
Memory: Temporary storage for programs and
data.
• RAM (Random-Access Memory):
• Volatile (data is lost when power is off).
• Faster than storage devices.
• Memory Addresses:
• Each byte has a unique address.
Memory Modern PCs:
• Typically have 4–8 GB of RAM.
• More RAM allows for smoother multitasking.
Memory vs. Storage:
• Memory is fast but temporary.
• Storage is slower but permanent.
Key Takeaway: Programs and data must be
loaded into memory for execution.
Types:
• Magnetic Disks: Hard drives (500 GB to 1
TB).
Storage • Optical Discs: CDs (700 MB), DVDs (4.7
GB).
Devices • USB Flash Drives: Portable storage (up to
Hard Drives:
256 GB).
• Used for permanent storage.
• Example: Save documents, photos, and
programs.
Key Takeaway: Storage devices
preserve data even when the
computer is off.
Input Devices:
• Keyboard: For typing text.
• Mouse: For pointing and clicking.
Input and Output Devices:
Output • Monitor: Displays text and graphics.
Devices • Printer: Produces physical copies.
Monitor Resolution:
• Measured in pixels (e.g., 1920x1080).
• Higher resolution = sharper images.
Key Takeaway: Input and output devices
enable interaction with the computer.
Dial-up: Slow (56
Kbps).
Modems: DSL: Faster (~20x dial-
up).
Cable: Faster than DSL.
Communica Network Interface
Connect computers to
networks.
tion Cards (NIC): Example: Ethernet
cards.
Devices
Wireless Enable Wi-Fi
Adapters: connectivity.
Key Takeaway: Communication
devices connect computers to the
internet and networks.
Machine Binary code understood by the CPU.
Language
Example: 1101101010011010.
:
Programm Assembly
Language
:
Mnemonics for machine instructions.
Example: ADD 2, 3, result.
ing High-
Language
Level English-like syntax.
Language Example: Java, Python, C++.
s:
s Compilers
vs. Compiler: Translates entire program into machine code.
Interprete Interpreter: Translates and executes line by line.
rs:
Key High-level languages make programming easier and more
Takeaway: efficient.
Definition:
• Software that manages hardware and software resources.
Operating Examples:
• Windows, macOS, Linux.
Systems
(OS) Functions:
• Control System Activities: Manage hardware (e.g., CPU,
memory).
• Allocate Resources: Assign CPU time, memory, etc.
• Schedule Operations: Run programs efficiently.
Key Takeaway: The OS is essential for running
applications.
Java:
• Developed by James Gosling (Sun Microsystems,
now Oracle).
• Platform Independence: Write once, run
anywhere.
Java and Java Applets:
the World • Programs embedded in web pages.
• Example: Interactive animations.
Wide Web Java Editions:
• Java SE: Standard Edition (desktop applications).
• Java EE: Enterprise Edition (server-side
applications).
• Java ME: Micro Edition (mobile devices).
Key Takeaway: Java is versatile and
widely used.
JDK (Java Development
Kit):
Java • Includes compiler, interpreter,
and other tools.
Developm IDE (Integrated
ent Tools Development
Environment):
• Examples: NetBeans, Eclipse.
• Combines editing, compiling,
debugging.
Example:
public class Welcome {
public static void main(String[] args) {
A Simple [Link]("Welcome to Java!");
Java }
Program }
Key Points:
Class name must match file name.
main method is the entry point.
Statements end with a semicolon (;).
Syntax Runtime
Errors: Errors:
• Detected by the • Occur during
compiler. execution.
Common • Example:
Missing
semicolon.
• Example:
Division by zero.
Errors
Logic Errors: Key
• Program runs Takeaway:
but produces
incorrect results.
Debugging is
• Example: a critical skill
Incorrect for
formula. programmers.
Comments: Use // for line
comments, /* */ for block
comments.
Programmin Indentation: Improves
g Style and readability.
Documentat Block Styles: Next-line vs. end-
ion of-line braces.
Consistency: Use a consistent
style throughout the program.
NetBeans:
• Create projects, classes, and run programs.
NetBeans Eclipse:
and • Similar functionality with a different interface.
Eclipse Both IDEs:
• Simplify coding, compiling, and debugging.
Key Takeaway: Use IDEs to boost
productivity.
Programming is problem-solving using software.
Key Java is a versatile, platform-independent
Concept language.
s: Understand hardware, software, and
programming basics.
Summar
y
Practice writing and debugging simple Java
Next programs.
Steps: Explore more advanced topics (e.g., object-
oriented programming).
Key
Takeawa Programming is a valuable skill for the digital age.
y: