02javaintroSmall

02javaintroSmall - Lecture Set 2: Starting Java 1. 2. 3. 4....

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CMSC 131 Spring 2008 Jan Plane (adapted from Bonnie Dorr) Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input CMSC 131 Spring 2008 Jan Plane (adapted from Bonnie Dorr) 1 This Course: Intro to Procedural Programming using Java Why Java? c Popular modern language c Used in web, business, telecom applications c Developed in 1990s, incorporates many features from earlier languages c Object-orientation c Garbage collection c Portability of object code CMSC 131 Spring 2008 Jan Plane (adapted from Bonnie Dorr) 2 Portability of Object Code? c Object code is 2GL (assembly) / 1GL (machine code) c Last time we said that 2GL / 1GL is architecture-specific c How can Java have portable object code? Answer: Java Virtual Machine (JVM)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 CMSC 131 Spring 2008 Jan Plane (adapted from Bonnie Dorr) 3 Java Virtual Machine c Java includes definition of Java bytecode = “fake” machine code for Java c Java compilers produce Java bytecode c To run Java bytecode, must have bytecode interpreter (“Java Virtual Machine”) on client machine .java Java compiler .class client client JVM JVM source code object code CMSC 131 Spring 2008 Jan Plane (adapted from Bonnie Dorr) 4 Facts about JVMs c For efficiency, JVMs often compile bytecode into native machine code c There are also “native” Java compilers (these compile Java directly to machine code) CMSC 131 Spring 2008 Jan Plane (adapted from Bonnie Dorr) 5 Method Headers c main is a method = “operation” c Operations require operands = data to work on c Operations return new data (result) c Header gives information on form of operands, result for methods For main: c Operand is collection of Strings c Result is “void” (= unimportant) c More later on “public”, “static” c Every program must have exactly one “main” method (where execution begins)
Background image of page 2
3 CMSC 131 Spring 2008 Jan Plane (adapted from Bonnie Dorr) 6 Output and Comments c Output to console c System.out.println c System.out.print c String Literals always use “quotation marks” c Comments: explanations added by programmer c ignored by the compiler c read by other people looking at the code c Two styles c /* … */ c // to end of line… c Comments are essential for good programming! CMSC 131 Spring 2008 Jan Plane (adapted from Bonnie Dorr) 7 Objects c Bundles of data (“instance variables”) and methods (“functions”) c Created using classes as “templates” c We’ll learn more later this semester CMSC 131 Spring 2008 Jan Plane (adapted from Bonnie Dorr) 8 Java Program Organization c Class c Structure around which all Java programs are based c A typical Java program consists of many classes c Each class resides in its own file, whose name is based on the class’s name c The class is delimited by curly braces { … }.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

02javaintroSmall - Lecture Set 2: Starting Java 1. 2. 3. 4....

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online