Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor Sep 2017
Lecture 01: Introduction Instructor: AbuKhleif, Mohammad Noor Sep 2017
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: moh.noor94@gmail.com facebook.com/moh.noor94 twitter.com/moh_noor94 3
Course Java SE Basics Object Oriented Programming Course Page: /courses/java-101-sep-2017 Or, go to: Courses Java 101 Course Sep 2017 Course Facebook Group: www.facebook.com/groups/akf2017java 4
Let s Start! 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. 6
Programming Languages Machine 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 7
Programming Languages Assembly (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 8
Programming Languages High 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; 9
POPULAR HIGH-LEVEL LANGUAGES 14.00% 12.00% Java, 12.69% 10.00% 8.00% C, 7.38% 6.00% 4.00% 2.00% C++, 5.57% C#, 4.78% Python, 2.98% PHP, 2.21% JavaScript, 2.02% Ruby, 1.93% Visual Basic.NET, 1.98% Perl, 1.95% Delphi/Object Pascal, 1.78% R, 1.82% Objective-C, 1.51% Assembly language, 1.64% Visual Basic, 1.75% Go, 1.57% Swift, 1.77% MATLAB, 1.63% PL/SQL, 1.48% 0.00% 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. 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: 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: 13
You paid for a Java course Why Java? 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 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++ 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 16
Java Standard Edition (Java SE) Java Enterprise Edition (Java EE) Java Micro Edition (Java ME) to develop clientside standalone applications or applets. to develop server-side applications. to develop applications for mobile devices. Java Editions 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 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 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) 20
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-andlaunching.html Download IntelliJ IDEA 21
Welcome to Java // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("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. 22
Welcome to Java // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("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. 23
Welcome to Java // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("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. 24
Welcome to Java // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("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 (*/) 25
Creating, Compiling, and Running Programs 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. 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 28
Let s Code Write a Java program that print your name and age to the console. 29
References: - 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 End of Lecture =D