Software for Translators Barcelona, January 2002
Content Programming and Languages Origins 4 Languages The Programming Cylcle Edit Compile Execute Exercises: Java Programming Language Elements
Programming and Languages
The ancient days (1950)
Punched Paper A C B D EF „Registers“ ld A, 1 1 A ld B, 2 2 B add A,B 3 A
The old days (1970)
Computer Memory A C B D EF „Registers“ Program Counter B ld A, 1 01 PC 1 A ld B, 202 PC 2 B add A,B 03 PC 3 A
Basic (1980)
10set a = 1; 20set b = 2; 30set a = a + b; 40print a; => 3 A C B D EF 2 B3 A
Basic (1980) print 1+2; => 3 A C B D EF 2 B3 A
Programming Languages Historic PL/1 Cobol Fortran Basic Object Oriented Smalltalk C C++ Java Python Exotic Prolog Lisp Scripting Shell Perl TCL Database SQL dBase
4 Languages Basic Visual Basic Java HTML
Basic Example 10 rem Just print Hello World. 20 print ´Hello World´ => Hello World
Visual Basic Example '############################################### '# # # # '# # This program places a text into a # # '# # a text box for viewing. # # '# # # # '############################################### Dim i As Integer Private Sub Command1_Click() On Error Resume Next CommonDialog1.ShowOpen i = FreeFile Open CommonDialog1.filename For Input As #i Text1.Text = Input(LOF(i), i) Close #i End Sub
Java Example // This example is from Java in a Nutshell. // Copyright (c) 1997 by David Flanagan public class Hello { public static void main(String[] args) { System.out.println("Hello World!"); } => Hello World
HTML Example Hello World! Text Editor: HTML Internet Explorer
The Programming Cycle
EditExecute Compile javac HelloWorld.java java HelloWorld
Edit
Compile javac HelloWorld.java
Execute java HelloWorld
Language Elements
Comments // Comment /* Comment */ % Comment Keywords: FOR NEXT WHILE DO I F Strings: “Hello World” ´Hello World´ ‘Hello World’ Identifiers: ClassName x, y, z Parenthesis: (foo bar) [foo bar] {foo bar}
Comments // This example is from Java in a Nutshell. // Copyright (c) 1997 by David Flanagan public class Hello { public static void main(String[] args) { System.out.println("Hello World!"); }
Keywords // This example is from Java in a Nutshell. // Copyright (c) 1997 by David Flanagan public class Hello { public static void main(String[] args) { System.out.println("Hello World!"); }
Strings // This example is from Java in a Nutshell. // Copyright (c) 1997 by David Flanagan public class Hello { public static void main(String[] args) { System.out.println("Hello World!"); }
Identifiers // This example is from Java in a Nutshell. // Copyright (c) 1997 by David Flanagan public class Hello { public static void main(String[] args) { System.out.println("Hello World!"); }