Introduction to OOP with Java - AKF Sep 2017 AbuKhleiF - www.abukhleif.com 1 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:
15
Embed
Introduction to OOP with Java - Abu Khleif | …abukhleif.com/.../AKF_Introduction_to_OPP_using_Java_Lect01_2pp.pdf · Delphi/Object Pascal, 1.78% Swift, 1.77% Visual Basic, 1.75%
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
• 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 - AKF Sep 2017
AbuKhleiF - www.abukhleif.com 4
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
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 - AKF Sep 2017
AbuKhleiF - www.abukhleif.com 5
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;
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 - AKF Sep 2017
AbuKhleiF - www.abukhleif.com 6
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.
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 - AKF Sep 2017
AbuKhleiF - www.abukhleif.com 7
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:
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 - AKF Sep 2017
AbuKhleiF - www.abukhleif.com 8
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++
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
• 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
• 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!");
}
}
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 - AKF Sep 2017
AbuKhleiF - www.abukhleif.com 13
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!");
}
}
Creating, Compiling,
and Running Programs
Introduction to OOP with Java - AKF Sep 2017
AbuKhleiF - www.abukhleif.com 14
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.
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/