School of Computer Science, University of Birmingham Java Lecture notes. M. D. Ryan. September 2001. Two modules together Week 1: introduction • Software Workshop 1 (20+20 credits) • The Java programming language – Taken by: CS, CSSE, CSSEBS • Software Workshop 1A (10+10 credits) • Lecturer: Dr. Mark Ryan – Taken by: AICS, half-CS, BioInf • Teaching assistant : • Both share two lectures and one exercise class per Dr. Dimitar Guelev week. • Demonstrators : Will, Kevin, Adam, Julie, • The 20 credits have an extra lecture a week, and extra exercise classes, and a different examination. James, Samuel, Laurence, James, Simon, Andre, Daniel, Andrew, Paul, Chris, Kumutha, • Please make sure you know whether you are 10cr or 20cr. Peter, Daniel, Kerry, Asuka, . . . Timetable information The WWW page for this module • Lectures: www.cs.bham.ac.uk/courses/java/fyw/ – Monday, 5pm. LT1, Law (20 cr only) – Thursday, 5pm. Vaughan Jeffreys, Education . • From the School home page: – Friday, 1pm. LT1, Law – follow People, Lecturers and professors, Dr • One exercise class per week Mark D Ryan, Personal Homepage, Teaching, – Monday, 1pm. Software workshop, First Year Workshop home • Lab sessions on Tuesdays, Wednesdays, Fridays page. – Suggestion: pick any two hours • The WWW page gives you a week-by-week • Weekly exercises (more for 20cr than 10cr) account of the material, and the exercises. – some assessed, some formative – see the WWW page for assessment details. Books recommended for this module A very simple program • Ira Pohl and Charlie McDowell , Java by Dissection , Addisson Wesley, 2000 . £25. • Cay Horstman, Computing Concepts with Java 2 , /* a program to print “Hello, World” John Wiley & Sons, 1999. £25. on the screen */ • (Reference book) C. Horstmann and G. Cornell, public class Hello Core Java , 4th edition, Vol. 1,2, Prentice Hall, { public static void main(String[] args) 1999. { String greeting = "Hello, World!\n"; System.out.print(greeting); • If you already have a different Java book, use it. } } 1
Points to note The program is a piece of text • Every program has at least one “class”, and • You type it in, using an editor the class declaration begins – The editor you will use is called emacs public class classname – The emacs editor is very well-suited for typing programs, and will help you in various ways • Every program has a class with a main (syntax highlighting, indentation, bracket “method” in it, and that is declared with matching). public static void main – Other editors you have heard of include MS (String[] args) Word; this is not suitable for typing programs. • When you finish typing and editing • You will create a subdirectory for the (correcting) your program, you save it on exercises of the Workshop disk. – You might call it java-workshop – The file name should be Fred.java , where – In which case its full name is Fred is the class name in the program. /home/students/ug/ug12aaa/java-workshop – A disk in Unix is organised into directories, – Potentially, another student could access the which are like folders in Windows 95/98/2000. files in your directory, by doing cd /home/students/ug/ug12aaa/java-workshop – Your directory is /home/students/ug/ug12aaa/ – You can, and should, prevent this by read- protecting this directory with the command – (the ug12aaa part is unique to you) chmod go-rwx java-workshop • When you have saved your file, you will • Having compiled your program, you run it with compile it using the command the command javac Fred.java java Fred – First, you should change to the right directory, – Note the difference between the compiling step, using cd ~/java-workshop javac Fred.java – Compiling the program means transforming it into a form which the computer can execute. and the running step, – If all goes well, the compiler will not produce any error messages, and will create the file java Fred Fred.class . – You can look at Fred.class in emacs if you want, but it will appear to be gibberish. 2
• If there were mistakes in your program, the compiler will complain about them, or they might show up when you run the program. • Three kinds of errors: – Compile-time errors (e.g. syntax errors) Errors that the compiler tells you about. – Run-time errors (e.g., division by 0) These are reported only when you try to run the program. – Programming errors (also called logical errors): it didn’t do what you intended. 3
Recommend
More recommend