Introduction to Java ? Developed at Sun Microsystems by James Gosling in 1991 ? Object Oriented ? Free ? Compiled and Interpreted (Hybrid) ? Current version is 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,% %r1,-1,%r1 %r1,%r2,%r4 …. Compiler output. the source program translated (compiled) to a target language. Compiled Languages (Simplified) ? piler ? 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 piler Scanning Parsing Name resolution Type checking Intermediate code generation Optimization Code generation Typical stages of piler 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 := >0a 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 ”;}?
Java Programming - UNLV:java编程-拉斯维加斯 来自淘豆网m.daumloan.com转载请标明出处.