31
Name of Course : Introduction to Java Programming Lecturer : Alexander Shkolnik E- mail: [email protected] Office Hours : Sun 14:00 - 16:00 build 37,room 520 Course number : 202.1.9031 Credits : 4 Course Site : http://www.cs.bgu.ac.il/~ ipc151 1

Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

  • Upload
    others

  • View
    14

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Name of Course : Introduction to Java Programming

Lecturer : Alexander ShkolnikE- mail: [email protected]

Office Hours : Sun 14:00 - 16:00 build 37,room 520

Course number : 202.1.9031

Credits : 4

Course Site : http://www.cs.bgu.ac.il/~ipc151

1

Page 2: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Course Objectives• The main purpose of the course - introduction to Java language

programming methods, based on new approaches in computer science.

• On the first part of the course students will acquire procedural

programming: software development technique that imposes a hierarchical

structure on the design of the programs. On the second part of the course

students will learn the principles of object-oriented programming (OOP):

programming technique based on objects.

• Students will learn operation system Windows 7 and Integrated

Development Environment (IDE) Eclipse, which provides first – class Java

programming tools.

• The course includes: algorithm building principles, basic Java commands,

control structure, arrays, different kinds of methods (including recursion

methods), principles of object-oriented programming (OOP), collections,

dynamic data structures and files manipulations.

2

Page 3: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Course requirements :• 1. 13 x 3 hours lectures

• 2. 13 x 2 hours (4 x 2 lab, 9 x 2 frontal) practical lessons

• 3. 4 programming assignments (about 20 hours each)

(every assignment 7.5% of the final grade).

Submissions: alone only.

• 4. Final exam 3 hours long (70% of final grade,

a "Pass" requirement regarding final exam: 56) .

No auxiliary material allowed, except for a single two-sided

A4 paper sheet (neither printed nor copied).

3

Page 4: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Our course site

4

http://www.cs.bgu.ac.il/~ipc151/Main

Page 5: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Review computer basics

User

Application Programs

Operating System

Hardware

5

Page 6: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Computer Structure

CPU

Internal Memory

InputOutput

MouseKeyboardMicrophoneDetectors

MonitorSpeakersMotors

External Memory

Hard DiskCD / DVDTapeDiskOnKey

6

Page 7: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

CPU ( מעבד )

The Central Processing Unit (CPU) is the brain of a computer.

It retrieves instructions from memory and executes them. The CPU speed is

measured in megahertz (MHz), with 1 megahertz equaling 1 million pulses per second. The speed of the CPU has been improved continuously.

CPU

e.g., Disk, CD,

and Tape

Input

Devices

e.g., Keyboard,

Mouse

e.g., Monitor,

Printer

Communication

Devices

e.g., Modem,

and NIC

Storage

Devices

Memory Output

Devices

Bus

7

Page 8: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Memory ( זיכרון )Memory is to store data and program instructions for CPU to execute.

A memory unit is an ordered sequence of bytes, each holds eight bits. A

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

executed. A memory byte is never empty, but its initial content may be

meaningless to your program. The current content of a memory byte is lost

whenever new information is placed in it.

CPU

e.g., Disk, CD,

and Tape

Input

Devices

e.g., Keyboard,

Mouse

e.g., Monitor,

Printer

Communication

Devices

e.g., Modem,

and NIC

Storage

Devices

Memory Output

Devices

Bus

8

Page 9: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Memory Unit : Byte• Byte (בית) is a unit of digital information.

It is an ordered collection of 8 bits ( binary

digit), in which each bit denotes the binary

value of 1 or 0.

• number of bits (סיביות) used to encode a character of text in the computer, which depended on computer hardware architecture.

• A byte can represent 28 = 256 distinct values, such as the integers from 0 to 255

• ASCII (American Standard Code for Information Interchange).

9

Page 10: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

How Data is Stored?

Data of various kinds, such as numbers, characters, and strings, are encoded as a series of bits (zeros and ones).

Computers use zeros and ones because digital devices have two stable states, which are referred to as zero and one by convention. The programmers need not to be concerned about the encoding and decoding of data, which is performed automatically by the system based on the encoding scheme.

A byte is the minimum storage unit.

.

.

.

2000

2001

2002

2003

2004

.

.

.

01001010

01100001

01110110

01100001

00000011

Memory content

Memory address

Encoding for character ‘J’ Encoding for character ‘a’ Encoding for character ‘v’ Encoding for character ‘a’ Encoding for number 3

1 KB = 1,024 bytes

1 MB = 1,048,576 bytes

1 GB = 1,073,741,824 bytes

10

Page 11: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Storage Devices ( התקני אחסון )Memory is volatile (נדיף), because 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.

There are three main types of storage devices: Disk drives, CD drives and

Tape drives.

CPU

e.g., Disk, CD,

and Tape

Input

Devices

e.g., Keyboard,

Mouse

e.g., Monitor,

Printer

Communication

Devices

e.g., Modem,

and NIC

Storage

Devices

Memory Output

Devices

Bus

11

Page 12: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Operating system ( מערכת ההפעלה )

• An operating system ( OS ) is a software program that enables the

computer hardware to communicate and operate with the computer

software.

• An operating system also has a vital role to play in security. Its job

includes preventing unauthorized users from accessing the computer

system.

• Examples of popular modern operating systems include Microsoft

Windows, Android,, Linux, Mac OS X, and IBM z/OS.

12

Page 13: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Operating system, cont.

At the simplest level, an operating system does two things:

1. It manages the hardware and software resources of the computer

system. These resources include such things as the processor, memory,

disk space, etc.

2. It provides a stable, consistent way for applications to deal with the

hardware without having to know all the details of the hardware.

Today's major operating systems provide a

Graphical User Interface - GUI.

ממשק משתמש להפעלת גרפיקה ) )

Elements of a GUI include such things as:

windows, pull-down menus, buttons, scroll bars,

iconic images.13

Page 14: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Programs◘ Computer programs, known as software, are

instructions to the computer.

You tell a computer what to do through programs.

Without programs, a computer is an empty machine.

Computers do not understand human languages, so

you need to use computer languages to communicate

with them.

◘ Programs are written using programming

languages ( שפות תכנות).

LispPascal

VB

CJavaC++

14

Page 15: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

High level languages vs. machine languages

שפת מכונה

שפת סף

שפת עלית

15

Page 16: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Programming LanguagesMachine Language Assembly Language High-Level Language

Machine language is a set of primitive instructions built into every computer. The instructions are in the form of binary code, so you have to enter binary codes for various instructions.

Program with native machine language is a tedious process. Moreover the programs are highly difficult to read and modify.

For example: to add two numbers, you might write an

instruction in binary like this:

110110101001101016

Page 17: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Programming LanguagesMachine Language Assembly Language High-Level Language

Assembly languages were developed to make programming easy. Since the computer cannot understand assembly language, however, a program called assembler is used to convert assembly language programs into machine code. For example:

to add two numbers, you might write an instruction in

assembly code like this:

ADDF3 R1, R2, R3

… ADDF3 R1, R2, R3

Assembly Source File

Assembler

… 1101101010011010

Machine Code File

17

Page 18: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Programming Languages

Machine Language Assembly Language High-Level Language

The high-level languages are English-like and easy to

learn and program.

For example 1: the following is a high-level language

statement that computes the area of a circle with

radius 5:

area = 5 * 5 * 3.1415;

For example 2: the following is a high-level language

statement that prints the string:

PRINT(“Welcome to Java course”);

18

Page 19: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Algorithm ( אלגוריתם )

An algorithm is a procedure or formula for

solving a problem.

The word derives from the name of the mathematician,

Mohammed ibn - Musa al - Khwarizmi, who was part of the

royal court in Baghdad and who lived from about 780 to 850.

Al-Khwarizmi's work is the likely source for the word algebra

as well.

Algorithms are implementation-

independent.

19

Page 20: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Basic computer operators

• INPUT/OUTPUT ( פלט/אפרטורים קלט ) operators

• ASSIGNMENT ( אופרטורים השמה ) operators

• ARITHMETIC ( אופרטורים חשבון ) operators

• SELECTION אופרטורים בחירה ) ( operators

• PROGRAM CONTROL ( שינוי סדר הוראות ) operators

20

Page 21: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

THREE INTEGER’S MAX VALUE(FLOWCHART)

22

Page 22: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

THREE INTEGER’S MAX VALUE( PSEUDOCODE )

ABשלושה מספרים למשתנים קלוט.1 C-ו,

MAXלמשתנה Aערך של השם. 2

MAX–ל Bערך של השםאזB > MAXאם. 3

MAX–ל Cערך של השםאזC > MAXאם. 4

MAXערכו של הדפס. 5

23

Page 23: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

THREE INTEGER’S MAX VALUE

( Java program )

24

Page 24: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Software Development Process

• Understand Problem Definition

• Generalize & Decompose the problem

definition

• Develop Solution Algorithm

• Write the Java program Code

• Test and Debug the program

25

Page 25: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Why Java?

The answer is that Java enables users to develop and

deploy applications on the Internet for servers, desktop

computers, and small hand-held devices.

The future of computing is being profoundly influenced

by the Internet, and Java promises to remain a big part

of that future. Java is the Internet programming

language.

Java is a general purpose programming language.

Java is the Internet programming language.

26

Page 26: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

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

27

Page 27: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Important Java Concepts and Terminology

• JRE is the Java Runtime Environment and it creates a virtual machine within your

computer known as the JVM (Java Virtual Machine).

JRE is specific to your platform and is the environment in which Java byte code is

run.

• JDK (formerly SDK) is the Java Development Kit.

JDK = JRE + development tools.

▪ IDE is the Integrated Development Environment, have been created to support the

development of Java programs.

IDEs combine an editor, compiler and other Java support tools

into a single application (Eclipse in this course).

• To learn more about JDK, JRE, IDE etc., visit

http://java.sun.com/javase/technologies/index.jsp

28

Page 28: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Running and Compiling C/C++

C++ Code

Linux binary

Windowsbinary

Linux executable

Windowsexecutable

Project Library for Linux

Project Library for Windows

Linux C/C++ linker

Windows C/C++ linker

29

Page 29: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Running and Compiling Java

JavaCode

JavaBytecode

JRE for Linux

JRE for Windows

Java compiler

Hello.java

javac Hello.java

Hello.class

Java interpreter translates bytecode to machine

code in JRE

JRE (Java Runtime Environment ) is the base set of

data files and programs (executables) which are

required to run Java Applications.

Java bytecode is the form of

instructions that the JVM executes

30

Page 30: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Eclipse• Eclipse is a multi-language software development

environment comprising an Integrated Development

Environment (IDE) .

• It is written mostly in Java.

• Before you can work with Eclipse, you'll need to download the

Java Development Kit (JDK).

• Eclipse is free software:

http://www.eclipse.org/downloads

31

Page 31: Name of Course : Introduction to Java Programmingipc151/wiki.files/Class_Java_1.pdf · 2014-10-06 · Memory Unit : Byte • Byte (תיב) is a unit of digital information. It is

Programming Errors• Syntax Errors ( דיקדוקשגיאות (

Java, like all other programming languages, has its own syntax.

Syntax errors are a type of compiler error. This means they will be

detected immediately when the programmer tries to convert his source

code into a program.

For example: one rule of Java syntax is that all commands must end with

a semicolon (;).

• Runtime Errors ( ריצהזמןשגיאות )

A runtime error means an error which happens, while the program is

running. Causes the program to abort.

• Logic Errors ( לוגיותשגיאות )

These kinds of errors are a lot harder to fix, because you don't necessarily

know what causes the error. Produces incorrect result.

32