Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
G51PR1 Introduction to Programming I 2000-2001 University of Nottingham Unit 1 : Introduction Overview 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 CourseMaster Teaching Staff Lecturer : Tsintsifas Athanasios (thanassis) – [email protected] Room:C73 (mon 10-12) (wed 9-10) (fr 10-12) CourseMaster Administrator : Pavlos Symeonidis – [email protected] Room:C73 (tues 2-6) (thur 2-6) Help Desk: Tarek Hegazy, – [email protected] Room : C75 Lab Assistants (terminal room - lab hours). CourseMaster help (via email), [email protected] Course Details 20ish lectures plus lab sessions. One to three coursework exercises per week. You will be assigned to 1 of 4 lab sessions – 2-4 & 4-6 Tuesday – 2-4 &, 4-6 Thursday Prerequisites : None (but you must do CUA concurrently). Objectives : To learn to think algorithmically and to express in sound implementations. Assessment 100% coursework via the CourseMaster system (used to be called Ceilidh, check www.cs.nott.ac.uk/~ceilidh). Assessment Starting on Friday 13th of October Exercises close 10 days after opening (every Monday 12:00) Usually you have three attempts to submit. The last attempt is always the final. Feedback after each submission gives you enough information to infer the correct the solution. More on the process of using CourseMaster on Friday. g STRINGS u gro k c G51PR1 ers ame t nta x Par while for do...while ne sti ng h. s on rsi cu sw itc . e. s a .c tax Syn Al go rith m Re e... nesting els If... Sy out CONDITIONALS objects METHODS LOOPS Lay Op e ra to rs s 5 pe Ty ARRAYS 3 4 ifiers Ident ELEMENTARY PROGRAMMING n tio c e ot on pr acti r t s ab 6 2 Variables ms CLASSES 7 Ba a Stre 8 1 INTRODUCTION nd 9 10 Programming les I/O GUI g ng n ni mp ili un Java w Fi R Co rvie n s ig de ove sin es oc Pr Summary of PR1 9-10 units of 1-2 lectures Resources Sun file servers (jdk is installed in solaris) PCs (jdk is installed in all lab PCs) CourseMaster installed in all lab PCs PFE editor or Emacs-JDE JDK 1.3 Course Transparencies : http://www.cs.nott.ac.uk/~azt/pr1 Reading Recommended: Java Gently by Judy Bishop (Addison-Wes). Java. How to Program by Deitel & Deitel (Prentice Hall). Developing Java Software by Winder & Roberts (Wiley). Java in a Nutshell by Flanagan (O’Reilly). Thinking in Java (Bruce Eckel) (available on the web) Other Sources of Information: CourseMaster : http://www.cs.nott.ac.uk/CourseMaster 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 Versions Java was officially announced in May 1995 Java 1.2.2 Java 1.1 First Idea Java 1.3 Java 1.2 Java 1.02 91 92 Green Project 93 94 95 OAK 96 97 98 99 00 Simple 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 preprocessors. 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 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 Java Bytecode Java Bytecode File Bytecode File 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 Win95 VM Solaris VM MacOS Win95 Solaris Java HW Portable The bytecode can run on virtual machines (VM) above different operating systems : • MacOS • Windows95/NT/CE • 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 : java HelloWorld.java java (Interpreter) executes .class • The Interpreter that you use to run programs written in Java. Example : javac 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!!!"); } } CourseMaster CourseMaster 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! CourseMaster Course Level : Options Exit MOTD Notes Summary CourseMaster Unit Level Notes Summary CourseMaster 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 Develop : PFE is CM’s standard editor for Java source You can always change it later on! Compile : From Menu : Execute->javac After Compilation : Good News Bad News Ctrl + G Gets you to any line number Run a program Two options : 1. From PFE, Execute->java – PFE : Options->Preferences->Execute Menu->java->Edit : – Start command (as independent process OR capture output) 2. From CourseMaster, Exercise Level->Run 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 CourseMaster