lecture02-june8 - 6/8/09 Lecture 2 Announcements Read A5,...

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

View Full Document Right Arrow Icon
6/8/09 1 Lecture 2 Announcements • Read A5, A9,A10 for next time • Assignment 1 out at end of week • Topics for today will answer the questions: –What is the Java programming language and how does it compare to C/C++ ? –an overview of Appendix A • Java jargon: method ~ = function A Quick Tour of Appendix A • The Java environment and classes • Everything must be inside of a class • Primitive data types and reference variables • Control statements • Methods and the Math class • Strings and things • Wrapper classes around the primitives • Defining your own classes • Arrays • I/O using Swing’s JOptionPane • I/O using streams Basic Language Constructs • All of the usual control constructs are there: – if . .. else, switch, while, do . .. while, for • There’s no goto in Java. – The only unconditional jump mechanism is the break or continue statement, which is used to jump out or to the end of one or more multiply-nested loops. • Java has method overloading, but no operator overloading. • Parameter passing: Call by value and reference are both supported • Java has an additional basic data type: boolean The boolean Data Type A boolean variable is used to hold truth values: either true or false (which are reserved words that stand for boolean literal values). Boolean variables are used in conditional tests. For example boolean lightsOn = true; // . . . Later in the program lightsOn = false; // . . . if(lightsOn) System.out.println(“see, the lights ARE on”); • Java is (an interpreted) write once, run anywhere language. – Uses a virtual machine (VM) concept – Write once, run everywhere (nearly) NEVER works with C/C++, but does (nearly) ALWAYS work with JAVA. – The biggest potential stumbling block is speed: • Interpreted Java runs in the range of 20 times slower than C. • But: nothing prevents the Java language from being compiled and there are just-in-time (JIT) compilers that offer significant speed-ups. Portability • Java has no preprocessor. – If you want to use classes in a given library, you say import and the name of the library. • For example: import java.awt.Rectangle; • #include does not directly map to import, but it has a similar feel to it – There are no preprocessor-like macros. – There is no conditional compiling (#ifdef) • You don't have separated HEADER-files defining class-properties – You can define elements only within a class. – All method definitions are also defined in the body of the class. Thus, in C++ it would look like all the functions are inlined (but they’re not). – File and classname must be identical in JAVA Program Organization
Background image of page 1

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

View Full DocumentRight Arrow Icon
6/8/09 2 • All the primitive types in Java have specified sizes that are machine independent for portability. – On some systems this leads to non-optimized performance
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/15/2009 for the course EE 322C taught by Professor Nettles during the Summer '08 term at University of Texas at Austin.

Page1 / 7

lecture02-june8 - 6/8/09 Lecture 2 Announcements Read A5,...

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

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