Vous êtes sur la page 1sur 22

Course : 1446T - Algorithm and Programming

Introduction to Algorithm and Java Programming Session 01

Outline
Algorithm and the characteristic Programming language Six basic operation Expression of algorithm (Pseudocode and Flowchart) Introduction to Java
Java language specification and API Java Edition, JRE and JDK

Creating, compiling, and executing Simple Java program

Bina Nusantara

Algorithm
What is an algorithm?
A set of detailed, unambiguous and ordered instructions developed to describe the progress necessary to produce the desired output from a given input

Example:
If you want to instruct someone to add up a list of prices on a pocket calculator, the algorithm might be like this following sample:

Bina Nusantara

Characteristics of an Algorithm
Input Output Definiteness Finiteness Effectiveness

Bina Nusantara

Programming Language
What is programming?
Creation of program that is executable by a computer and performs the required tasks

The high-level languages are English-like and easy to learn and program The following well-known high-level languages:

Bina Nusantara

COBOL (Common Business Oriented Language) FORTRAN (FORmula TRANslation) Pascal C C++ (an object-oriented language, based on C) Java This is what we learn in this subject
6

Expression of Algorithm
An Algorithm can be expressed using some popular methods as below: Pseudocode Flowchart

Bina Nusantara

Six Basic Operations


Input Output Repetition Selection Computation Initialize or Storing value to an identifier

Bina Nusantara

Sample of a Pseudocode (1)


Example of phone calls using pseudocode.
BEGIN Hold up the phone WHILE not dial Press dial button WHILE not connected Waiting dial IF connected THEN WHILE not finish Talking Hold down the phone END

Bina Nusantara

Sample of a Pseudocode (2)


Example of Pseudocode to determine odd-even number
BEGIN Number = Input Number Result = Number % 2 IF Result = 0 THEN Print The number is even number ELSE THEN Print The number is odd number END

Bina Nusantara

10

Flowchart Symbols
The common symbols used to create a flowchart:

Bina Nusantara

11

Sample of a Flowchart (1)


Example of Phone Calling Flowchart
END

Start

Hold up the phone

Hold down the phone


Yes

Press dial button


No No

Finish

Dialing
Yes No

Talking
Yes

Waiting
Bina Nusantara

Connected 12

Sample of a Flowchart (2)


Example of Flowchart to determine odd-even number
Start

Input Number

Number % 2
1 0

Print Odd Number

Print Even Number

END
Bina Nusantara

13

Introduction to Java

Bina Nusantara

14

Java
Java was developed by a team led by James Gosling at Sun Microsystems Originally called Oak (in 1991)
Design for use in embedded chips in consumer appliance

Renamed Java (in 1995)


Re-design for developing Internet applications

Bina Nusantara

15

Java Language Specification and API


Java language specification and Java API define the Java standard. Java language specification is a technical definition of the language that includes the syntax, and semantics of the Java programming language. The application program interface (API) contains pre-defined classes and interfaces for developing Java programs. The java language specification is stable, but the API is still expanding.

Bina Nusantara

16

Java Edition and JRE


Java Edition:
Java Standard Edition (Java SE) Java Enterprise Edition (Java EE) Java Micro Edition (Java ME)

Java Runtime Environment (JRE)


A Software that execute Java based application Java Virtual Machine (JVM) is a collection of programs to execute java bytecode on any computer platform.

Bina Nusantara

17

JDK
Java Development Toolkit (JDK) consist of set of separate program, each invoked from a command line, for developing and testing Java programs. Java development tool is a software that provides an Integrated Development Environment (IDE) for rapidly developing Java programs. Example:
JBuilder by Borland (www.borland.com) NetBeans Open Source by Sun (www.netbeans.org) Eclipse Open Source by IBM (www.eclipse.org) Code Warrior by Metrowerks (www.metrowerks.com) TextPad Editor (www.textpad.com) JCreator LE (www.jcreator.com) JEdit (www.jedit.org)

Bina Nusantara

18

Most commonly application programs in JDK


Compiler: javac Interpreter: java Debugger: jdb Applet Viewer : appletviewer Documentation: javadoc Compressor: jar
Java Compiler
Compiled by generates

Welcome.java (Java source code file)

Welcome.class (Java bytecode executable fle)


Executed by

JVM

Bina Nusantara

19

Creating, Compiling, Executing


Source code (developed by the programmer) Create/Modify Source Code public class Welcome { Save on the disk Public static void main(String [] args) { Source Code System.out.println(Welcome to Java!); } } Compile Source Code e.g., javac Welcome.java Bytecode (generated by the compiler for JVM to read and interpret, not for you to understand) Method Welcome() 0 aload_0 Method void main(java.lang.String[]) 0 getstatic #2 3 ldc #3 <String Welcome to Java!> Bina5 Nusantara invokevirtual #4 8 return
If compilation errors Stored in the disk

Bytecode

Run Bytecode e.g., java Welcome

Result

If runtime errors or Incorrect result

20

Simple Java Program


// This application program prints Welcome to Java!
Class name

public class Welcome { public static void main(String [] args) { System.out.println(Welcome to Java!); } Class heading, String }
Main method signature

Filename: Welcome.java

Comments

Bina Nusantara

21

References
Daniel Liang, Y., 2011, Introduction to java programming, vol.08, Pearson Education, New Jersey. Chapter 1. Lesley Anne Robertson, 2006, Simple program design : a step by step approach, Vol.05, Course Technology.

Bina Nusantara

22

Vous aimerez peut-être aussi