+ All Categories
Home > Documents > Materi 01 - Introduction to Java Programming

Materi 01 - Introduction to Java Programming

Date post: 12-Dec-2015
Category:
Upload: ratna-d-anjani
View: 233 times
Download: 3 times
Share this document with a friend
Description:
pengenalan bahasa pemrograman java
Popular Tags:
35
Introduction to Java Programming Y. Daniel Liang
Transcript
Page 1: Materi 01 - Introduction to Java Programming

Introduction toJava Programming

Y. Daniel Liang

Page 2: Materi 01 - Introduction to Java Programming

Introduction What is a computer?

– Electronic devices that stores and process data– Includes both hardware and software

Hardware – physical aspects that you can see– Central Processing Unit (CPU)– Memory (main memory)– Storage Devices (hard disk, floppy disk, CDs, tapes)– Input and Output Devices (monitors, keyboards, mice,

printers)– Communication Devices (modems and network

interface cards)

Page 3: Materi 01 - Introduction to Java Programming

Hardware Central Processing Unit (CPU)

– Brain of a computer – Retrieves instructions from memory and executes them– 2 components:

control unit – controls and coordinates the actions of the other components

arithmetic/logic unit– perform numeric operations (addition, subtraction,

multiplication, division)– Perform logic operations (comparison)

Built on semiconductor chip with millions of transistors

Page 4: Materi 01 - Introduction to Java Programming

Hardware

Memory (main memory)– Data are encoded as a series of bits.– Bit – binary digit: zero and one– Stores data and program instructions for CPU

to execute– A memory unit is an ordered sequence of bytes,

each holding 8 bits– Encoding scheme: ASCII

Page 5: Materi 01 - Introduction to Java Programming

Hardware Memory (main memory)

– A program and its data must be brought to memory before they can be executed

– The content of memory is lost when new infor is placed in it.

– Each byte has a unique address, used to locate the byte.– Can be accessed in any order, thus is called RAM

(Random-access memory)– 1 Megabyte (MB) is about 1 million bytes.– Also built on silicon semiconductor ships containing

thousands of transistors, but less complicated.– Memory is volatile, the content is lost when the power

is turned off.

Page 6: Materi 01 - Introduction to Java Programming

Hardware Storage Devices (hard disk, floppy disk, CDs,

tapes)– Programs and data are stored permanently on storage

devices and moved to memory when computer actually uses them.

– 4 main types of storage devices: Disk drives (hard disks, floppy disks) CD drives (CD-R, CD-RW, DVD). DVD stands for Digital

versatile disc. Tape drives USB flash drives

Page 7: Materi 01 - Introduction to Java Programming

Hardware

Input and Output Devices (monitors, keyboards, mice, printers)– Allows user to communicate with the computer– Common input devices: keyboards, mice– Common output devices: monitors, printers.

Page 8: Materi 01 - Introduction to Java Programming

Hardware

Communication Devices (modems and network interface cards)– To create network of computers

Page 9: Materi 01 - Introduction to Java Programming

Software Software/computer program

– invisible instructions that control the hardware and make it perform specific tasks.

– Tell computer what to do in computer/machine language

Page 10: Materi 01 - Introduction to Java Programming

Software Computer languages

1. Machine language

2. Assembly language

3. High level language

Page 11: Materi 01 - Introduction to Java Programming

Software

Machine language – a set of primitive instructions built into every

computer– Different for different types of computers.– The instructions are in the form of binary code,

e.g. to add 2 numbers (very tedious): 1101101010011010

Page 12: Materi 01 - Introduction to Java Programming

Software

Assembly language– Low-level programming language which uses

mnemonic to represent machine-language instructions

– E.g.: ADDF3 R1, R2, R3– Assembly code need to be converted into

machine code by using an assembler– Assembly program

is platform dependent Combination of mnemonic and machine instruction

Page 13: Materi 01 - Introduction to Java Programming

Software

High-level language– English-like and easy to learn and program.– E.g.:

Area = 5 * 5 * 3.1415;

– COBOL, FORTRAN, BASIC, Pascal, Ada, C, Visual Basic, Delphi, C++, C#, Java

– Source program is compiled into machine code by a compiler and linked to supporting library code by a linker to form an executable file. Fig. 1.4

Page 14: Materi 01 - Introduction to Java Programming

Software

High-level language (continue)– Can port/move a source program to any

machine with appropriate compilers but the source program must be recompiled

– Java program, compiled it once into intermediate machine code known as bytecode. Bring the bytecode to any computer with a JVM (Java Virtual Machine). JVM interprets the bytecode into the machine codes and execute them.

Page 15: Materi 01 - Introduction to Java Programming

An overview of the java development process.

Source: http://java.sun.com/docs/books/tutorial/getStarted/intro/definition.html

Page 16: Materi 01 - Introduction to Java Programming

Through the Java VM, the same application is capable of running on multiple platforms.

Source: http://java.sun.com/docs/books/tutorial/getStarted/intro/definition.html

Page 17: Materi 01 - Introduction to Java Programming

Software

Compiling versus interpreting– Compiling translates the high-level code into a

target language code as a single unit– Interpreting translates the individual steps in

the high level code one at a time. Each step is execute immediately after it is translated.

Page 18: Materi 01 - Introduction to Java Programming

Software Operating system (OS)

– Software that controls and manages the systems– Fig. 1.6, page 36.– E.g.: Windows (98, NT, XP, ME), MacOS, Linux etc.– Major tasks

Controlling and monitoring system activities (security, input, output, file directories, make sure programs running together do not interfere with each other)

Allocating and assigning system resources to program Scheduling operations

– Multiprogramming – multiple programs to run simultaneously by sharing CPU

– Multithreading – allows concurrency within a program; it subunits can run at the same time (e.g. editing and saving at the same time)

– Multiprocessing/parallel processing – use 2 or more processors together to perform a task.

Page 19: Materi 01 - Introduction to Java Programming

What Is Java?

History

Characteristics of Java

Page 20: Materi 01 - Introduction to Java Programming

History James Gosling

Oak – 1991, for embedded consumer electronic appliances

Renamed Java, 1995, for developing Internet applications

HotJava – The first Java-enabled Web browser

Java applets – java programs that run from a Web browser

– http://javaboutique.internet.com/movingtree/

Page 21: Materi 01 - Introduction to Java Programming

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

Page 22: Materi 01 - Introduction to Java Programming

Java IDE Tools Inprise JBuilder

Microsoft Visual J++

Symantec Café

Forte by Sun MicroSystems

IBM Visual Age for Java

NetBeans 6.0 (free, open-source IDE, runs on Windows, Linux, Solaris, and the MacOS)

JCreator LE 4.0 (free) by Xinox Software

Page 23: Materi 01 - Introduction to Java Programming

Java Language Specification, API, JDK and IDE

Java Language Specification– Technical definition of the language which includes the

syntax and semantics of the Java Programming language (java.sun.com/docs/books/jls)

API– Contains predefined classes and interfaces for

developing Java programs.

– 3 editions of Java API J2SE - version Java SE 6.0 (jdk1.6.0_02) J2EE J2ME

Page 24: Materi 01 - Introduction to Java Programming

Java Language Specification, API, JDK and IDE

JDK– A set of programs for developing and testing

Java program, each of which is invoked from a command line.

IDE (integrated development environment)– Software that provides integrated development

environment (editing, compiling, building, debugging and online help) for rapidly developing Java program

Page 25: Materi 01 - Introduction to Java Programming

Getting Started with Java Programming

A Simple Java Application

Compiling Programs

Executing Applications

Page 26: Materi 01 - Introduction to Java Programming

A Simple Application

Example 1.1//This application program prints Welcome

//to Java! public class Welcome { public static void main(String[] args) {

System.out.println("Welcome to Java!"); }}

RunRunSourceSource

Page 27: Materi 01 - Introduction to Java Programming

Creating, compiling and executing a Java Programs

Fig. 1.11, page: 44.

Page 28: Materi 01 - Introduction to Java Programming

Compiling Programs

On command line– javac file.java

Page 29: Materi 01 - Introduction to Java Programming

Executing Applications

On command line– java classname

JavaInterpreter

on Windows

JavaInterpreter

on Sun Solaris

JavaInterpreteron Linux

Bytecode

...

Page 30: Materi 01 - Introduction to Java Programming

Example

javac Welcome.java

java Welcome

output:...

Page 31: Materi 01 - Introduction to Java Programming

Anatomy of a Java program

Comments Reserved words Modifier Statement Block Class Method The main method

Page 32: Materi 01 - Introduction to Java Programming

Anatomy of a Java program Comments

– Documents the program for understanding purpose

– Ignored by compiler

– //

– /* */

Reserved words or keywords– Words that have specific meaning to the compiler and

cannot be used for other purposes in the program

– E.g: public, static, class, void

Page 33: Materi 01 - Introduction to Java Programming

Anatomy of a Java program Modifier

– Certain reserved words are modifiers that specify the properties of the data, methods and class and how they can be used.

– E.g: public, private, static, final, abstract, protected. Statement

– Represents an action or a sequence of actions– Ends with semicolon (;)

Block– Groups the components of the program– Begins with opening brace { and ends with a closing

brace }– Class block, method block

Page 34: Materi 01 - Introduction to Java Programming

Anatomy of a Java program Class

– Program is defined by using one or more class– Will be covered in more details later.

Method– A collection of statements that perform a sequence of

operations.– Can be used without fully understanding how it works.– Invoke by calling the method name with the

requirement argument The main method

– A special method where the program execution begins.– JVM invokes the main method to execute an

application.

Page 35: Materi 01 - Introduction to Java Programming

Summary


Recommended