190 likes | 283 Views
CSC 8600 Object-Oriented Design & Programming John Lewis Villanova University. Overview of Course. Java Basics; Java vs. C and C++ Core OO Concepts objects and classes API support and class libraries encapsulation, visibility, static modifier
E N D
CSC 8600 Object-Oriented Design & Programming John Lewis Villanova University
Overview of Course • Java Basics; Java vs. C and C++ • Core OO Concepts • objects and classes • API support and class libraries • encapsulation, visibility, static modifier • inheritance, class hierarchies, abstract classes • interfaces, polymorphism • The Java I/O Model; Exceptions; Internationalization • Applets; Graphics; Threads
Overview of Course • Graphical User Interfaces; Events; The AWT API • AWT Components; Layout Managers • The Swing API; Swing Components • Network Communication; Client/Server; The RMI API • Native Programs; The JNI API • Database Interaction; The JDBC API
Java’s Popularity • Language design • Web-based execution • Buzzword compliant: • simple • object-oriented • pure (versus hybrid) • distributed • interpreted • architecture-neutral • multi-threaded • dynamic • safe
Java Buzzwords • Simple • compared to C and C++ • not when compared to HTML • Object-Oriented • objects and classes are fundamental • Pure vs. Hybrid • pure: the object model is all but forced • hybrid: a mix of the object-oriented and procedural models
Java Buzzwords • Architecture-Neutral • consistency across platforms for language issues • low level representation (bytecode) is not tied to a particular processor type • Interpreted • the bytecode is usually interpreted during execution • Dynamic • classes and library support are dynamically loaded as needed
Java Buzzwords • Distributed • built-in and API support for distributed processing • Threaded • built-in thread control • Safe • concerns regarding client execution of unknown code • references as “safe pointers”
Comparing Java to C and C++ • Java is superficially similar to both C and C++ • Similar syntax and reserved words • Similar control structures • if, if-else, switch • while, do, for • Similar method definition structure • But several other basics and many key underlying concepts are quite different
Java Reserved Words abstract boolean break byte byvalue case cast catch char class const continue default do double else extends false final finally float for future generic goto if implements import inner instanceof int interface long native new null operator outer package private protected public rest return short static super switch synchronized this throw throws transient true try var void volatile while
Java Data • There are two basic data type categories: • primitive data • references to objects • Primitive data types are built into the language • Integers: byte, short, int, long • Floating Point: float, double • Character: char • Boolean: boolean
Java Data • All numeric primitive types are signed and have a fixed size for all platforms: byte 8 bits float 32 bits short 16 bits double 64 bits int 32 bits char 16 bits long 64 bits boolean ? bits
Java Data • Characters are based on the Unicode character set • international • 16 bits per character • ASCII is a subset • Explicit boolean type • conditions must produce boolean results • Primitive data are automatically initialized • though compilers tend to check validity of use
Java Comments • Two forms: // comment runs to the end of the line /* comment runs to terminating symbol, across line breaks */ • A special format with tags can be used to create HTML documentation of classes and packages: /** @author John Lewis */
Comparing Java to C and C++ • All non-primitive data are objects • no structs, unions, enums • arrays and strings are objects • Arrays perform automatic bounds checking • Java has a built-in string concatenation operator (+) • No pointer arithmetic or explicit dereferencing • No typedef or preprocessor • No goto statement
Comparing Java to C and C++ • No forward referencing required • No comma operator • No variable-length parameter lists • No optional or const method parameters • The main method cannot return a value • No global (file level) variables
Java Applications • Processing begins with the main method • Each method belongs to, and is defined within, a particular class • A class often contains multiple methods • A program is often made up of many classes • The simplest program has one class and one method
Java Translation and Execution • A Java compiler translates Java source code into a low-level representation called bytecode • Java bytecode is not the machine language for any traditional CPU • An interpreter translates bytecode into machine language and executes it • Therefore the compiler output is not specific to any particular machine • Theoretically: write once, run anywhere
Java Translation and Execution Java source code Java bytecode Java compiler Java interpreter Bytecode compiler Machine code
Applet Translation and Execution local computer Java compiler Java source code Java bytecode Web browser remote computer Java interpreter