Post on 01-Feb-2018
transcript
Introduction to OOP with Java
Instructor: AbuKhleif, Mohammad Noor
Sep 2017
www.abukhleif.com
Introduction
Instructor: AbuKhleif, Mohammad Noor
Sep 2017
www.abukhleif.com
Lecture 01:
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• moh.noor94@gmail.com• facebook.com/moh.noor94• twitter.com/moh_noor94
Introduction to OOP with Java - AbuKhleiF www.abukhleif.com
3
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
Let’s Start!
Introduction to OOP with Java - AbuKhleiF www.abukhleif.com
5
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Creating, Compiling,
and Running Programs
Introduction to OOP with Java - AbuKhleiF www.abukhleif.com
26
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
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
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
- 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