Topic1 Programming Concepts
Topic1 Programming Concepts
◦ software - programs in which contents invisible instructions that control the hardware
and make it perform specific tasks.
◦ You can learn a programming language without knowing computer hardware, but you
will be better able to understand the effect of the instructions in the program if you do.
What is a Computer?
A computer consists of a CPU, memory, hard disk, floppy disk, monitor, printer,
and communication devices.
7
The Hardware
• The CPU clock determines how frequently the computer hardware executes instructions.
• A system’s hardware components are synchronized with the clock. Every time the clock
ticks, another hardware action occurs.
Primary and Random Access MemoryUnit
• ASCII encoding:
• ‘a’ is represented by 01100001
• ‘b’ is encoded as 01100010
CDs
The programs that you use every day such as word processors, spreadsheets, and
games are permanently stored on secondary storage devices.
Compared to RAM, secondary memory is, in general, cheaper (per bit), slower,
larger, electromechanical rather than electronic, and persistent: secondary
memory devices do not lose their values when you turn off the computer.
Input/Output Devices
Standard Input Devices: Output devices:
◦ keyboards Monitors
◦ mouses Printers
◦ joysticks speakers
◦ stylus pens
◦ cameras
◦ microphones
Communication Devices
A regular modem uses a phone line and can transfer data in a speed up to 56,000 bps (bits
per second).
A DSL (digital subscriber line) also uses a phone line and can transfer data in a speed 20
times faster than a regular modem.
A cable modem uses the TV cable line maintained by the cable company. A cable modem is
as fast as a DSL.
Network interface card (NIC) is a device to connect a computer to a local area network (LAN).
The LAN is commonly used in business, universities, and government organizations. A typical
type of NIC, called 10BaseT, can transfer data at 10 mbps (million bits per second).
15
Programs
• Are machine-dependent
• each computer type has its own machine language.
◦ Must use language translators, called assemblers, to convert them to machine code.
◦ Disadvantages:
◦ In general, each assembly language instruction corresponds to one machine
language instruction. Therefore, the programs written in them are lengthy.
◦ Because of variations in assembly languages, programs written using them are not
portable.
21
Interpreting/Compiling Source Code
◦ A program written in a high-level language is called a source program.
◦ Since a computer cannot understand a source program, a source program must be translated into machine
code for execution.
◦ A compiler is a program used to translate the source program into a machine language program called an
object program.
◦ The object program is often then linked with other supporting library code before the object can be executed
on the machine.
◦ You can port a source program to any machine with appropriate compilers.
◦ The source program must be recompiled, however, because the object program can only run on a specific
machine.
23
Compiling Source Code
24
Operating Systems:
• Why Java?
• The answer is that Java enables users to deploy applications on
the Internet for servers, desktop computers, and small hand-
held devices.
• Java Applets
• Java programs that run from a Web Browser
• Applets use a modern graphical user interface with buttons, text fields etc.
to interact with users on the web and process their request.
• Java can also be used to develop applications for hand-held devices such as
Palm and cell phones
Java’s History
• James Gosling and Sun Microsystems
• Originally called Oak
• Java, May 20, 1995, Sun World
• HotJava
• The first Java-enabled Web browser
• Early History Website:
• http://java.sun.com/features/1998/05/birthday.html
Companion
Website Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic
www.cs.armstrong.edu/liang/JavaCharacteristics.pdf
29
• The Java Language Specification, API, JDK and IDE
• The Java language specification is a technical definition of the
language that includes the syntax and semantics of the Java
programming language.
Major changes
◦ J2SE 1.2 (a.k.a JDK 1.2, 1998) – codename Playground
◦ J2SE 1.3 (a.k.a JDK 1.3, 2000) – codename Kestrel
◦ J2SE 1.4 (a.k.a JDK 1.4, 2002) – codename Merlin
◦ J2SE 5.0 (a.k.a JDK 1.5, 2004) – codename Tiger
◦ Java SE 6 (a.k.a JDK 6, 2009) – codename Mustang
◦ Java SE 7 (a.k.a JDK 7, 2011) – codename Dolphin
◦ Java SE 8 (a.k.a JDK 8, 2014)
Java SE Version Java SE Version Version Number Release Date
Version Number Release Date
Java SE 9 9 September, 21st 2017
JDK 1.0 1.0 January 1996
(Oak)
Java SE 10 10 March, 20th 2018
JDK 1.1 1.1 February 1997
Java SE 11 11 September, 25th 2018
J2SE 1.2 1.2 December 1998
(Playground)
Java SE 12 12 March, 19th 2019
J2SE 1.3 1.3 May 2000
(Kestrel)
Java SE 13 13 September, 17th 2019
J2SE 1.4 1.4 February 2002
(Merlin)
Java SE 14 14 March, 17th 2020
J2SE 5.0 1.5 September 2004
(Tiger)
Java SE 15 15 September, 15th 2020
Java SE 6 1.6 December 2006
(Mustang) Java SE 16 March, 16th 2021
16
Java SE 7 1.7 July 2011
(Dolphin) Java SE 17 17 Sept 14th 2021
Java SE 8 1.8 March 2014
Java SE 18 18 March 22nd, 2022
Ref : https://www.codejava.net/java-se/java-se-versions-history
JDK Editions
◦ Java Development Toolkit (JDK) consists of a set of separate programs
for developing and testing Java programs.
• Editing, compiling, building, debugging, and online help are integrated in one
graphical user interface.
• Just enter source code in one window or open an existing file in a window, then
click a button, menu item, or function key to compile and run the program.
A Simple Program (IDE tool – eclipse)
• Example
A Simple Program (IDE tool – BlueJ)
https://www.bluej.org/
• Example
Creating and Editing Using NotePad
38
• Creating, Compiling, and Running Programs
Compiling Java Source Code Learn More
40
animation
41
animation
42
animation
43
Anatomy of a Java Program
Reserved
Comments Package Modifiers
words
The main
method
Comments
Comments are ignored by the compiler.
//… (one line), or
/* …. */ (for one or multiple lines)
• When the compiler sees //, it ignores all text after // in the same line.
• When it sees /*, it scans for the next */ and ignores any text between /* and */.
Name Description
[] Brackets Array
53
Programming Or Implementation Phase
Evolution Design
Evaluation Implementation
CODING
SYNTAX YES
ERROR ?
NO
EXECUTE OR
RUN
DOCUMENTATION OR
MAINTENANCE
Programming Phase: Coding
◦ Translation or conversion of each operation in the flowchart or
algorithm (pseudocode) into a computer-understandable language.
• The compiler will check the program code know also as source
code so that any part of the source code that does not follow
the format or any other language requirements will be flagged
as syntax error.
Programming Phase: Debugging
• This syntax error in also called bug, when error is found the
programmer will debug or correct the error and then
recompile the source code again.
• Trying to understand the logic of the program by looking at the source code is
not a good approach.
• Runtime Errors
• Causes the program to abort
• Occur while an application is running such as input error (unexpected value that
the program cannot handle) or division by zero.
• Logic Errors
• Produces incorrect result
Syntax Errors
63
Syntax Errors
64
Syntax Errors
65
Runtime Errors
66
Logic Errors
Which displays:
Total is 0
But the result that we want is 5.
67
Logic Errors Example
68
Logic Errors
69
Debugging
Logic errors are called bugs. The process of finding and
correcting errors is called debugging.
You can hand-trace the program (i.e., catch errors by reading the
program), or you can insert print statements in order to show the
values of the variables or the execution flow of the program.
This approach might work for a short, simple program.
But for a large, complex program, the most effective approach for
debugging is to use a debugger utility.