name
http://my.uopeople.org/mod/book/print.php?id=8892
Learning Guide Unit 1
Site:
University of the People
Course: Course:
CS1102 CS1102 Introductio Introduction n to Programm Programming ing 1
Book Book::
Learn Learnin ing g Gui Guide Unit nit 1
Printed by: Visoth Chuon Date: Date:
Thurs Thursday day,, 3 Februa February ry 2011, 2011, 12:39 12:39 PM
name
http://my.uopeople.org/mod/book/print.php?id=8892
Overview Introduction Download and Install Software Test Installation Reading Assignment Exercise Learning Journal Task Labs
name
http://my.uopeople.org/mod/book/print.php?id=8892
Unit 1: Introduction to Computers and Programming Topics: This unit will address the following topics: Introduction to the operation of a computer The Java Virtual Machine Object Oriented Programming User interface Variables, Strings Objects and Subroutines of Java Text Input and Output Learning Objectives: Become familiar with basic concepts of computer programming Understand the Fundamentals of Object Oriented Programming Acquire the basic skills for simple programming Write simple programs in Java Tasks: Download and install the JDK package and the PSPad editor. Test your installations. Do the Exercise. Post your answer to the question in your Discussion Forum and follow it up with approximately 3-4 comments to other students’ posts. Rate other student’s posts. Perform Lab 1 Perform Lab 2 Post your activities throughout the week in the Learning Journal and complete the Learning Journal
name
http://my.uopeople.org/mod/book/print.php?id=8892
This course is an introduction to computer programming. Programming is the art of explaining to a computer what you want it to do, in exact detail and in a language that the computer can understand. P rogramming is only one part of computer science, but it is the most basic and most central part. It is an activity that requires you to think logically, to solve problems, to express yourself clearly, and ofte n to endure a certain amount of frustration as you try to get your programs to work. The result, though, can be very rewarding. This course has no prerequisites, although a general familiarity with computers would certainly be helpful. Many different languages are used for writing computer programs. Some of the most important are: Assembly language, C, C++, C#, Pascal, BASIC, Cobol, FORTRAN, Ada, Lisp, Smalltalk, Prolog, Perl, Python, Ruby, and Java. It is impossible to learn all the different programming languages. Fortunately, it is possible to learn principles and general techniques of programming that can be applied no matter what language you write in. Although you will work with a specific language, you should try not to lose sight of the general ideas. In this course, we will use the Java programming language. Java is a relatively new language, having been introduced in 1995. In the years since its introduction, it has become one of the most important languages for real application development. It is a very versatile language. Java can be used to write regular desktop applications and to make "applets" that can appear on Web pages. Many complex interactive Web sites are written in Java, and it can be used to write applications for many types of mobile phones. Even high-performance scientific programming has been done in Java. Although C++ might still be the most popular language, Java seems to be at least a close second at this point in time. Java has also become very popular for teaching programming.
name
http://my.uopeople.org/mod/book/print.php?id=8892
Before you can write and run Java programs, you need to install the Java platform on your computer system. The Java platform is available free of charge from the java.sun.com web site. You can choose the Java® platform and an editing environment specific to your operating system (e.g., Windows,Linux, Mac X, etc.) The download page contains the information you need to install and configure the Java platform for writing and running Java programs. In this course, we will carry out severa l programming projects. Therefore, in addition to the Java Development Kit (JDK) you should also install an editor. Downloading and Installing the JDK 1. 2. 3. 4. 5. 6. 7.
Access http://java.sun.com/ Place the mouse on Downloads at the top bar and click on “Java SE” Find the “Java SE Development KIT (JDK)” section and download its current update. Select the platform that you want to install on (e.g. Windows) Agree to the conditions and click on Continue Chose the file and download it (around 73MB) Return to stage 3. Place your mouse over the “ Docs” of “Java SE Development KIT (JDK)” and click on “Installation Guide” 8. Chose the right Platform and System (e.g. JDK / Microsoft Windows / Windows) and click on it 9. Follow the instruction in the Notes.
Downloading Installing an Editor PSPAD PSPAD
name
http://my.uopeople.org/mod/book/print.php?id=8892
PSpad editor is one of many editors that supports the Java syntax and is able to invoke the Java c ompiler and the interpeter. Access http://www.pspad.com/ Choose your preferred language (e.g. English) Click on “Download” and choose the version you want to download. The simplest will be “ Installer.” You might want to download additional add-ons (e.g. Spell Checkers) and extensions (many). Install the program. Setting up the link to the Java Compiler and Interpreter a. Invoke PSpad b. Click on “Setting” at the top bar c. Click on “Highlighter Setting” d. Click on “Java” in the left pane e. Click on the “Compiler” tab f. Fill in the information where Java is located as in the image example below adjusting the locations where Java is installed on your computer and its version. g. Click on “OK” 7. Using PSpad: a. If you drag a Java program to the PSpad icon it will open displaying the program. (Of course you can do this from “File” / “Open” and then selecting the Java file). b. The fourth icon from the right (a page with 010 on it) is the Compiler / Interprete r icon. Click on it to execute. 1. 2. 3. 4. 5. 6.
Other editing environments If you prefer a different editor, we suggest one of the following: jGRASP Netbeans Then select your operating system and the Java SE option Netbeans installation Instructions http://netbeans.org/community/releases/67/install.html Sun’s Java Tutorial: Getting Started Sun provides a good tutorial for getting started using Java and creating the famous first program “Hello World”. The link to the tutorial is given below. http://java.sun.com/docs/books/tutorial/getStarted/cupojava/index.html Classpath You will need to set your Java classpath. The Classpath is an argument set on the command-line, or through an environment variable, that tells the Java Virtual Machine where to look for user-defined c lasses and packages in Java programs. Refer to one of these links: http://en.wikipedia.org/wiki/Classpath_%28Java%29 http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html
name
http://my.uopeople.org/mod/book/print.php?id=8892
Use the HelloWorld.java program provided in the Code library of this unit. Download it and place it in a directory. We recommend that you will set up a directory that will be used for your programming activities throughout this class. All the different subroutines that you will develop and additional ones that are required (such as TextIO.java) should be located there. The file HelloWorld.java contains the very basic HelloWorld program, which simply prints out the message "Hello World!". Since we have not compiled this file for you, to run the program you must first compile the source code file. To do this, open a DOS screen (Start / Run / type CMD and click on OK), navigate using the CD command to the right directory and issue the command javac HelloWorld.java "javac" is the Java compiler program. (This is one case where you really need to use the command-line interface). The result should be the HelloWorld.class file that is the compiled, Java-bytecode version of the Hello World program. Now that the compiled program exists, you do not have to compile the program ever again, unless you want to edit it and change what it does. Run the program with the command: java HelloWorld "java" is the name of the java bytecode interpreter. The computer will say hello to the world. (Note that you say "java HelloWorld" to execute the class file, and not " java HelloWorld.class".) You now know how to compile and run a program. If this works okay, now is the time to te st your PSPad editor: Invoke the PSpad program. Either load the HelloWorld.java program using the File / Open mechanism to locate the program or drag the program into the main screen of the PSPad program or to its icon. Compile the program by using either: File / Compile or CTRL+F9 or Click on the 4th icon from the right at the top bar (the one with 010 on it). You should get the same Hello World! Now check the editing facility by changing the message to Hello Beautiful World! and run it again. Watch for the change of the output message.
name
http://my.uopeople.org/mod/book/print.php?id=8892
Thoroughly read the Syllabus for this course available in the General Information Section on the c ourse home page. For this week, you should read all of Chapter 1 of the textbook and in Chapter 2, Sections 2.1 up to and including section 2.4. The textbook is accessible from the General Information and Forums section of the Course Home Page. You can read the document online or download the pdf to your local computer (preferre d). Be aware that the full textbook in pdf is approximately 5.5 MB. Chapter 1: The Fetch and Execute Cycle: Machine Language Section 1.1 The Fetch and Execute Cycle: Machine Language Section 1.2 Asynchronous Events: Polling Loops and Interrupts Section 1.3 The Java Virtual Machine Section 1.4 Fundamental Building Blocks of Programs Section 1.5 Objects and Object-oriented Programming Section 1.6 The Modern User Interface Section 1.7 The Internet and the World-Wide Web Quiz Chapter 2: Programming in the Small I: Names and Things Section 2.1 The Basic Java Application Section 2.2 Variables and the Primitive Types Section 2.3 Strings, Objects, Enums, and Subroutines Section 2.4 Text Input and Output
name
http://my.uopeople.org/mod/book/print.php?id=8892
Now write your first exercise, you will write a program that does a computation and prints out a result. Here are some facts: Every year, 724 billion cubic yards of water flow out of the Mississippi. There are 1760 yards in a mile. There are 365 days in a year. Here is the question: How many cubic miles of water flow out of the Mississippi every day? Post your first program in your Learning Journal. Discuss any problems you may have encountered, and your enthusiasm at having written your first program, in the Forum.
name
http://my.uopeople.org/mod/book/print.php?id=8892
Answer any 10 of the questions below in your Learning Journal (before you look at the answers). 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24.
Why are machine languages different from one another? What does a computer do when it is presented with a stupid instruction? What is the difference betwee n an Assembly Language instruction and a machine language instruction ? Why do we use languages other than Assembly? How does the computer fetch a particular item in memory? How much information is contained in a register? Give examples of other 6 devices that can be made to work with a computer. Describe the interrupt procedure. Why do we need interrupts? What is a device driver? How do you use type cast to c hange a number into a letter? Use type casting in a numerology example. What happens when you use an arithmetic operator to combine values of different types? What is a program counter? What is asynchronous? Give examples of an asynchronous event. What is a thread? What is multitasking? Give 3 examples. What happens when a thread is blocked? What are some uses of interrupts? What is the difference between synchronous and asynchronous? What is the function of an Operating System? What is the difference between a compiler and an interpreter? Distinguish between an automatic type cast and a forc ed one. Can information be lost in a type cast? Explain.
name
http://my.uopeople.org/mod/book/print.php?id=8892
This course has a required lab component. The labs give you a chanc e to get hands-on experience with the computer and with programming. Remember that you always have someone to help you get through the trouble that inevitably arises by consulting your peers and instructor in the forums. The labs are however generally intended to be individual work and unless otherwise instructed you should be completing them on your own. Each lab will involve some programming. There might also be a few questions for you to answer in writing. You should generate a lab report consisting of your answers to the programming and other exercises. Lab reports should be completed by the end of the learning week. You may be asked to submit the lab report as an assignment to be assessed by your peers. In some cases, the lab will be a starting point for a longer programming assignment that you can work on for several weeks.