Java Programming Introduction & Concepts. Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and.

Slides:



Advertisements
Similar presentations
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Advertisements

1 Lecture 10 Intermediate Representations. 2 front end »produces an intermediate representation (IR) for the program. optimizer »transforms the code in.
1 Pass Compiler 1. 1.Introduction 1.1 Types of compilers 2.Stages of 1 Pass Compiler 2.1 Lexical analysis 2.2. syntactical analyzer 2.3. Code generation.
CPSC Compiler Tutorial 9 Review of Compiler.
Lecture 01 - Introduction Eran Yahav 1. 2 Who? Eran Yahav Taub 734 Tel: Monday 13:30-14:30
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Compiler Construction1 A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University First Semester 2009/2010.
1 Programming Languages Translation  Lecture Objectives:  Be able to list and explain five features of the Java programming language.  Be able to explain.
CS 153: Concepts of Compiler Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Compiler design Computer Science Rensselaer Polytechnic Lecture 1.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
(1.1) COEN 171 Programming Languages Winter 2000 Ron Danielson.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
COP4020 Programming Languages
Chapter 1. Introduction.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Parser-Driven Games Tool programming © Allan C. Milne Abertay University v
Java Bytecode What is a.class file anyway? Dan Fleck George Mason University Fall 2007.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
1 Programming Languages Tevfik Koşar Lecture - II January 19 th, 2006.
CSC 338: Compiler design and implementation
Compiler course 1. Introduction. Outline Scope of the course Disciplines involved in it Abstract view for a compiler Front-end and back-end tasks Modules.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
CST320 - Lec 11 Why study compilers? n n Ties lots of things you know together: –Theory (finite automata, grammars) –Data structures –Modularization –Utilization.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
1 Chapter 1 Introduction. 2 Outlines 1.1 Overview and History 1.2 What Do Compilers Do? 1.3 The Structure of a Compiler 1.4 The Syntax and Semantics of.
Compiler design Lecture 1: Compiler Overview Sulaimany University 2 Oct
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Programming Languages
A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
A compiler is a computer program that translate written code (source code) into another computer language Associated with high level languages A well.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Introduction to OOP CPS235: Introduction.
CSC 4181 Compiler Construction
Language Implementation Overview John Keyser Spring 2016.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Fundamental of Java Programming (630002) Unit – 1 Introduction to Java.
Chapter 1. Introduction.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Lecture 1b- Introduction
Advanced Computer Systems
Compiler Design (40-414) Main Text Book:
Visit for more Learning Resources
Chapter 1 Introduction.
Introduction to Compiler Construction
CS 3304 Comparative Languages
Overview of Compilation The Compiler BACK End
Chapter 1 Introduction.
课程名 编译原理 Compiling Techniques
Compiler Lecture 1 CS510.
Course supervisor: Lubna Siddiqui
CSE401 Introduction to Compiler Construction
Overview of Compilation The Compiler BACK End
System Programming and administration
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Chapter 10: Compilers and Language Translation
A Tour of Language Implementation
Programming language translators
Presentation transcript:

Java Programming Introduction & Concepts

Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and Interpreted (Hybrid) Current version is 1.6

Types of Languages 2 different dimensions for classification Programming paradigm Compiled or interpreted (or hybrid)

Compiled Languages (Simplified) int a := 100; while (a > 0) { a := a – 1; } Source code (program) written in a source language. Compiler Performs checks on the program like - are variable names defined? - are they the right type? - are functions used correctly? - etc etc. Produces output - bytecode - binary executable ld length,% addcc %r1,-1,%r1 addcc %r1,%r2,%r4 …. Compiler output. the source program translated (compiled) to a target language.

Compiled Languages (Simplified) A compiler Translates (compiles) a program written in a source language to a program written in a target language. Performs a number of checks (syntactically and semantically) on the code to assure that the translated code is ‘correct’.

The Inside of a Compiler Scanning Parsing Name resolution Type checking Intermediate code generation Optimization Code generation Typical stages of a compiler

Scanning A scanner reads the input (source program) and creates a stream of tokens. int a := 100; while (a > 0) { a := a – 1; } Scanner [INT, int], [ID, a], [COEQ, :=], [INTLIT, 100], [WHILE, while], [LPAREN, (], …. Token Stream Token type Actual scanned text

Parsing A parser reads a token stream and produces a parse-tree (if the program is syntactically correct) [INT, int], [ID, a], [COEQ, :=], [INTLIT, 100], [WHILE, while], [LPAREN, (], …. Scanner := a a while 100 := > 0 a a + 1 Parse-tree (simplified) int

Syntax The syntax of a language describes which programs are correct in the sense that the textual representation follows the rules of the language. int a := 100; while (a > 0) { a := a – 1; }  int a := 100; while (a > 0) { a ( > a – 1; }  int a := 100; while (a > 0) { a := a + “Hello”; } ?

Name Resolution Traverses the tree and determines if all names (variables, parameters, methods, classes etc.) have been declared.

Type Checking Checks that the program is correct with respect to types (one of the possibly many semantic checks) int a := 100; while (a > 0) { a := a + “Hello”; }  int a := 100; while (a > 0) { a := a - 1; }  int a := 100; while (a > 0) { a := a ; } double a := 100; while (a > 0) { a := a - 1; }  OK though 100 or 1 are integer and not double values is coerced into and 1 into 1.0.

Semantics Where syntax describes what the ‘shape’ of a legal program is, semantics describes the meaning of the program.

Intermediate Code Generation Sometimes a compiler generates intermediate code Easier to optimize Improves portability

Optimization Optimization rewrites code/intermediate code to make it run faster …. (not for this course to bother with!)

Code Generation 0:bipush 100 2:istore_1 3:iload_1 4:ifle14 7:iload_1 8:iconst_1 9:isub 10:istore_1 11:goto 3 14:return Code can be machine code byte code Code can be for Register based architectures Stack based architectures

Interpreted Languages Some languages are not compiled, but executed (interpreted) directly. Typically interpreted languages are slower No need to recompile when making changes

Programming Paradigms A paradigm relates to the fundamental style of a language. Object Oriented: classes and objects Functional: everything is a function Process oriented: communicating processes Imperative: ‘straight line code’ (often part of some of the above)

Where does Java Fit? Java is an Object Oriented Hybrid language We have classes and objects Source is compiled to bytecode Bytecode is interpreted

The Java Compiler (javac) The java compiler is called javac Takes in source code files Produces class files for each referenced class.

Java Bytecode A compiled java class resides in a class file (one for each class) Bytecode is a type of machine code, but for a stack oriented architecture All computation is done on a stack, there are no registers

The Java Virtual Machine (JVM) A class file can be interpreted by the java virtual machine (JVM) using the command: java Must contain a method called main to run

Correctness What does it mean that something is correct? It never crashes? It always work? (what does works mean?) …..