introduction to oop with java -...

30
Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor Sep 2017 www.abukhleif.com

Upload: truongtu

Post on 01-Feb-2018

253 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Introduction to OOP with Java

Instructor: AbuKhleif, Mohammad Noor

Sep 2017

www.abukhleif.com

Page 2: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Introduction

Instructor: AbuKhleif, Mohammad Noor

Sep 2017

www.abukhleif.com

Lecture 01:

Page 3: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Instructor

• AbuKhleif, ‘Mohammad Noor’• Studied Computer Engineer (JU 2012-2017)• Works as a Software Automation Engineer @ Atypon –

John Wiley and Sons Company - Jordan Branch

• Reach me at:• www.abukhleif.com• [email protected]• facebook.com/moh.noor94• twitter.com/moh_noor94

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

3

Page 4: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Course

• Java SE Basics• Object Oriented Programming• Course Page:

www.abukhleif.com/courses/java-101-sep-2017• Or, go to: www.abukhleif.com Courses Java 101 Course

– Sep 2017• Course Facebook Group:

www.facebook.com/groups/AKF2017Java

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

4

Page 5: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Let’s Start!

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

5

Page 6: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

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.

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

6

Page 7: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Programming LanguagesMachine 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:

1101101010011010

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

7

Page 8: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Programming LanguagesAssembly (Low 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

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

8

Page 9: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Programming LanguagesHigh Level Languages

• The high-level languages are English-like and easy to learn and program.

• For example, the following is a high-level language statement that computes the area of a circle with radius 5:

area = 5 * 5 * 3.1415;

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

9

Page 10: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Java, 12.69%

C, 7.38%

C++, 5.57%

C#, 4.78%

Python, 2.98%

PHP, 2.21%

JavaScript, 2.02%

Visual Basic .NET, 1.98%

Perl, 1.95%

Ruby, 1.93%

R, 1.82%

Delphi/Object Pascal, 1.78%

Swift, 1.77%

Visual Basic, 1.75%

Assembly language, 1.64%

MATLAB, 1.63%

Go, 1.57%

Objective-C, 1.51%

PL/SQL, 1.48%

0.00%

2.00%

4.00%

6.00%

8.00%

10.00%

12.00%

14.00%

POPULAR HIGH-LEVEL LANGUAGES

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

10

Page 11: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Interpreting/Compiling Source Code

•A program written in a high-level language is called a source program or source code.

•Because a computer cannot understand a source program, a source program must be translated into machine code for execution.

• The translation can be done using another programming tool called an interpreter or a compiler.

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

11

Page 12: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Interpreting Source Code

• An interpreter reads one statement from the source code, translates it to the machine code or virtual machine code, and then executes it right away, as shown in the following figure:

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

12

Page 13: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Compiling Source Code

• A compiler translates the entire source code into a machine-code file, and the machine-code file is then executed, as shown in the following figure:

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

13

Page 14: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Why Java?

• You paid for a Java course

• It’s the current “hot” language

• Java enables users to develop and deploy applications on the

Internet for servers, desktop computers, and small hand-held

devices

• It’s platform independent• this makes it great for Web programming

• It has a vast library of predefined objects and operations

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

14

Page 15: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Why Java?

• Java is a general purpose programming language.

• Java is the Internet programming language.

• It’s almost entirely object-oriented

• It’s more secure

• It isn’t C++

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

15

Page 16: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Why Java?

• Java Is Simple

• Java Is Object-Oriented

• Java Is Distributed

• Java Is Interpreted

• Java Is Secure

• Java Is Portable• Please, read about Java characteristics here:www.cs.armstrong.edu/liang/JavaCharacteristics.pdf

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

16

Page 17: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Java Editions

Java Standard Edition (Java SE)

to develop client-side standalone applications or

applets.

Java Enterprise Edition (Java EE)

to develop server-side

applications.

Java Micro Edition (Java ME)

to develop applications for mobile devices.

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

17

Page 18: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

JDK

• The Java Development Kit (JDK) consists of a set of separate programs, each invoked from command line, for developing and testing Java programs.

• Download Page:

www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

18

Page 19: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

JDK Versions

JDK 1.02 (1995)

JDK 1.1 (1996)

JDK 1.2 (1998)

JDK 1.3 (2000)

JDK 1.4 (2002)

JDK 1.5 (2004) a. k. a. JDK 5 or Java 5

JDK 1.6 (2006) a. k. a. JDK 6 or Java 6

JDK 1.7 (2011) a. k. a. JDK 7 or Java 7

JDK 1.8 (2014) a. k. a. JDK 8 or Java 8

JDK 1.9 (Coming in 2017) a. k. a. JDK 9 or Java 9

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

19

Page 20: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

IDE

• The Integrated Development Kit (IDE) provides graphical user interface to edit, compile, build, and debug programs.

• Popular Java IDEs:

• NetBeans (Open Source)

• Eclipse (Open Source)

• IntelliJ IDEA (Free and Enterprise Editions)

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

20

Page 21: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Download IntelliJ IDEA

• Download Page: jetbrains.com/idea/download/

• Choose your OS (Windows?)

• Choose your version (Community?)

• Download!

• Want help? Please refer to this page:

www.jetbrains.com/help/idea/installing-and-launching.html

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

21

Page 22: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Welcome to Java

• Java source programs are case sensitive.• Every Java program must have at least one class.• Each class has a name. By convention, class names start with an uppercase

letter.• The main method is the entry point where the program begins execution.• A class may contain several methods. A method is a construct that contains

statements.

// This program prints Welcome to Java!

public class Welcome {

public static void main(String[] args) {

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

}

}

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

22

Page 23: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Welcome to Java

• A pair of curly braces { } in a program forms a block that groups the program’s component.

• Every class has a class block that groups the data and methods of the class.

• Every method has a method block that groups the statements in the method.

// This program prints Welcome to Java!

public class Welcome {

public static void main(String[] args) {

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

}

}

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

23

Page 24: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Welcome to Java

• The System.out.println statement displays the string Welcome to Java on the console.

• A String is a sequence of characters. Strings should be enclosed in double quotation marks.

• Every statement in Java ends with a semicolon (;).• public, class, static, and void are reserved words : have a specific meaning to

the compiler and cannot be used for other purposes. In the program.

// This program prints Welcome to Java!

public class Welcome {

public static void main(String[] args) {

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

}

}

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

24

Page 25: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Welcome to Java

• Comments are ignored by the compiler.

• Two types of comments:

• Line comments: preceded by two slashes (//).

• Block (or paragraph) comments: enclosed between (/*) and (*/)

• Documentation comments: enclosed between (/**) and (*/)

// This program prints Welcome to Java!

public class Welcome {

public static void main(String[] args) {

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

}

}

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

25

Page 26: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Creating, Compiling,

and Running Programs

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

26

Page 27: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Creating, Compiling,

and Running Programs

• Java source code is compiled into Java bytecode

• Your Java code may use the code in the Java library

• The bytecode is similar to machine instructions, but is architecture neutral and can run on any platform that has a Java Virtual Machine (JVM)

• The JVM is an interpreter, which translates individual instructions in the bytecode into the target machine language code and executes it immediately.

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

27

Page 28: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Creating, Compiling,

and Running Programs

• Practically, you can do this on your PC using:• Any text editor to write and save your java file.

• DOS / Windows CMD / Linux Terminal / … to compile and run your program.

• To do that, refer to these links:• facweb.cs.depaul.edu/noriko/JavaSetup/

• stackoverflow.com/a/26693191

• But, believe me, you don't want this headache.

• Instead, let’s use IntelliJ IDEA

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

28

Page 29: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

Let’s Code

•Write a Java program that print your name and age to the console.

Introduction to OOP with Java - AbuKhleiF www.abukhleif.com

29

Page 30: Introduction to OOP with Java - abukhleif.comabukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_1pp.pdf · Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor

- Liang, Introduction to Java Programming 10/e- Eng. Asma Abdel Karim Computer Engineering Department, JU Slides- www.tiobe.com/tiobe-index

Instructor: AbuKhleif, Mohammad Noor

Sep 2017

www.abukhleif.com

References:

End of Lecture =D