Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Intro III.1 (Fr Feb 23).

Similar presentations


Presentation on theme: "Java Intro III.1 (Fr Feb 23)."— Presentation transcript:

1 Java Intro III.1 (Fr Feb 23)

2 Java Programming Intro
The Rubato Architecture Some History The Java Platform How to Run a Java Class The Oracle Tutorial Our First Program Its First Extension A Second Program

3 1. The Rubato Architecture

4 2. Some History Java version 1 (beta) was introduced in 1995 by the SUN computer scientist James Gesling, later Sun was absorbed by the Oracle SW company. Now, we are at Java version 9. We have 9 Mio Java developers in 2017.

5 3. The Java Platform Java is characterized as a platform-independent language, more precisely, you write a Java program (source code XXX, always with the extender .java, i.e. the source name is XXX.java), then you compile it by the command javac XXX.java and you get the file XXX.class, the so-called bytecode.

6 3. The Java Platform (cont.)
This cannot run, but now, every operating system can have its own interpreter, the so-called Java Virtual Machine JVM, that runs/executes the bytecode by the command java XXX (+ parameters if needed) We shall see in a minute how this is done concretely.

7 3. The Java Platform (cont.)
Java is also an object-oriented language, i.e., its conceptual structure is very much like our form-denotator architecture: it consists of classes which are space types like forms, and objects which are points in the classes, much as denotators are points in forms. class ~ form object ~ denotator We shall see the details soon.

8 3. The Java Platform (cont.)
Most successful modern languages are object-oriented, e.g. C++ (the o.o. extension of C), Objective C (for Mac only), Smalltalk, Eiffel, Delphi, Object Pascal, etc.. But Java is the only successful platform-independent language. This is why I switched to the first version of Rubato, which was first written in Objective C for the NeXT and OS X macs, to Java in 2001 at the CS Department of the U of Zurich.

9 3. The Java Platform (cont.)
Java is implemented in most important OS with about 2000 predefined classes and defines the Java Platform on these OS. There are several fine software environments for Java programming, such as Eclipse for Mac. We shall however not use any of these tools which would take away too much time to be introduced. Instead we shall program everything on the easy environment of text files and the Terminal app.

10 4. How to run a java class: a) Define the class XXX.java in a text app (not Word, just plain text without hidden formatting) in your DDD folder. b) Open the Terminal app. Change to the DDD folder by the command cd + drag the DDD folder here and return. c) Write ls to see that the file XXX.java is there. d) Write javac XXX.java and return. e) If no error is in the class file, you should now see the class file XXX.class (check with ls). f) Run the program of you class by java XXX (+ parameters if needed).

11 5. The Oracle Tutorial

12 6. Our First Program 6.1 Open a text app (like TextEdit on Mac) and set to write plain text. 6.2 Write the following short program (really write everything, it’s important to be able to write the program code!): class HelloWorldApp {   public static void main(String[] args) {     System.out.println("Hello World!"); // Display the string.     } }

13 6. Our First Program 6.3 Save this file in DDD exactly under the name HelloWorldApp.java 6.4 Compile it by javac HelloWorldApp.java 6.5 Check by ls that we now have the class file HelloWorldApp.class 6.6 Run it by java HelloWorldApp

14 Short Discussion of Code Structure
opening bracket of class class signature main method's name class name arguments of method opening bracket of method class HelloWorldApp {   public static void main(String[] args) {     System.out.println("Hello World!"); // Display the string.     } } print method's name print method's argument a comment closing bracket of method closing bracket of class   public static void method accessible to all programmers class method method does not return anything to the program

15 Hello Jay Afrisando! or Hello Zilu Chen! i.e., your own name.
7. Its First Extension Want to write a program that prints also your name, not just a generic greeting sentence. Like Hello Jay Afrisando! or Hello Zilu Chen! i.e., your own name. 7.1 To this end, we use the input argument String[] args of the main method. This is an array of String objects, like (“Jay”, “Afrisando”) which is an array of two Strings: args[0] is “Jay”, and args[1] is “Afrisando”.

16 7. Its First Extension (cont.)
We now want these arguments to be part of our text. We therefore write concatenation of String objects System.out.println("Hello "+ args[0]+" "+args[1]+ "!"); first String object first String object of argument which is a String array (= sequence of String objects starting from index 0, then index 1, etc.) empty space String object second String object of argument ! String object

17 7. Its First Extension (cont.) and get the code (without the comment):
class HelloMyWorld { public static void main(String[] args){ System.out.println("Hello "+ args[0]+" "+args[1]+"!"); } 7.2. Now compile HelloMyWorld.java! You get HelloMyWorld.class run it! But also write the two arguments, you name: java HelloMyWorld Zilu Chen

18 8. A Second Program


Download ppt "Java Intro III.1 (Fr Feb 23)."

Similar presentations


Ads by Google