Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSc 201 Introduction to Java George Wells Room 007, Hamilton Building

Similar presentations


Presentation on theme: "CSc 201 Introduction to Java George Wells Room 007, Hamilton Building"— Presentation transcript:

1 CSc 201 Introduction to Java George Wells Room 007, Hamilton Building Email: G.Wells@ru.ac.za

2 Notice from Dean of Science Thank you to students for the way you prepared for curriculum approval –went very smoothly for the science faculty HOWEVER, some science students have not yet registered their subjects –These students MUST complete their curriculum approval in the Dean’s office TODAY

3 Notice (cont.) Any changes to your curriculum can only be done after discussion with the Dean –cannot change on ROSS or at Eden Grove If the Dean detects a problem with your curriculum, he will email you to see him –It is essential that you respond to that email as quickly as possible so we can correct the error

4 Introduction to Java

5 Chapter 1: Getting Started What is Java? –Recent programming language (1995) –Based on C++ –Great for teaching (and learning!)

6 History 101 1991: The Green Project –Intelligent “set-top boxes” –Oak 1993: The Internet/World Wide Web 23 May 1995: Java 1.0 –Sun and Netscape

7 History (cont.) Quick fixes! –Java 1.1 –Development of libraries and language –1.1.7 Stability at last! – Java 1.2 (November 1998) –Integrated the library development –Marketed as Java 2!

8 History (cont.) Performance at last: Java 1.3 (May 2000) –Not Java 3! Oracle buys Sun Microsystems (2010) Current version –Java 1.6 (also called Java 6!) –Standard Edition (SE) –also Micro and Enterprise Editions (ME and EE)

9 Our First Java Program /* Comment 1: Written by George Wells -- 6 January 2011 */ public class HelloWorld { public static void main (String[] args) { System.out.println("Hello, world\n"); // Comment 2 } // main } // class HelloWorld

10 Python Equivalent! print "Hello, world\n"

11 Basics Case sensitivity: –String is not the same as string –MAIN is not the same as main Java keywords are all lower case –e.g. public class static void

12 Looking at the program: The main method /* Comment 1: Written by George Wells -- 6 January 2011 */ public class HelloWorld { public static void main (String[] args) { System.out.println("Hello, world\n"); // Comment 2 } // main } // class HelloWorld The program’s entry point

13 Looking at the program: Statements /* Comment 1: Written by George Wells -- 6 January 2011 */ public class HelloWorld { public static void main (String[] args) { System.out.println("Hello, world\n"); // Comment 2 } // main } // class HelloWorld A single statement

14 Terminated by semicolons: Free format –Examples: Statements System.out.println("Hello, world\n"); One statement a = b + c + d; a = 1; b = 2; c = a * b + 3; d = 4; Four statements Use one statement per line!

15 Looking at the program: Grouping parts of the program /* Comment 1: Written by George Wells -- 6 January 2011 */ public class HelloWorld { public static void main (String[] args) { System.out.println("Hello, world\n"); // Comment 2 } // main } // class HelloWorld Braces A Compound Statement

16 Looking at the program: Comments /* Comment 1: Written by George Wells -- 6 January 2011 */ public class HelloWorld { public static void main (String[] args) { System.out.println("Hello, world\n"); // Comment 2 } // main } // class HelloWorld

17 Looking at the program: Strings and Escape Sequences /* Comment 1: Written by George Wells -- 6 January 2011 */ public class HelloWorld { public static void main (String[] args) { System.out.println("Hello, world\n"); // Comment 2 } // main } // class HelloWorld Escape Sequence

18 Output: –System.out is an output stream (connected to the screen by default) –println is a method to display information Input and Output Input: –System.in is an input stream (connected to the keyboard by default) – More complicated! (wait until Chapter 10)

19 Compiling and Running Java Programs A little different! DOS command-line tools Compiler: javac Case is significant!

20 Compiling (cont.) The compiler produces a.class file –Bytecode (not machine code) –Allows portability (Java programs can run on almost any hardware and operating system) Needs an interpreter –The Java Virtual Machine (JVM) –A program that “executes” bytecode

21 Compiling public class HelloWorld {... javac HelloWorld.java HelloWorld.class HelloWorld.java File of bytecodes

22 Running HelloWorld.class java HelloWorld Run the interpreter

23 Or use an IDE JCreator

24


Download ppt "CSc 201 Introduction to Java George Wells Room 007, Hamilton Building"

Similar presentations


Ads by Google