Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Hands On Java Lab 1 Exercise Lab 1: Getting Started with Java   Introduction The main purpose of this lab is to introduce you to the computing environment of your laboratory. You will use the ideas in this lab again and again throughout this course, so you should make every effort to understand not only what, but why you are doing what you are doing at each step. Before we can begin our session, your instructor must inform you how to begin a session with the computer at your particular institution. The way this is done differs from school to school, according to the kind of computer being used, whether they are networked or stand-alone, whether a security system is in place, and so on. Among the things your instructor will tell you will be the answers to the following questions: Should the computer be turned on at the beginning of the exercise and off at the end of the exercise, or does it remain on all of the time? Do users of the computer have personal accounts (requiring one to login to begin an exercise), or can anyone use the computer? If users have personal accounts: How do I find out my username (the name by which I am known to the computer)? How do I find out my password (the secret word that allows access to my account)? Is it necessary to change my password (and if so, how is it done)? In your windowing environment (e.g., MacOS): Must I do something special to enter that environment? What role does the mouse play in that environment? How do I exit that environment? What must I do to quit a session using the computer? About this Manual In this (and every other) exercise, instructions will be printed in this default font (the one you are reading). To help you distinguish the instructions from what appears on your screen, text that you should see displayed on your screen will be shown in this font. Text that you are to type or enter will be shown in the this font. The distinction between typing something and entering something is as follows: to type the letter y, simply press the keyboard key marked y. to enter the letter y, press the keyboard key marked y, followed by the key marked Return (it may be marked Carriage Return, CR, or perhaps Enter on your particular machine). Getting Started Before you can create a program, you must first become familiar with how to control basic operations on the computer. This is one of the fundamental purposes of the operating system (OS). There are two basic methods of interacting with a computer that are in use today. An environment in which you use a mouse to interact with menus, windows, and icons on a computer's screen is called a graphical user interface, or GUI (pronounced gooey) environment. MacOS, Windows-95 and Windows-NT all provide similar GUI environments. Since you are reading this, you are presumably doing so using a software application called a web browser, such as Netscape or Internet Explorer. A web browser is an application that provides a GUI environment for exploring the World Wide Web, a network of computers from around the world linked together to share information. As you have (presumably) already discovered, a web browser lets you download information from remote computers simply by pointing the mouse at a link and clicking its left button. In contrast to a GUI, there are environments in which you repeatedly: are prompted for a command, enter a command, and the machine displays the result of the command. These are called command-line environments -- environments in which you interact with the machine by typing commands following the system prompt. MS-DOS (a precursor of Windows-95 and Windows-NT) and UNIX are examples of operating systems that use the command-line environment. In order to use a command-line environment, you must learn those commands that the environment "understands." This in general makes a command-line environment more difficult to use than a GUI, since you must be able to recall the right commands to use the system. By contrast, users of a GUI environment need only be able to recognize the proper menu choice, link, or icon they need to select in order to make something happen. Follow your instructor's instructions for beginning a session, then click on the appropriate link for the operating system that you are using to continue. Unix/Linux Macintosh OS Windows You are encouraged to look at the other sections to get a feel for how the other operating systems function.   Your First Program Once you have created your labs folder/directory as detailed in the previous section, you are ready to write your first Java program. For now, writing a program consists of three steps: Creating a project to hold your program. Writing a source program in a high-level language (i.e., Java) and storing that program in a file; and Translating that source program into a language much closer to the machine code that your computer uses (i.e., Java byte-code). Since a program can be composed of many files, we will organize our program using a project. To write the program you will use a text editor. Once your program is entered, you can translate it into byte code using a compiler. Graphically the process can be pictured as follows: As we shall see in a later lab exercise, this is a bit of a simplification, but it is sufficiently accurate to give you an idea of what is occurring. For now, just realize that the text editor is what you use to enter a program, and the compiler is what you use to translate it. Creating a Project Both JBuilder and Code Warrior have built-in tools/mechanisms for organizing source files. With SDK we will use a combination of tools. Depending on which environment you will be using click on the appropriate link: SDK Code Warrior JBuilder Editing Your File We want to enter a simple program named which will read in a number and then print out 2, 4, and 8 times its value. Depending on which environment you will be using click on the appropriate link: SDK Code Warrior JBuilder   Translating and Then Running a Program When your source program is entered and saved, it is time to execute the program and look at the results. Again click on the appropriate link to see how it is done: SDK Code Warrior JBuilder    Applying the Scientific Method An important part of any science, including the science of computing, is to be able to observe behavior, form hypotheses, and then design and carry out experiments to test your hypotheses. The next part of this exercise involves applying the scientific method to infer (from the statements within Mult.java) how the certain aspects of Java output system work. Since two heads are (sometimes) better than one, feel free to work through this section with the person sitting next to you. Observe Study your hard copies of Mult.java and its output, positioning the pieces of paper so that you can see both of them simultaneously, side by side. Note in particular the points at which lines end and blank lines appear. Everything that appears in the output is caused by something in Mult.java, so study the text of Mult.java and try to identify what within the program causes the output lines of text to break to a new line where they do. Hypothesis Construct a hypothesis (i.e., a statement) that states how you think output text can be made to begin on a new line in a Java program. Experiment Design an experiment using Mult.java that tests whether or not your hypothesis is false. (Recall that the scientific method can only prove that a hypothesis is false; it can never absolutely prove a hypothesis to be true.) Then modify Mult.java as necessary to perform your experiment, retranslate Mult.java into byte code, and run it. If the resulting behavior indicates that your hypothesis is false, repeat the preceding Observe-Hypothesis-Experiment steps until you form a hypothesis that you are unable to prove to be false. When you are unable to prove your experimental hypothesis to be false, print a hard copy of your modified Mult.java. On that hard copy, write down your hypothesis, your experiment, and circle that part of the program that performs your experiment. Then print a hard copy of its output and note on it the effects of your experiment.   Wrapping Up the Session In the remainder of this exercise, we examine some cleaning up tasks you will need to do in most sessions. Finishing up SDK Code Warrior JBuilder Once you have cleaned up in this manner, end your session with the computer, following your instructor's instructions. Note: If your head feels ready to explode, don't panic! This first lab covers a great deal of material, that you will use over and over again, and as you do so, you will begin to naturally memorize those commands that you use most frequently. You can speed up the process by reviewing each of the steps you took in this exercise and practicing in your free time. Submit: Your original hard copy of Mult.java, the hard copy of its output, a hard copy of your modified Mult.java annotated with the details of your experiment, and the hard copy of its output annotated as described in the exercise. Phrases you should now understand: Integrated Desktop Environment, Folder, File, Navigate, Editor, Compiler and Linker, Hard Copy, Printer. Back to the Prelab Questions Back to This Lab's Table of Contents Forward to the Homework Projects Back to the Table of Contents Back to the Introduction Copyright 2000 by Prentice Hall. All rights reserved.