Presentation is loading. Please wait.

Presentation is loading. Please wait.

8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.

Similar presentations


Presentation on theme: "8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment."— Presentation transcript:

1 8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment –2.0 platform

2 Machine Languages natural language of the computer numeric language hard to read (for humans) EX: +1300042774 +1400593419 +1200274027

3 Assembly Languages abbreviations replace some machine language programs called assemblers translate assembly language into machine code EX:LOAD BASEPAY ADD OVERPAY STORE GROSSPAY

4 High-Level Languages look more like human languages programs called compilers convert high-level code into machine language structured & object-oriented –structured: Pascal, C –structured & object-oriented: Java, C++

5 Disciplined approach Clearer to read & debug than previous programming styles Pascal, C Ratherthan de cidnbyrs lf hw2use language, you agree to abide by certain conventions to help in collaboration and usability. Structured Programming

6 Object-Oriented Programming A OOP program has objects that can perform actions on other objects. EX: –newspaper editor, researcher, writer, layout designer –restaurant cook, maitre d’, waiter, dishwasher, customer

7 OOP Terminology Objects –program construction w/ associated data & actions –EX: a flat head screwdriver Methods –actions that objects can do –EX: turn screws, pry, chisel Classes –sets of similar objects -- all objects have same kinds of data & same methods –EX: lots of screwdrivers that look and act the same.

8 Java Environment Edit (we’ll use Symantec Visual Café) Compile (javac creates.class file from.java file) Load (java class loader puts.class file into the computer’s memory) Verify (bytecode verifier to ensure security, etc.) Execute (interpreter begins running the program)

9 Our First Java Program // Fig. 2.1: Welcome.java // A first program in Java public class Welcome1 { public static void main ( String args[] ) { System.out.println ( “Welcome!” ); } }

10 Comments // Fig. 2.1: Welcome.java // A first program in Java public class Welcome1 { public static void main ( String args[] ) { System.out.println ( “Welcome!” ); } } Must start with // for a single-line comment

11 White space: it doesn’t matter. // Fig. 2.1: Welcome.java // A first program in Java public class Welcome1 { public static void main ( String args[] ) { System.out.println ( “Welcome!” ); } } White space is empty space in the program. You can put as many spaces between words as you like.

12 Class Definition // Fig. 2.1: Welcome.java // A first program in Java public class Welcome1 { public static void main ( String args[] ) { System.out.println ( “Welcome!” ); } } Defines new class called Welcome1 that is public. The class name (by convention) should be capitalized, and MUST be the same as the name of the file (case-sensitive).

13 Braces // Fig. 2.1: Welcome.java // A first program in Java public class Welcome1 { public static void main ( String args[] ) { System.out.println ( “Welcome!” ); } } Braces (squiggly parentheses) must enclose everything about a class. MUST be paired.

14 Methods // Fig. 2.1: Welcome.java // A first program in Java public class Welcome1 { public static void main ( String args[] ) { System.out.println ( “Welcome!” ); } } Methods are sets of instructions, or actions to be performed.

15 Methods // Fig. 2.1: Welcome.java // A first program in Java public class Welcome1 { public static void main ( String args[] ) { System.out.println ( “Welcome!” ); } } public refers to access permissions. void refers to what will be returned from the method (the output).

16 Methods // Fig. 2.1: Welcome.java // A first program in Java public class Welcome1 { public static void main ( String args[] ) { System.out.println ( “Welcome!” ); } } main is the name of the method. (String args[] ) defines the parameters for the method.

17 Method Definition Body // Fig. 2.1: Welcome.java // A first program in Java public class Welcome1 { public static void main ( String args[] ) { System.out.println ( “Welcome!” ); } } Entire method body MUST be surrounded by braces.

18 Method Definition // Fig. 2.1: Welcome.java // A first program in Java public class Welcome1 { public static void main ( String args[] ) { System.out.println ( “Welcome!” ); } } System.out.println prints the string “Welcome!” and then moves the cursor down to the next line. println uses the string “Welcome!” as its argument. println will print a string, then move to the next line. The similar method print will print a string and NOT move to the next line.

19 Method Definition // Fig. 2.1: Welcome.java // A first program in Java public class Welcome1 { public static void main ( String args[] ) { System.out.println ( “Welcome!” ); } } A statement is an action; a function. They work like sentences. All statements MUST end with a semicolon.

20 Second Java Program: pg. 42 // Fig. 2.3: Welcome2.java // Printing a line with multiple statements public class Welcome2 { public static void main ( String args [] ) { System.out.print ( “Welcome to” ); System.out.print ( “ Java Programming!” ); } }

21 Second Java Program: pg. 42 // Fig. 2.3: Welcome2.java // Printing a line with multiple statements public class Welcome2 { public static void main ( String args [] ) { System.out.print ( “Welcome to” ); System.out.print ( “ Java Programming!” ); } } comments Class definition header Class body Method header Method name statements brackets

22 Escape Sequences Inline character sets that do basic things with text. \nnewline. Moves cursor to next line. \ttab. Moves cursor to next “tab stop” \rreturn.Moves cursor back to start of line. \\backslash. Prints a backslash character. \”double quote. Prints a double quote character. \’single quote. Prints a single quote character.

23 Third Java Program: pg. 42 // Fig. 2.4: Welcome3.java // Printing multiple lines with one statement public class Welcome3 { public static void main ( String args [] ) { System.out.print ( “Welcome to\nJava!” ); } } comments Class definition header Class body Method header Method name statement brackets

24 Next Time: Welcome4.java Identifiers Import statements Getting out of the MSDOS window: dialog boxes


Download ppt "8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment."

Similar presentations


Ads by Google