0% found this document useful (0 votes)
7 views

Chapter 01 Introduction To Java

Uploaded by

mohakabtan2
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Chapter 01 Introduction To Java

Uploaded by

mohakabtan2
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Chapter 01

Introduction
to Java
Contents
1. Introduction
1
1. Why Program?
2
1. Computer Systems: Hardware and Software
3
1. Programming Languages
4
1. What Is a Program Made Of?
5
1. The Programming Process
6
1. Object-Oriented Programming
7
1.1 Introduction
This book teaches programming using Java.
Java is a powerful language that runs on practically every type of
computer used to create large applications, small programs, mobile
applications, and code that powers a website.
Before plunging right into learning Java, however, this chapter will
review the fundamentals of computer hardware and software, then
take a broad look at computer programming in general.
1.2 Why Program?
Computer – programmable machine designed to
follow instructions
Program/Software – instructions that a computer
follows to perform a task
Programmer – person with the right skills who
designs, creates, and tests programs for computers
SO, without programmers, no programs; without
programs, the computer cannot do anything
Programming – an Art and Science
Computer programming is both an art and a science. It is an art because every
aspect of a program should be carefully designed. Here are a few of the things that
must be designed for any real-world computer program:
The logical flow of the The mathematical The layout of the
instructions procedures programming statements

The appearance of the The way information is The program’s “user


screens presented to the user friendliness”

Help systems and written


documentation

It is also programming is a science. Because programs rarely work right the first time they
are written, a lot of analyzing, experimenting, correcting, and redesigning is required.
1.3 Computer Systems: Hardware and Software
Hardware refers to the physical components of which a computer is made.
A computer, as we generally think of it, is not an individual device, but a
system of devices.
The major hardware components of a computer are:
A. The central processing unit (CPU)
B. Main memory
C. Secondary storage devices
D. Input and Output devices
The Central Processing Unit (CPU)
At the heart of the computer is the central processing unit(CPU)
The CPU’s job is to fetch instructions, follow instructions, and produce
some resulting data Internally, the CPU consists of two parts:
Control Unit: Coordinates all of the computer’s operations
Arithmetic and Logic Unit (ALU): Performs mathematical operations
CPU
Arithmetic
Logic
Unit

Control
Unit
Main memory
Commonly known as random-access memory (RAM)
RAM contains:
• currently running programs
• data used by those programs.
RAM is volatile, which means that when the computer is turned off, the contents of
RAM are erased.
RAM is divided into units called bytes.
A byte consists of eight bits that may be either on or off.
Each byte in memory is assigned a unique number known as an address.

The number 149 is stored in the byte at address 16


Secondary Storage
Secondary storage devices are capable of storing
information for longer periods of time (non-volatile).
Common Secondary Storage devices:

Secondary Storage

Solid
Hard Disk
State USB Optical
Drivers(H CD/DVD
Drive(SSD Drive Device
DD)
)
Input Devices
Input is any data the computer collects from the outside world.
That data comes from devices known as input devices.
Common input devices:
Common input devices

Keyboa Mous Digital


Scann
rd e er
Camer USB
a
Output Devices
Output is any data the computer sends to the outside world.
That data is displayed on devices known as output devices.
Common output devices:
Common output devices

CD/ printe Disk


Monitors USB
DVD rs Drives
Computer Systems: Software
Software refers to the programs that run on a computer.
There are two classifications of software:
Software Classifications

System Application
Utility Program
Software Software

Windo MAC LINU databa Wor Exc Antivir


IDE
w OS X se d el us
1.4 Programming Languages
A program is a set of instructions a computer follows in order to
perform a task.
A programming language is a special language used to write
computer programs. Computers are designed to follow
instructions.
A computer program is a set of instructions that enable the
computer to solve a problem or perform a task
Collectively, these instructions form an algorithm
An algorithm is a set of well-defined steps for performing a task
or solving a problem.
The steps in an algorithm are performed sequentially.
A History of Java
• 1991 - Green Team started by Sun Microsystems (now owned
by Oracle).
• Their first project was to develop a handheld device named
*7(“star seven”) that could be used to control a variety of home
entertainment devices
• There was a need for a programming language that would run
on various devices.
• Java (first named Oak) was developed for this purpose.
Continue,……
• Java enabled web browser (HotJava) demonstrated at 1995
Sun World conference.
• Java incorporated into Netscape shortly after.
• Java is “cross platform”, meaning that it can run on various
computer operating systems.
Types of Java

Java Applications Java Applets


1.5 What Is a Program Made Of?
The Compiler and the Java Virtual Machine
• A programmer writes Java programming statements.
• These statements are known as source code.
• A text editor is used to edit and save a Java source code file.
• Source code files have a .java file extension.
• A compiler is a program that translates source code into an
executable form.
• During the translation process, the compiler uncovers any syntax
errors that may be in the program.
• Syntax errors are mistakes that the programmer has made that
violate the rules of the programming language.
Continue,….
• The Java compiler translates a Java source file
into a file that contains byte code instructions.
• Byte code instructions are the machine language
of the Java Virtual Machine (JVM) and cannot be
directly executed directly by the CPU.
• Byte code files end with the .class file extension.
• (JVM) is a program that reads Java byte code
instructions and executes them as they are read.
• JVM is often called an interpreter.
• Java is often referred to as an interpreted language.
Portability
• The term portable means that a program
may be written on one type of computer then
run on a wide variety of computers, with little
or no required modification.
• Because Java byte code is the same on all
computers, compiled Java programs are highly
portable. In fact, a compiled Java program
may be run on any computer that has a Java
Compiling a Java Program
• The Java compiler is a command line utility.
• The command to compile a program is:
javac filename.java
• javac is the Java compiler.
• The .java file extension must be used.
Example: Payroll.java you would use the
command:
javac Payroll.java
Running Java Program
• To run the Java program, we use java command in the following form:
• java Filename
• Filename is the name of the .class file that you wish to
execute.
–However, you do not type the .class extension.
• For example, to run the program that is stored in the
Payroll.class file, you would enter the following command:
java Payroll
–This command runs the Java interpreter (the JVM) and executes
the program.
Integrated Development(IDE)
In addition to the command prompt, there are also several Java integrated
development environments (IDEs). These environments consist of a text editor,
compiler, debugger, and other utilities integrated into a package with a single set of
menus. A program is compiled and executed with a single click of a button, or by
selecting a single item from a menu

IntelliJ IDE NetBeans Eclipse

NodePade++ VS Code JDeveloper


1.6 The Programming Process
The programming process consists of several steps which include designing,
creating, testing, and debugging activities.
1. Clearly define what the program is to do.
2. Visualize the program running on the computer.
3. Use design tools to create a model of the program.
4. Check the model for logical errors.
5. Enter the code and compile it.
6. Correct any errors found during compilation.
Repeat Steps 5 and 6 as many times as necessary.
7. Run the program with test data for input.
8. Correct any runtime errors found while running the program.
Repeat Steps 5 through 8 as many times as necessary.
9. Validate the results of the program.
1.7 Object-Oriented Programming
Java is an object-oriented programming (OOP) language.
Server
Applications
OOP is a method of software development that has its own
practices, concepts, and vocabulary.
Programming Language
Procedural Object Oriented
Programming Programming

Pasca Pyth
C VB.net C++ Java
l on
Continue,…
A class is a collection of programming statements that specify the attributes
and methods that a particular type of object may have.
Think of a class as a “blueprint” that objects may be created from.
So, a class is not an object, but a description of an object

Methods
Or Behaviors
Inheritance
Inheritance is the ability of one class to extend the capabilities of another.
Server
For example, consider a program that uses classes representing cars, trucks,
and jet planes. Applications
Although those three types of objects in the real world are very
different, they have some common characteristics.
They are all modes of transportation, and they all can carry some number
of passengers. So, each of the three classes could be based on a Vehicle
class
In OOP terminology, the Vehicle
class is the superclass.
The Car, Truck, and JetPlane
classes are subclasses.
ANY
QUESTIONS
‫و ا ل س ال م ع ل ي ك م‬
‫ورحمة الله‬
‫ه‬ ‫ت‬ ‫ا‬
Eng.Mahad Ahmed
‫ك‬ ‫ر‬ ‫ب‬ ‫و‬
Jimale
+252-618-95-95-95
[email protected]

You might also like