G51OOP Object Oriented Programming Comp Sci University of Nottingham Unit 1 : Introduction
Overview Background Teaching Staff Course Details Assessment OOP Summary Resources Programming Programming Languages High Level Languages Interpreters / Compilers Introduction to Java Java History Java Properties Types of Programs JDK tools The HelloWorld program Using CourseMaster
Teaching Staff Lectures : Colin Higgins, CourseMaster Administrator : Essam Eliwa? Lab Assistants - labs, problems classes Web site - http://www.cs.nott.ac.uk/~cah/g51oop/
Course Details (1 st Semester) 20 lectures. Monday 15:00 : LT2 Tuesday 13:00 : LT2 Coursework exercises. Lab sessions. Tuesdays 14:00 to 16:00. Prerequisites : G51PRG (and a little intelligence J ). Objectives : To learn problem solve, to think in an object-oriented manner and to express solutions as sound implementations in Java.
Assessment Some coursework via the CourseMarker system (used to be called CourseMaster and Ceilidh before that).
Assessment Some courseworks that do not count towards assessment. 3 to 4 courseworks that do. Details to be announced later.
Resources Sun file servers (JDK is installed in Solaris) PCs (JDK is installed in all lab PCs) Favourite editor (notepad?) CourseMaster installed in all lab PCs Later Eclipse Web Site root is at http://www.cs.nott.ac.uk/~cah/g51oop/
Reading Recommended? (but don t buy unless needed): Java Gently by Judy Bishop (Addison-Wes). Java. How to Program by Deitel & Deitel (Prentice Hall). Developing Java Software by Winder & Roberts (Wiley). Java Software Solutions by Lewis and Loftus (Pearson/Addison Wesley). Thinking in Java (Bruce Eckel) (available on the web) Other Sources of Information: USE A WEB SEARCH Sun Java Tutorial : http://java.sun.com/docs/books/tutorial/getstarted/index.html WWW general : search in www.google.com! Intense Java Course : http://www.cs.nott.ac.uk/~azt/java.htm
Programming "A program is a sequence of instructions. A recipe, a musical score, and a knitting pattern are all programs." P Grogono, Programming in Pascal. - The way to deal with an impossible task is to chop it down into a number of merely very difficult tasks, and break each one of them into a group of horribly hard tasks, and each one of them into tricky jobs, and each one of them... (Terry Pratchet, Truckers)
Programming Languages There are four basic programming language levels: machine language assembly language high-level language fourth-generation language Each CPU has its own specific machine language The other levels were created to make programming easier
Programming Languages A program must be translated into machine language before it can be executed on a particular type of CPU This can be accomplished in several ways A compiler is a software tool which translates source code into a specific target language Often, that target language is the machine language for a particular CPU type The Java approach is somewhat different
High Level Languages Old-fashioned languages include: BASIC - often used by beginners on home computers. FORTRAN - old but still popular with some scientists and engineers, new versions are introduced every few years. Algol - an elegant little-used internationally designed language, whose features are being incorporated into other languages. COBOL - a widely used and well standardised language used in commerce. APL - an interactive scientific language with a very mathematical notation. PL/I - a failed attempt by IBM at achieving an all-purpose language, now almost dead.
High Level Languages Other Languages : Pascal - good for beginners, often taught as a first language. Modula2 - a development of Pascal to make it more realistic for large programs, and to enable modern program design techniques to be used. C - a practical language, see below. C++ - an object-oriented development of C. ADA - a USA Department of Defense standard, now adopted by the UK Ministry of Defense also, aimed at safe programming for real-time embedded systems. Java A robust, secure, portable, network enabled variation on C/C+ +.
High Level Languages Compare the COBOL: rate_per_hour multiplied by hours_worked gives gross_pay with C/C++: pay = rate * hours Some language aims: understanding, documentation > commercial (eg COBOL). handling vectors or complex numbers > scientific/engineering (FORTRAN). simplicity > beginners (Basic, Pascal). safety > real time systems (ADA, Modula-2). complexity > object-oriented (C++, Eiffel, Java).
Interpreters vs Compilers Interpretation : BASIC & APL are interpreted. Each line is decoded and interpreted by the computer as it is executed. Instructions in loops may have to be interpreted many times. This is inefficient and causes the computer to run slowly. Compilation : Most other languages are compiled. Whole program first analysed by a compiler (another program). Converted into a machine executable form. Runs much faster (an order of magnitude or more). Can apply many types of optimisation during or after compilation. In two parts compilation into an object module, then loading/linking into the executable.
Java: What is it? Sun s Description. Java is a : Simple Object Oriented Distributed Interpreted Robust Secure Architecture Neutral Portable High Performance Multithreaded and Dynamic programming language. It contains an extensive library of classes for graphics programming, input/output, string handling, maths functions, basic data structures, etc.
Java History C language was evolved as a portable operating system language Dennis Ritchie (at Bell labs) developed it from B (which came from BCPL). Originally ran on a DEC PDP-11 computer in 1972. C++ is an object-oriented extension to C developed by Bjarne Stroustroup early 80 s. Sun had an internal corporate research project, Green, in 1991, to develop intelligent consumer devices. Project lead to the language Oak (James Gosling) based on C/C+ +. Oak about to be cancelled when WWW came along. Sun saw renamed Oak to Java and saw potential for use on the web Java formally announced in May 95. Since then, Java generated huge interest.
Java s Early Versions Java was officially announced in May 1995 Java 1.2.2 First Idea Java 1.02 Java 1.1 Java 1.2 Java 1.3 91 92 93 94 95 96 97 98 99 00 ETC! Green Project OAK
Simple Removes areas of C/C++ that cause most errors Memory management Pointers Templates Operator overloading Has a small set of Language Constructs. Borrows the C and C++ syntax. Is free from pointers. Uses Garbage Collection. Does not use header files and pre-processors.
Object Oriented Not hybrid like C++. Supports the basic notions of OO : Abstraction, Modularity, Encapsulation, Hierarchy, Typing, Concurrency, Persistance.
Distributed Works on a variety of platforms. Provides support for : Networking, Internet, Remote Objects.
Interpreted sort of The Java compiler translates Java source code into a special representation called bytecode Java bytecode is not the machine language for any traditional CPU Another software tool, called an interpreter, translates bytecode into machine language and executes it Therefore the Java compiler is not tied to any particular machine Java is considered to be architecture-neutral Java Source File Java Compiler Java Bytecode Java File Bytecode Java File Bytecode File JVM
Robust Exception and Error handling. Multi-Tasking. Memory protection and management. Allows Modular development. Extensive compile-time checking.
Secure The features of bytecode and its interpretation, prevent unintentional or intentional sabotage of compiled programs. Security has been considered in many levels.
Architecture Neutral Bytecode can run on any JVM on any platform. Write Once run Anywhere. JDK implementation on many platforms. Java Bytecode Mac VM WinXP VM Solaris VM MacOS WinXP Solaris Java HW
Portable The bytecode can run on virtual machines (VM) above different operating systems : MacOS Windows95/NT/CE/XP/Vista Solaris OS2 etc It can also run directly on hardware.
High - Performance Multithreading allows more than one task in a program. With JIT compilers the interpreted code compiles at run time and gives almost native code speed. Java Bytecode Native JIT Java VM Operating System Hardware Java OS Java HW
Dynamic Java has been built to support the development of dynamically extendable systems. Java provides dynamic linking of the binary code at runtime.
Java s Genealogy
Java : Types of Programs Applets : Execute on HTML Browsers. Have severe security restrictions. GUI Applications : Are Interpreted and Executed. Use the current s platform s GUI widgets. Mostly use Java s AWT or JFC packages. Console Applications : Simple Text Console.
JDK basic tools javac (Compiler).java->.class The Java Language Compiler that you use to compile programs written in Java into bytecodes. Example : javac HelloWorld.java java (Interpreter) executes.class The Interpreter that you use to run programs written in Java. Example : java HelloWorld javadoc (Doc. generator).java html Generates documentation in HTML format from Java source code. Example : javadoc HelloWorld.java
The First Java Program Filename: HelloWorld.java public class HelloWorld { } public static void main(string argv[] ) { System.out.println("Hello World!!!"); }
CourseMarker CourseMarker is a Courseware system that provides for : The presentation of Information summaries, notes, coursework questions, hints, daily messages The administration of coursework coursework delivery, submission management, overall class management The automatic assessment of coursework solution space modeling, assessment and feedback mechanisms, plagiarism checking tools
Logging in CM client: To login to CM you need both a windows and a unix password. Once you are in windows you can click the CM icon This will get you to the login screen : Unix Password!
Message of the day : Informs you about the latest in exercises Do read it!
CourseMarker Course Level : Options Exit MOTD Notes Summary
CourseMarker Unit Level Notes Summary
CourseMarker Exercise Level : Setup Develop Submit Question View TD Marks Run Run TD
Setup : Puts the skeleton source and other files in your working area Do not setup over your solution
Unix / JCreator For early exercises use your favourite editor under Unix/Windows (notepad?) and compile by hand (via java & javac) For subsequent exercises use Eclipse (you can use anything else you like, but support will not be provided)
Submit After having developed the solution you need to refresh the CM browser by refreshing the course tree structure. You will be asked to confirm and then wait for the result. Expanded Result tree Submission Number Feedback for every check
Other Options : View TD : Allows you to see the testing input that CM uses for the particular exercise. Marks : Allows you to check the exercise s last submission Options : Allows you to change : Visual properties. Editor command.
Summary Background Teaching Staff Course Details Assessment PR1 Summary Resources Programming Programming Languages High Level Languages Interpreters / Compilers Introduction to Java Java History Java Properties Types of Programs JDK tools The HelloWorld program Using CourseMarker