1-Introduction To Computer, Programming, and Java
1-Introduction To Computer, Programming, and Java
College of Science
Department of Computer Science
Fundamentals of Programming
First Stage
First Semester
Introduction to Computer,
Programming, and Java
3
CPU
4
Memory
Bus
5
How Data is Stored?
» Memory is volatile; because the information is lost when the power is off.
Programs and data are permanently stored on storage devices and are
moved to memory when the computer actually uses them. E.g. Disk drives
(hard disks and floppy disks) and CD drives.
Bus
7
Output Devices: Monitor
8
Communication Devices
9
Programs
10
Programming Languages
Machine Language Assembly Language High-Level Language
1101101010011010
11
Programming Languages
Machine Language Assembly Language High-Level Language
12
Programming Languages
Machine Language Assembly Language High-Level Language
13
Popular High-Level Languages
Language Description
Ada Named for Ada Lovelace, who worked on mechanical general-purpose computers. The Ada
language was developed for the Department of Defense and is used mainly in defense projects.
BASIC Beginner’s All-purpose Symbolic Instruction Code. It was designed to be learned and used easily
by beginners.
C Developed at Bell Laboratories. C combines the power of an assembly language with the ease of
use and portability of a high-level language.
C++ C++ is an object-oriented language, based on C.
C# Pronounced “C Sharp.” It is a hybrid of Java and C++ and was developed by Microsoft.
COBOL COmmon Business Oriented Language. Used for business applications.
FORTRAN FORmula TRANslation. Popular for scientific and mathematical applications.
Java Developed by Sun Microsystems, now part of Oracle. It is widely used for developing platform-
independent Internet applications.
Pascal Named for Blaise Pascal, who pioneered calculating machines in the seventeenth century. It is a
simple, structured, general-purpose language primarily for teaching programming.
Python A simple general-purpose scripting language good for writing short programs.
Visual Visual Basic was developed by Microsoft and it enables the programmers to rapidly develop
Basic graphical user interfaces.
14
Interpreting/Compiling Source Code
15
Interpreting Source Code
16
Compiling Source Code
» A compiler is a computer program that translates the entire source code into a machine-
code file, and the machine-code file is then executed, as shown in the following figure.
» A compiler should comply with the syntax rule of that programming language in which
it is written. However, the compiler is only a program and cannot fix errors found in that
program. So, if you make a mistake, you need to make changes in the syntax of your
program. Otherwise, it will not compile.
» Both compiler and interpreters do the same job which is converting higher-level
programming language to machine code. However, a compiler will convert the code into
machine code before the program run.
17
Operating Systems
18
Why Java?
» It is easy to learn
» “Write once run anywhere”, java apps can run on any system (Windows, Mac, or Linux)
» Java programmers are in demand.
» Android which is the most popular mobile OS runs on Java.
» Java is an Object-Oriented Programming Language.
» Large community support, a huge number of supporters on the web.
19
Java programming language
» It was originally developed by Sun Microsystems which was initiated by James Gosling
and released in 1995 as a core component of Sun Microsystems' Java platform (Java 1.0
[J2SE]).
» Java SE 17 is the latest release for the Java SE Platform
» The Java programming language is a high-level language that can be characterized by all
of the following buzzwords:
• Simple: syntax is based on C++ and removed many confusing instructions.
21
Java Development Process
» All source code is first written in plain text files ending with the .java extension.
» Those source files are then compiled into .class files by the javac compiler.
» A .class file does not contain code that is native to your processor, it instead
contains bytecodes of the machine language of the Java Virtual Machine (Java VM).
» With Java, you write the program once and compile the source program into a special
type of object code, known as bytecode. The bytecode can then run on any computer
with a Java Virtual Machine, as shown below. Java Virtual Machine is a software that
interprets Java bytecode
22
Creating Java Application
23
A Simple Java Program
System.out.println("Welcome to Java!");
24
Compiling and Running Java from TextPad
» Open TextPad
» Write the source code
» Ctr + 1 to Compile the code
» Ctr + 2 to the code
» What is the output ?
25
Two More Simple Examples(1)
26
Two More Simple Examples(2)
27
Anatomy of a Java Program
» Class name
» Main method
» Statements
» Statement terminator
» Reserved words
» Comments
» Blocks
28
Class Name
» Every Java program must have at least one class. Each class has a name. By convention,
class names start with an uppercase letter. In this example, the class name is Welcome.
29
Main Method
» Line 2 defines the main method. In order to run a class, the class must contain a method
named main. The program is executed from the main method.
30
Statement
31
Statement Terminator
32
Reserved words
» Reserved words or keywords are words that have a specific meaning to the compiler and
cannot be used for other purposes in the program.
» For example, when the compiler sees the word class, it understands that the word after
class is the name for the class.
33
Blocks
34
Special Symbols
" " Opening and closing Enclosing a string (i.e., sequence of characters).
quotation marks
; Semicolon Marks the end of a statement.
35
{ …}
36
(…)
37
;
38
"…"
39
Programming Errors
» Syntax Errors
• Detected by the compiler
» Runtime Errors
• Causes the program to abort
» Logic Errors
• Produces an incorrect result
40
Syntax Errors
public class ShowSyntaxErrors {
public static main(String[] args) {
System.out.println("Welcome to Java);
}
}
41
Runtime Errors
42
Logic Error
public class ShowLogicErrors {
public static void main(String[] args) {
System.out.println("Celsius 35 is Fahrenheit degree ");
System.out.println((9 / 5) * 35 + 32);
}
}
43
Exercises
44
» https://www.w3schools.com/java/default.asp
Read more…
» https://www.tutorialspoint.com/java/index.htm
» https://www.guru99.com/java-tutorial.html