200 likes | 224 Vues
This course delves into advanced object-oriented programming with a focus on Java. Explore OOP concepts, Java programming, modular units, program structures, and more. Emphasizes proper program design and offers a unique syllabus. Join us for an in-depth exploration of object-oriented design principles.
E N D
Computer Science II for Majors Fall 2010 Introduction CMSC 202
Instructors Mr. Ryan Bergeron Lecture Section 01 Tues/Thurs, 10:00am – 11:15am in Lecture Hall 3 Ms. Susan Mitchell Lecture Section 07 Mon/Wed, 5:30pm – 6:45am in Lecture Hall 1 Mr. John Park Lecture Section 13 Tues/Thurs, 1:00pm – 2:15pm in SOND 110
Bergeron & Mitchell Sections For students with little or no Java background Both sections have the same website are assigned the same projects are given the same lab assignments get the same lecture material have the same final exam (same day, time, location) Exams1 and 2 are different. You must take the exam given by your instructor.
Advanced Section (13) – Mr. Park • For students with substantial Java background (or equivalent) • Students must either have previously taken a course in Java (e.g., AP Comp Sci), or feel *completely* comfortable with a similar language (e.g., C/C++) • Emphasis on OO Design • Syllabus restructured to incorporate design principles throughout the various topics • Coverage of Advanced Topics • Will cover additional Java concepts (time permitting)
Park Section (con’t) • Shares the CMSC 202 web site with the other two sections • Some links are different (schedules/notes, projects) • Some pages have additional comments for this section, but are well-marked • Unique schedule, notes, and projects • Exams1 and 2 are different. • (This is true for all CMSC 202 sections.) • Has own final at the regularly schedule date and time
What is CMSC 202? An introduction to object-oriented programming (OOP) and object-oriented design (OOD) Uses the Java programming language Uses the Eclipse integrated development environment (IDE) Strong emphasis on proper program design Course website www.cs.umbc.edu/courses/undergraduate/202/fall10
Procedural vs. OO Programming A Collection of Objects Procedural Object-Oriented (OO) Examples: C, Pascal, Basic, Python Modular units: functions Program structure: hierarchical Data and operations are not bound to each other. Examples: Java, C++, Ruby Modular units: objects Program structure: a graph Data and operations are bound to each other. A Hierarchy of Functions
Python vs. Java – A Little Sample Python: print “Hello, world” quotient = 3 / 4 if quotient == 0: print “3/4 == 0”, print “in Python” else: print “3/4 != 0” Java: public class Hello { public static void main(String[] args) { int quotient; System.out.println(“Hello, world”); quotient = 3 / 4; if (quotient == 0) { System.out.print(“3/4 == 0”); System.out.println(“ in Java”); } else { System.out.println(“3/4 != 0”); } } } // Things to note: // Everything has to be in some class // We need a “main()” // Statements end with ‘;’ // Variables must be declared // “if/else” syntax different // Statement blocks demarcated by “{…}” // Comments are different // …but there is much that is similar
What’s an Object? Must first define a class A data type containing Attributes - make up the object’s “state” Operations - define the object’s “behaviors” Bank Account account number owner’s name balance interest rate more? String sequence of characters more? compute length concatenate test for equality more? deposit money withdraw money check balance transfer money more? name attributes (state) operations (behaviors)
So, an object is … a particular “instance” of a class. 12-345-6 Ryan Bergeron $1,250.86 1.5% 65-432-1 Dennis Frey $5.50 2.7% 43-261-5 Susan Mitchell $825.50 2.5% Bergeron’s Account Frey’s Account Mitchell’s Account • For any of these accounts, one can • deposit money • withdraw money • check the balance • transfer money
Why Java for 202? Popular modern OO language Wide industry usage Used in many types of applications Desirable features Object-oriented Portability (cross-platform) Easy handling of dynamic variables Garbage collection Built-in GUI libraries
Java History Created by Sun Microsystems team led by James Gosling (1991) Originally designed for programming home appliances Difficult task because appliances are controlled by a wide variety of computer processors Writing a compiler (translation program) for each type of appliance processor would have been very costly. Solution: two-step translation process compile, then interpret
Compilers, Interpreters, and the JVM Compiled Languages (e.g. C, C++) compile execute source code binary code Compiler is unique to each processor Interpreted Languages (e.g. JavaScript, Perl, Ruby) Interpreter translates one code instruction at a time into binary and executes it interpret source code Small, easy to write Interpreter is unique to each processor Java Bytecode is processor independent compile interpret source code bytecode JVM is unique to each processor Java Virtual Machine (JVM)
Compiling and Running C/C++ Project Library for Linux Linux binary Linux executable C/C++ Code Linux C/C++linker Linux C/C++compiler Project Library for Windows Windows binary Windows executable Windows C/C++ compiler Windows C/C++linker
Compiling and Running Java JRE for Linux Java Code Java Bytecode java Hello javac Hello.java Java interpreter (JVM) translates bytecode to machine code in JRE Java compiler Hello.java Hello.class java Hello JRE for Windows
Java Terminology Java acronyms are plentiful and confusing. Here are the basics. JVM – Java Virtual Machine Translates Java bytecode to machine code API – Application Programming Interface Java code libraries JRE – Java Runtime Environment The JVM and the Java API together JDK (formerly SDK) – Java Development Kit JRE + tools (compiler, debugger) for developing Java applications and applets J2SE – Java 2 Platform, Standard Edition The JRE and JDK products taken as a “family” To learn more about JDK, JRE, etc, visit: http://java.sun.com/javase/technologies/index.jsp
Java Versions Current version of Java: Java 6, also known as Java 1.6 or Java 1.6.0 This is the version running on GL servers Previous version: Java 5, also known as Java 1.5, Java 1.5.0 or “Java 2 SE Version 5” To learn more about Java version naming, visit: http://java.sun.com/javase/namechange.html
Java Applications Two types of Java programs: Applications (a “regular” Java program) A program with a class that contains an operation named main When a Java application program is run, the run-time system automatically invokes the method named main. All Java application programs start with the main method. Applets Java program that is meant to be run from a Web browser Can be run from a location on the Internet Can also be run with an applet viewer program for debugging Applets always use a windowing interface, whereas applications may use a windowing interface or console I/O.
The Eclipse IDE An integrated development environment (IDE) for writing Java programs. Contains (minimally): editor debugger Java compiler Java JVM Free download for your PC See course “Resources” page on the CMSC 202 website Available in all OIT labs around campus We’ll show you more in Lab 1.