Classification of Programming Languages Based on How … · 2 Compiler – Compilers vs....
Transcript of Classification of Programming Languages Based on How … · 2 Compiler – Compilers vs....
1
Classification ofProgramming Languages
Based on How TheyDerive Machine Code
222
Compiler –
Compilers vs. Interpreters
computer program that transforms source code written in one computer language to equivalent code in anotherlanguage
A compiler must translate an entire program into machine code before
the program can be executed.
• compiled languages: C, C++, Eiffel, Fortran, Crystal, …• most commonly it is translation from a high-level to a machine lang.
3
COMMERCIAL COMPILER
4
http://www.slideshare.net/darokoblog/an-introduction-to-java-programming-language-forbeginnersjava-programming-tutorials
5Compilers vs. Interpreters (cont.)
Interpreter – program that directly executes instructions written in a programming or scripting language without compilingthem into a machine language
An interpreter translates one program statement at a time, executing a statement as soon as it is translated (‘on the fly’).
• interpreted languages: JavaScript, PHP, Ruby, Python, …
6Compilers vs. Interpreters (cont.)
Once compiled, code is immediately ready
to run.
Code needs to be compiled separately for different CPUs.
Can be optimized for a CPU, to run faster.
Compiled code cannot be optimized
‘on the fly’.Difficult to ‘decipher’what the source code was from executable.
Code cannot be rununless compiled.
The same source code can be ‘run’ on
all machines.
User must install proper interpreter.
Can test code right away, without having
to compile it.
Have to go through ‘on the fly’ translation
every time.Can observe
program execution ‘line by line’.
Source, not machine code, gets
disseminated.
7Compilers vs. Interpreters (cont.)
Is Java a compiled or an interpreted
language ?!?!
8
Classification ofProgramming Languages
Based on Programming/Coding Philosophy
9Procedural vs. Object Oriented Programming
Procedure-OrientedProgramming
- style of programming in which individualoperations used in a program are groupedinto logical units called procedures / functions
• operations / procedures are executed in the order of their appearance in the main program
• main program can be viewed as a sequence ofprocedure calls
• procedures from one program often CANNOT be reused in another program
10Procedural vs. Object Oriented Programming (cont.)
Example [ C program ]
11Procedural vs. Object Oriented Programming (cont.)
Object-OrientedProgramming(OOP)
- style of programming in which both data and thefunctions that operate on that data are combined/encapsulated into a single program entity calledobject
• thinking in OOP manner involves envisioning programcomponents as objects (class instances) that are similarto concrete objects in the real world
12
Object-Oriented Programming (OOP) Advantages Ease of comprehension. Ease of modification and maintenance. Ease of code re-use.
Procedural vs. Object Oriented Programming (cont.)
Object-Oriented Programming (OOP) Disadvantages Requires (initially) longer code/software design time. Could lead to larger and more complex programs. Could produce slower programs.
13Procedural vs. Object Oriented Programming (cont.)
C, Fortran, Pascal, … Eiffel, Ruby, Python, …
Java is 99% OOP language.
14
OOP Basics
Class - a blueprint / template for objects• class definition describes what attributes its objects will have and
what methods those objects will be able to do
You can use the same class as a template to make (instantiate) many objects.
Object Oriented Programming
15Object Oriented Programming (cont.)
Object - a concrete instance of a classes• you can create objects from classes that you write and from classes
written by other programmers, including Java’s creators
16Object Oriented Programming (cont.)
https://engamrtarek.wordpress.com/2013/12/29/java-the-three-oop-principles-encapsulation-inheritance-polymorphism/
17Object Oriented Programming (cont.)
Encapsulation - mechanism that binds together code and itsrespective data - all methods and data relatedto an object are stored within the object/class
• serves as a ‘protective wrapper’ that shields thecode and data from outside interference and misuse
• key enablers of encapsulation: public and privateaccess modifiers
• ideally, object data should be accessible only throughobject methods
18Object Oriented Programming (cont.)
Example [ encapsulation ]
19Object Oriented Programming (cont.)
Inheritance - ability to create classes that share the attributes andmethods of existing classes, but with more specificfeatures• child/sub class inherits all the members (fields, methods and
nested classes) from its parent/super class
single inheritance multilevel inheritance hierarchical inheritance
• enables faster code development, and allows for better codeorganization and minimization of duplicate code
20Object Oriented Programming (cont.)
Example [ inheritance ]
21Object Oriented Programming (cont.)
Example [ inheritance ]
22Object Oriented Programming (cont.)
- allows actions to act differently based on either which object is performing the action orthe object the action is being performed on• method is able to deal with different types of inputs
• polymorphism enables programmers to create codethat is easier to understand and reuse
Polymorphism
23Object Oriented Programming (cont.)
Example [ polymorphism ]
24
25Java
Is Java a pureOO language?!
- for a language to be pure OO language,it must:• support Encapsulation• support Inheritance• support Polymorphism• all predefined types must be Objects• all user defined types must be Objects• operations performed on objects must be
through methods exposed at the objects
Java’s primitive data types are not objects:
int, char, float
Java static methods and variables can be accessed
directly from the class, without the need to create an instance.
Java is 99% OOP.
262626Java (cont.)
Is Java compiled or interpreted language?!Java combines the use of a compiler and an interpreter.Java compiler translates Java source code into (intermediate-level)Java bytecode – ‘machine language’ for Java Virtual Machine (JVM) .Java VM (interpreter) reads Java bytecode and executes it on a specific machine.
MyProgram.java MyProgram.class
Win JVM
Mac JVM
Unix JVM
27Java (cont.)
- bytecode (x.class) generated after compilationof a java source file can be executed on anyplatform
Java is PlatformIndependent(Cross-Platform)Language • bytecode generated on Windows is the same as the
bytecode generated on Mac• note, however, that JVMs are platform dependant !!!
28Java (cont.)
Java and the Internet
http://java.meritcampus.com/core-java-topics/Creation-Of-Java-As-Platform-Independence-WORA
29Java (cont.)
Java History