Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
1 Classification of Programming Languages Based on How They Derive Machine Code Compilers vs. Interpreters 2 Compiler – computer program that transforms source code written in one computer language to equivalent code in another language • most commonly it is translation from a high-level to a machine lang. • compiled languages: C, C++, Eiffel, Fortran, Crystal, … A compiler must translate an entire program into machine code before the program can be executed. 3 COMMERCIAL COMPILER 4 http://www.slideshare.net/darokoblog/an-introduction-to-java-programming-languageforbeginnersjava-programming-tutorials Compilers vs. Interpreters (cont.) 5 Interpreter – program that directly executes instructions written in a programming or scripting language without compiling them into a machine language • interpreted languages: JavaScript, PHP, Ruby, Python, … An interpreter translates one program statement at a time, executing a statement as soon as it is translated (‘on the fly’). Compilers vs. Interpreters (cont.) Once compiled, code is immediately ready to run. Can be optimized for a CPU, to run faster. Difficult to ‘decipher’ what the source code was from executable. Code needs to be compiled separately for different CPUs. Compiled code cannot be optimized ‘on the fly’. Code cannot be run unless compiled. 6 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. Compilers vs. Interpreters (cont.) Is Java a compiled or an interpreted language ?!?! 7 8 Classification of Programming Languages Based on Programming/Coding Philosophy Procedural vs. Object Oriented Programming 9 Procedure-Oriented - style of programming in which individual operations used in a program are grouped Programming into logical units called procedures / functions • main program can be viewed as a sequence of procedure calls • operations / procedures are executed in the order of their appearance in the main program • procedures from one program often CANNOT be reused in another program Procedural vs. Object Oriented Programming (cont.) Example [ C program ] 10 Procedural vs. Object Oriented Programming (cont.) 11 Object-Oriented - style of programming in which both data and the functions that operate on that data are combined/ Programming encapsulated into a single program entity called (OOP) object • thinking in OOP manner involves envisioning program components as objects (class instances) that are similar to concrete objects in the real world Procedural vs. Object Oriented Programming (cont.) Object-Oriented Programming (OOP) Advantages Ease of comprehension. Ease of modification and maintenance. Ease of code re-use. Object-Oriented Programming (OOP) Disadvantages Requires (initially) longer code/software design time. Could lead to larger and more complex programs. Could produce slower programs. 12 Procedural vs. Object Oriented Programming (cont.) C, Fortran, Pascal, … 13 Eiffel, Ruby, Python, … Java is 99% OOP language. Object Oriented Programming 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 (cont.) 15 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 Object Oriented Programming (cont.) https://engamrtarek.wordpress.com/2013/12/29/java-the-three-oop-principles-encapsulationinheritance-polymorphism/ 16 Object Oriented Programming (cont.) Encapsulation - mechanism that binds together code and its respective data - all methods and data related to an object are stored within the object/class • ideally, object data should be accessible only through object methods • serves as a ‘protective wrapper’ that shields the code and data from outside interference and misuse • key enablers of encapsulation: public and private access modifiers 17 Object Oriented Programming (cont.) Example [ encapsulation ] 18 Object Oriented Programming (cont.) 19 Inheritance - ability to create classes that share the attributes and methods of existing classes, but with more specific features • child/sub class inherits all the members (fields, methods and nested classes) from its parent/super class • enables faster code development, and allows for better code organization and minimization of duplicate code single inheritance multilevel inheritance hierarchical inheritance Object Oriented Programming (cont.) Example [ inheritance ] 20 Object Oriented Programming (cont.) Example [ inheritance ] 21 Object Oriented Programming (cont.) Polymorphism - allows actions to act differently based on either which object is performing the action or the object the action is being performed on • method is able to deal with different types of inputs • polymorphism enables programmers to create code that is easier to understand and reuse 22 Object Oriented Programming (cont.) Example [ polymorphism ] 23 24 Java Is Java a pure OO 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. 25 26 Java (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. Win JVM Mac JVM MyProgram.java MyProgram.class Unix JVM Java (cont.) Java is Platform - bytecode (x.class) generated after compilation of a java source file can be executed on any Independent platform (Cross-Platform) • bytecode generated on Windows is the same as the Language bytecode generated on Mac • note, however, that JVMs are platform dependant !!! 27 Java (cont.) Java and the Internet http://java.meritcampus.com/core-java-topics/Creation-Of-Java-As-Platform-Independence-WORA 28 Java (cont.) Java History 29