Chapter 2
Introduction to Java
Chapter II Topics
2.1 Introduction
2.2 Getting Started with Java
2.3 A Visit to the United Nations
2.4 Java Bytecode
2.5 Applications and Applets
2.6 Installing the Java Development Kit
2.7 Installing the JCreator IDE
2.8 Text Output With println
2.9 Program Compile Errors
2.10 The Responsible Use of Computers
2.11 Summary
2.1 Introduction
Some students are impatient in general, but when it comes to technology, many students are very impatient. Lots of students march in a computer science class with prior knowledge of using a computer. Such students have played fancy video games, emailed all over town, researched on the Internet, and used computers for word processing and many other applications. These students are not impressed with a dull - black & white - text output, program that displays: Hello Guys.
Computer science is not very different from many other professions in the introductory stages. Few medical students perform open-heart surgery during the first week of medical school. The average law student is not asked to argue a case before the Supreme Court after studying one court case. Navy pilot candidates are not asked to land an airplane on an aircraft carrier at night, during a storm, with one engine shut down, during week-one of flight training. In other words, if you expect to waltz in and start creating programs that will land you a five-thousand dollars a week part-time job, then you will be disappointed.
This chapter will start by showing you the necessary tools to write a simple Java program. Keep in mind that you will be creating your program in a high-level language, Java. This means you need some type of editing environment to write your program. After the program is written you need to go through several steps to create machine code that can be executed by the computer. Learning those fundamental program-writing skills is right now our primary concern.
There are two primary output modes that are available with Java: text and graphics. Text is petty easy and pretty boring. Graphics is exciting, interesting and quite a bit more challenging. The focus in this chapter is to understand first how to execute small, simple text programs. Exciting video games, snazzy interactive web pages are all possible with Java. However, that is not a practical starting point.
It is possible that you already know some other programming language, such as C++. If such is the case, you will learn Java much faster and you may find the topic descriptions in Exposure Java rather slow moving. That is fine, but keep in mind that this text book is written for the student who has no prior knowledge of any programming language or any exposure to computer science concepts. If you have such prior knowledge, you are lucky, but do be careful. Java is similar to some other program languages, but there are also major differences, which can cause difficulties.
2.2 Getting Started with Java
There are many abstract concepts in computer science. These are concepts independent of any programming language. Object Oriented Design, Algorithmic Analysis and various other topics can be discussed without reference to a specific programming language. In high school and in college the title of the course will probably say Computer Scienceor AP Computer Science. The course title will not state Java Programming. Yet here you are in Chapter II with a section titled: Introduction to Java. You will learn many common generic computer science concepts. My experience has shown that students are more comfortable when abstractness and generic concepts come at a later date.
Consider the following. You love to travel. Traveling everywhere is your goal, your passion and your dreams. So what do you do? Just travel? That is not so practical. You want to visit many foreign destinations, but getting there requires familiarity with air travel or train travel or car travel or canoeing or hiking or biking. At this stage let us consider that our goal and destination is to unlock the mysteries of computer science and right now we are using the Java Train to get us there. So come aboard and see where we are heading.
In this first Java introduction you will learn what makes Java a unique language, which is platform independent and works so well with the Internet. You will also find where you can download Java tools for free from Sun Microsystems.
Java makes a distinction between a program meant to be executed in a web page and a program meant to be executed in a regular computer environment. This is a distinction that you need to understand well. Finally, you will observe and practice the steps necessary to take a Java source code program to final execution.
2.3 A Visit to the United Nations
Some students are getting concerned. Perhaps you have heard that Mr. Schram is actually also certified as a Social Studies teacher and the poor man is just getting confused. How does the United Nations help us get started with Java? Good question and you will soon see how the United Nations provides us with an excellent analogy to explain how Java accomplishes some of its main goals. Have you ever observed a United Nations meeting with all the delegates present? It is fascinating to hear around 200 delegates from around the world communicate and yet each delegate speaks in his or her own language. How does everybody else understand what is discussed in roughly 200 different languages?
The delegates could consider that everybody speaks in one universal language. What might that language be? Oh, of course, it is English. That is easy for you to say, because you already speak English. How about Spanish? Spanish is spoken all around the world. It seems like a good candidate for a universal language. Now hold on and be not so quick. In reality more people speak Chinese than English or Spanish, so the logical choice should be Chinese. I trust you see the problem. Convincing 200 delegates to adopt a single language would probably mark the end of the United Nations, as we know it today.
Now the UN could hire translators for every possible language combination. That adds up to about 20,000 different translators and an enormous salary budget for the UN. We have not even considered where the 20,000 translators would be staying in the building. Perhaps you think that 20,000 is an outrageous amount, but think about it. The delegate speaking Punjabi needs 199 translators from Punjabi to each of the other 199 languages. The next delegate needs 198 translators, and then 197 and so forth until the last delegate needs one translator. This means we need to add up all the numbers from 1 to 199. There is a mathematical formula that will compute this:
Sum of all #s from 1 to N = N(N+1) = 199(200) = 19,900 (close to 20,000)
2 2
I hope you do not think that the UN uses such an approach. A clever two-step translation process is used. English is selected as an intermediate language. Do not get confused, because English is not the selected universal language for all the delegates. It is an intermediate language. This requires 199 translators who can speak each one of the 199 languages and English.
Assume that delegate from India speaks Punjabi. His or her message is first translated by one translator from Punjabi to English. Then 198 translators go to work and translate English to each one of the other 198 languages. Suppose that the delegate from Iran responds in Farsi. The process repeats itself in the opposite direction. Farsi is first translated into English. Now English is translated into 198 different languages, including Punjabi, and the delegate from India has a first response. Yes it does result in a time delay, but with a minimal number of translators everybody is able to communicate. The secret of the United Nations communication success is the two-step translation process with the intermediate English step. Java uses a similar two-step translation process to achieve one of its important goals of being platform independent.
2.4 Java Bytecode
Computers have improved tremendously over the years and today most computers communicate rather well with each other. Still, it is common to create a program on one computer that will simply not work on another computer. As a summer workshop presenter for many years I would be careful to bring along my own Pascal and C++ software. Early on, I learned that my programs, carefully written and checked in my own lab, would frequently hiccup in another lab with different computers and software.
One of Java's goals is to be platform independent. The term platform is used abstractly here, but you can use it literally. If you walk from one platform onto another platform that are both of identical size and height it is easy to transfer. Different platforms cause difficulties. In the early days of train travel, Europeans experienced the inconvenience of changing trains at some country borders, because the railroad tracks were different sizes and trains could not continue.
Platform Independence
A programming language is considered platform independent or portable if program source code created on one type of computer platform can execute on another computer platform without any difficulty.
So how does Java accomplish this feat? Programs start out as source code written by a programmer in a somewhat human language, which in this case is Java. Next this source code needs to be translated into machine code that the computer understands. Now comes the problem. A machine code file on one computer does not necessarily make sense to another computer. The code file may contain lovely ones and zeroes of the type that computers use, but not all computers follow the same rules of how to handle this low-level code. Look around when you travel. Not everybody drives on the right side of the road.
Java starts by compiling the high-level source code into bytecode. Bytecode is almost machine code, but not quite. Computers cannot execute bytecode. The bytecode file that is created will be identical regardless of where it was created. Think about the UN. Bytecode is the intermediate English stage. This means that Java compilers need to be available for all the different platforms to create the exact same bytecode for the same source code.
Bytecode is not understood by any computer. It is not the machine code that is normally required for execution. However, bytecode is understood by a special program that is a Java interpreter. That is right, Java uses a compiler to translate programmer's source code into bytecode and then continues with an interpreter to translate and execute the bytecode file line by line.
Bytecode
Bytecode is a low level-level code file that cannot execute as a regular machine code file.
Bytecode is understood, and executed, by a Java interpreter, called a Java Virtual Machine (JVM)
Do you understand the United Nations analogy better now? Platform-A uses the necessary compile software to translate a source code program into bytecode. This bytecode arrives at Platform-B. Platform-B has acquired a Java interpreter that will translate, and execute the bytecode according to Platform-B's requirements.
So the two-step translation process makes sense to you, even though platform-independence was never a high priority in your life? But why use both a compiler and interpreter? Aren't compilers more efficient translators? Good question and compilers do execute much faster than interpreters. However, the efficiency comes with a price. Compilers are much larger programs than interpreters. It takes sophisticated processing to determine if an entire program has correct syntax before the translation process starts. Interpreters are only concerned if one line has correct syntax and then proceeds to translate that one line.
The answer to this question is connected with Sun Microsystems's second goal. Remember that their first goal was to create a platform-independent language, and that goal was achieved with the two-step translation process. Their second goal was to create a language that would be suitable with web pages on the Internet. Achieving this goal requires that a web browser can translate the provided bytecode. Using a compiler does mean efficient execution speed, but it also means a large program that needs to be added to the web browser.
There is also a secondary problem. Compilers first translate the entire file before execution. Now this is a big plus and customers of application programs do not have to wait around to translate any programs. When you word process you do not start by translating some source code program. This was already done for you by the software company. You get the executable program and the only waiting time required is the time that it takes to load the program in memory and execute the instructions of the program. With a web browser there is another story. You click on some Internet link and now your web browser downloads some Java bytecode. Many people will get impatient waiting around for an initial translation process, even if the end result is quicker. If the web browser uses an interpreter that starts spitting out execution after each line of translation that means something is happening, and this approach is more desirable for a web browser.
Java Uses a Compiler and an Interpreter
Java uses a compiler to translate the program source code created by the programmer into bytecode.
Java then continues and uses an interpreter to translate the bytecode into executable machine code line by line.
It must be clearly understood that it is not possible to take some Java bytecode and start executing this on any computer. Yes the code is meant to be portable to any computer with any operating system. However, this only works with a computer that has a Java Virtual Machine(JVM). JVM is the name for the interpreter that takes the bytecode and then executes the program. The name virtualis selected because with this interpreter in place, the computer now acts like any other computer that has the JVM. The key here is that there are many JVMs floating around. Everyone starts with the same bytecode, but these different JVMs all take the bytecode and create the appropriate machine code for its assigned computer.
You may also understand some delay with web pages. First, there is the time required to actually download the web page file. Second, if the file contains Java bytecode then there will be a second delay translating the Java file. Why then use Java? Java has several nice benefits for the Internet. With Java it is possible to make web pages dynamic and interact with the user. Regular web pages can look pretty, but it requires some special language like JavaScript, VBScript or Java to provide information to web pages that can be processed. A second benefit is security. Regular HTML web pages do not hide the code. The code used to create the web page can be viewed in the browser. Frequently, this is not very desirable like in the case where you take an on-line test. It is not possible to see the original Java source code and even if you could view the Java bytecode in the browser, it would not make any sense at all.
2.5 Applications and Applets
The term Java Appletis now so widespread that most computer and Internet users have seen or heard this term rather frequently. Do you know what an applet is? The name implies little application and that definition can cause confusion. A Word Processing program is a very large application. Another program that averages three numbers is a very small application, but the average program can either be an application or an applet in Java.
When a program is written to execute in its own stand-alone environment, it is a regular application. This is different from a program that operates inside a web page. The web page is controlled by HTML, which is Hyper Text Markup Language, a special program language for web pages. When a Java bytecode file operates inside a web page, it must conform to certain web page standards that do not exist in a stand-alone environment. The web page controls the Java bytecode and not the other way around. Now if the bytecode is designed to operate inside a web page it is called an applet, otherwise it is called an application.
Applet or Application?
A Java program designed to operate inside a web page
is called an applet.
A Java program designed to operate in a stand-alone environment is called an application.
If the difference between application and applet is clear then you should realize that an applet could be much larger than an application. Now in reality it is true that most applications are larger than applets; it is just important to know that this is not a requirement.
You must also understand that a web page can have multiple applets inserted throughout the entire website. Remember that it is not possible to create an entire website with Java. The Java applet or applets must operate inside an HTML environment that controls the website.
2.6 Installing the Java Development Kit
Sun Microsystems provides the necessary software on their website to compile and execute Java programs. Sun Microsystems also allows you to download this software free of charge, subject to a variety of legal conditions. Basically, to write Java programs you need an editor, a compiler and an interpreter.
The Basic Java Tools
1. A text editor to write Java program source code
2. A compiler to translate source code into bytecode
3. An interpreter to translate and execute bytecode
The Java software provides you with the necessary compiler and interpreter software for free. The text editor is where there are many choices. There is a choice between a text editor that is part of an integrated environment and a stand-alone text editor. There are various software packages on the market that combine the editor to write the program with the Java translators and various other tools to develop Java programs. Such software has a complete Integrated Development Environment or IDE for Java. Most of the popular Java IDEs need to be purchased, but there are some excellent free products on the market as well.
To truly understand the convenience of an IDE you first would need to understand what is involved with Java program development using a stand-alone text editor. You need to start with a fundamental text editor. It is not necessary that this is a full-fledged word processor. There is no need to underline program statements, display words in different font sizes or spell-check the program. Underlining Java code will confuse the compiler and spell-checkers are familiar with a human language like English, not a programming language like Java. A plain-old editor like Notepad is sufficient, and such a text editor comes free with any type of windows environment. The text editor is used to create, load and save Java programs. All Java programs end with the .java suffix.
Now it is necessary to use the Java compiler to create bytecode. The Java compiler can be accessed at the Command Prompt. If the Java compiler is happy with the syntax of your program, the source code will be translated into bytecode. All bytecode files end with a .class suffix. If some mistake is made in the sentence structure or syntax of your program statements, the compiler will respond with some error messages. At this stage you need to return to the text editor to identify and fix your errors. It is this process of going back forth between text editor and compiler that is avoided by the IDEs of a variety of software products. The IDE is used to create the program and also compile and execute the program. If a mistake is made in the creation of the program, the IDE automatically returns you to the editor part of the IDE to find your mistake. You will not need to be too concerned about using the rather tedious text editor and command prompt since you are going to be using an IDE.
The Three Steps of a Java Program
1. Write the Java source in some text editor.
The source code file must end with .java.
2. Translate the source code file with a Java compiler into
an intermediate bytecode file that will end with .class.
3. Execute the bytecode file with a Java Virtual Machine
(JVM) program, which is an interpreter.
Note: All three of these steps can be done with a text editor and the command prompt or an Integrated Development Environment (IDE), like JCreator.
All this talk about Java compilers, text editors, command prompts and IDEs is great, but you cannot do anything until the Java software in first installed. Right now let us go to the Sun Microsystems web site where the Java software can be downloaded for free. Then we will download an IDE and you will be ready to do some serious Java programming. It is very likely that both the Java software and the IDE are already loaded on your school computers. The detailed steps to perform the software installation yourself are provided so that you can use the same software on your home computer.
Sun Microsystems has a large website with their main home page located at http://java.sun.com. You can start at the home page or you can go straight to the specific web page to download the latest version of Java, which is at http://java.sun.com/javase/downloads/index.jsp.
The latest version - at the time I wrote this - is Java 2 JDK 6.0 Update 3. What that actually means will be explained shortly. This version will be used for the Exposure Java 2008 version, which is taught during the 2008-2009school year. I will show you a sequence of web pages to help you download the correct software, starting with the figure 2.1 first web page.
The information that follows, especially the actual web site displays, may be different from your experience. Web pages change quicker than NFL coaches. First there is the issue of newer versions that constantly change. Second, there may simply be a change in the appearance of the web page that somebody decides requires a change to a new and improved look.
Nevertheless, there is an excellent chance that what you will see on your monitor will at least greatly resemble the pictures that follow. If they don't, you will get additional instruction from your teacher for this section.
Figure 2.1 does not start with the Sun Microsystems home page. You are looking at the first download web page. You can go straight to the download page by typing http://java.sun.com/javase/downloads/index.jsp in the URL window. URL means Uniform Resource Locator. This is the Internet address of the web page you wish to see.
Figure 2.1
You might be curious about the various choices you see in the web page shown by figure 2.1. It appears that you can download something with NetBeans, EE, JDK and JRE. We are not using NetBeans or EE. They may be nice options, but they are not used in your course.
You want to select the first download choice, shown near the bottom of the screen in figure 2.1 -- choice called JDK 6 Update 3. JDK means Java Development Kit, which is precisely the software you need to compile and execute Java programs. 6 Update 3 means Version 6 Update 3.
The JRE choice is included in your JDK download. The Java Runtime Environment (JRE) is necessary to run Java programs that have already been created. Technology people love acronyms. These files are not for programmers or students of computer science. The JRE files are strictly for people who use existing applications, which in this case were created in Java. Earlier you learned about the Java Virtual Machine (JVM), which happens to be the same thing as the JRE. Why stick to one confusing item, if two items confuse even better?
You will now be treated to the customary legal license agreement that you must accept before you can download the software. You may be surprised why Sun Microsystems provides free software and then beats you over the head with legal language. This is actually quite understandable. Companies do not pay the bills by providing products for free. Frequently, the free software is a simpler version of a professional - not free - product. In other cases the product is free under certain conditions. For instance, Sun Microsystems is happy to let you use their software for free to learn Java and to write Java programs, but if you start to make money selling programs that use their software, the rules change.
Figure 2.2 shows the next screen. You need to click on Review License Agreement and read through it and accept the license agreement.
Figure 2.2
Figure 2.3 shows the start of the rather lengthy legal document. I have carefully read this document, and you should read it for yourself. The legal language is confusing, but you can take my word that if you plan to use the software to learn Java programming, you may download this product for free without any concern. Accept the legal terms and then click the Accept License Agreement bar.
Figure 2.3
Sun Microsystems has manydifferent JDKs for a variety of computer platforms, which are shown in figure 2.4. You want to go to the Windows Platform, which provides two options. You can download the Offline or the Online installation file. Both files accomplish the same goal, but there is a significant difference. The Online choice downloads a very small file with instructions to download additional information during software installation. The Offline choice downloads all the necessary files required for installation. This means that you can then install the software and it is not necessary to be connected to the Internet. Download the version that is best for your needs.
Figure 2.4
It would seam logical to put a check mark by the file you want to download and then click Download selected with Sun Download Manager. This may work, but if you simply want to download the file and not mess with a “download manager” whose purpose is “to insure a pleasant download experience” then click on the actual words Windows Offline Installation, Multi-language. That will bring up the window in figure 2.5.
Figure 2.5
After you click Save you will be prompted for a location to save the file. This can be any folder you wish. Sun Microsystems does not care. For now assume that you want to store the file on the Desktop. Figure 2.6 shows the Save As window right before you click the save button.
The 586 in the download file indicates that it is meant for a 586 processor. In the early days of the Intel processors they were called 286, 386, 486 processors and when the 586 processor arrived it was called Pentium. With the continuous technological improvement that chips experience, the naming then became Pentium II, Pentium III and Pentium IV. Java is not real picky, but you do need a Pentium II or better computer to run this Java program.
Figure 2.6
You need to realize that at this stage your have either downloaded the complete Java installation file or a small file that will make installation possible while connected to the Internet. The Java software is not installed at this point. Leave the web browser and find the file that you downloaded. Figure 2.7 shows a file with a coffee cup icon and an involved name. The name is selected to indicate the Java JDK version, as well as the proper platform for this file.
Figure 2.7
Have you wondered about the programming language name Java? It works like this. Java is one of the main islands in the country of Indonesia. The coffee grown on this island is quite famous and named after the island. This is a common practice with many products. Wines like Champagne and Bordeaux are named after the areas in France where the grapes are grown to produce this wine.
Apparently, the creators of Java drank many cups of coffee trying to develop this new language and I suppose they had a taste for Java coffee. Hence, the programming language is named Java.
The Java installation file from Sun Microsystems is now on my Desktop. It may be in the place on your computer or another folder. It does not matter. Navigate to the folder where the installation icon is stored and then double-click on the Java icon to start the installation process. It is possible that when you do this, you might see a security warning message like the one in figure 2.8.
Figure 2.8
Click run and you should get to figure 2.9, where you see another legal agreement. (You may be asked to wait a few seconds before the agreement shows up.) Basically, this license agreement is very similar to the previous agreement you saw at download time. Once again accept the terms of the agreement.
If you are running Windows Vista, you will get some extra security windows that ask permission to continue. This is customary. Accept and continue.
Figure 2.9
The install program starts with the Custom Setup window. The default location where the program is going to be installed will be indicated at the bottom of the setup window under Install to:
C:\ProgramFiles\Java\jdk1.6.0\ or similar folder name is the default location and will work fine for your installation.
Figure 2.10
The installation process will now commence. The actual appearance will be different depending on the earlier selection of offline or online files. Figure 2.11 shows installation using offline. You are about to install a large software program. This is a major installation and it will take quite some time. This part of the setup installs the JDK or Java Development Kit.
Figure 2.11
When the JDK installation is finished, setup returns you to the Custom Setup window, shown in figure 2.12. You will note that the first option, the Development installation, is no longer available. The next installation is the Runtime environment. It is the second part of the setup and makes it possible to run or execute Java programs on your computer. The last two parts are not part of the default installation and will be ignored. You will not return to this window.
Click Next >to continue the installation part. This part will go faster than the development installation. You will now install the JRE. Just click Next > to continue the installation and then click Finish after that.
Figure 2.12
Figure 2.13 shows the window that appears at the conclusion of the installation process. Click Finish and you are done. If you used a CD, especially if you borrowed a CD, make sure to remove the CD and return it to its owner or storage location.
Figure 2.13
If you left the check mark on the previous screen from figure 2.13 a browser window will pop up with the readme file providing information on the new JDK Version 6.
Figure 2.14
2.7 Installing the JCreator IDE
The Java Development Kit (JDK), which you installed in the last section, provides the Java tools to compile Java source code into Java byte code and then you have the Java Runtime Environment (JRE) available to run or execute program. This is all very lovely, but none of these programs helps you to write a program or make it particularly easy to write, compile and execute the programs you create. It is possible to write programs with a text editor like notepad and all programs can be compiled and executed at the command prompt. However, working with the command prompt is quite tedious and in many school computer labs the command prompt has been disabled.
What comes to the rescue is an Integrated Development Environment (IDE), which combines, or integrates, the text editing, compiling, executing, error message reporting and program output all inside one environment. There are many excellent Java IDE programs available on the market for purchase. There are also a surprising number of Java tools on the Internet ready for free downloading. I get numerous emails requesting information about the best Java IDE. I do not know what the best IDE is simply because I have not taken the time to check out all the available products. I have neither the time nor the desire for such a research project. I have looked around until I found something that works well and is free. Free is very important to me, because that means that students can use this software at home. The Java JDK package is already free and now we continue with an IDE that is free as well. This is a great combination for our students.
The IDE that I use right now is JCreator 4.50 LE, distributed and copyrighted by Xinox Software. I will explain shortly where you can download this product. Is JCreator the best IDE on the market? That is an opinion and opinions are not fact. I do know that JCreator works very well and is easy to use. You will also find that certain IDEs work better for creating programs from scratch and others are better for viewing large existing programs. If you are already using some IDE, like CodeWarrior, JBuilder or BlueJ, please continue using that IDE and skip this section. Java programs are not IDE dependent, and this section is inserted for the convenience of my personal students who will be using JCreator.
It is not my intention to explain all the different capabilities of JCreator. I am not so sure if I know all the capabilities. I will explain how to download the software and how to get started. Right now the mission is to be able to work with existing programs and to write simple new programs using JCreator. JCreator may already be present on your school computer. This section explains the download and installation processes for students who want their own home copy of the IDE. This will complete you home computer installation.
JCreator can be downloaded from http://www.jcreator.com. Figure 2.15 shows the home page of the Xinox software company. Look at the left column and click the Download selection.
Figure 2.15
Figure 2.16 shows the Download page. First you need to understand the difference between the PRO version and the LE version. JCreator cannot afford to pass out free software to everybody without making money in some fashion. The company uses a simple approach. They provide a Light Edition (LE), which is a very nice IDE for people who want to learn Java. This makes the LE edition ideal for an educational environment.
Xinox also has a Professional Edition, which includes sophisticated debugging tools for the professional programmer. People like the opportunity to see if the purchase of software is justified. You start by downloading the LE version for free, check it out, and then you can decide to pay for the Pro version. I have seen the Pro version. It is very nice, but the advanced features are not necessary for high school computer science classes.
Figure 2.16 shows that you may select between LE edition v3.50 and v4.50. This may surprise you. Why would anybody want to download an older version? This actually is not so odd. There are various reasons to prefer an older version. Sometimes newer versions have greater computer memory requirements. Your computer may be older and work better with an older version. It is also possible that you prefer the features of an older version better and you are not ready to switch to a different approach. Finally, it is entirely possible that the latest and greatest has not been fully tested. There may be annoying bugs present in a new version. You may prefer to wait, using the older version in the meantime, until the bugs are fixed. That being said, I have had a chance to check out version 4.50 and have decided to use it at John Paul II High School during the 2008-2009 school-year. Proceed and click the appropriate download button.
Figure 2.16
Xinox makes your life simple. They have provided links to the Sun Microsystems web site to help you download the proper Java software. Remember that JCreator is a tool to create Java programs. It is not a compiler and interpreter. JCreator is a great piece of software, but without the JDK (Java Development Kit) it cannot function. This means if you have not already downloaded and installed the JDK, then you need to do so now before JCreator is installed. If you have, you are ready to proceed and click the DOWNLOAD button for JCreator LE v4.50.
Figure 2.17 shows downloading the zip file and saving it to the desktop.
Figure 2.17
Double-click the jcrea450_setup.exe file. Figure 2.18 shows two windows. If you see the first one do not be concerned. JCreator can be trusted so go ahead and click Run. This will bring you to the JCreator welcome screen shown in the second window.
Figure 2.18
Figure 2.19 shows the standard software installation window where you accept the installation agreements. Accept the agreement and click Next. In essence the agreement states that you will not use this software for financial gain. You can do that with the professional version, which is not free. You are a student and in most cases you will not use this software to create software to become a millionaire. If you do then you are violating the agreement.
Figure 2.19
The next window – shown in figure 2.20 – allows you to specify the location of where the software will be installed. The default location is fine. This window also mentions that you must have at least 13.1 MB of free disk space (hard drive) to install JCreator. With modern computers today having 60+ GB of hard drive space that should not be a problem.
Figure 2.20
Click Next three more times -- accepting all defaults. When you see the screen in figure 2.21 below, click Install.
Figure 2.21
When the installation is complete, you still are not done. On the screen shown in figure 2.22 you need to make sure you have a checkmark by Launch JCreator LE before you click Finish.
Figure 2.22
Figure 2.23 shows a user settings screen. The settings should be the same no matter who is using JCreator so click Save settings for all users andthen click Next. Make sure you do NOT click Finish.
Figure 2.23
In figure 2.24 click on .java and then click Next.
Figure 2.24
Figure 2.25
The screen shown in figure 2.25 is where the location of the JDK is specified. Since we installed it in the default directory of C:\Program Files\Java\jdk1.6.0, we need that same default directory for this setting in JCreator. Chances are it showed up automatically. If it did not, click Browse and fix it. Also, it is entirely possible, that the directory might be slightly different. There may be new updates between the time this was written and the time you download the files. Instead of jdk1.6.0, the directory might be jdk1.6.1 or jdk1.6.0_01 or whatever. Once you have the proper directory, you can click Finish.
Right now JCreator is almost ready for use. You should be looking at the monitor with either the display shown in figure 2.26 or figure 2.27. Before we get to business of using an IDE with Java we want to make some setting changes on the software to make working with JCreator simpler.
Figure 2.26
JCreator works with many different windows. In the early learning stages some windows cause more confusion than help. First, we will get rid of the annoying Tip of the Day window. Remove the check by Show tips on startup and click Close.
Figure 2.27
Whether you are seeing the Start Page shown in figure 2.26, or the JCreator website shown in figure 2.27, we do not want either. Both get in our way.
Click Configure and Options.
Expand Workspace by clicking the plus [+].
Click Start up and open the pulldown window by the arrow in Figure 2.28.
Click on None and OK.
Close JCreator.
Figure 2.28
Reload JCreator by double-clicking the JCreator icon which should now be on the desktop.
Next, will get rid of the File View and Package View windows shown in figure 2.29. Just click the X on both. A Class View window may show up when closing the others. Just close that window as well. These windows are useful when working with projects, but we will not be using projects for a while. Right now those windows are just in the way. Your goal is to get your screen to look like the display shown by figure 2.30.
Figure 2.29
Figure 2.30
I personally do not like the default font of the text edit window in JCreator. Change it to a better font with the a few steps using:
Click Configure
Click Options
Click the plus sign of +Java
Click Font
Search for Fixedsys until you see the figure 2.31 display
Click FixedSys
Click OK
Figure 2.31
JCreator wants to be friendly and helpful. There is a special set of settings that will automatically load the last workspace used by JCreator. Perhaps that is practical when somebody works at one computer and nobody else touches the computer. It becomes a different matter in a school where multiple students touch the same computer. There can be some serious confusion when the computer loads a foreign program, which JCreator thinks was your last project. To eliminate this potential problem do the following:
Click Configure
Click Options
Click the word Workspace, but not the plus sign.
Remove all the checks in the Workspace window as you see in figure 2.32.
Click OK.
Figure 2.32
When - and not if - you have errors in your program, the Java compiler can tell you the line number where it found the error. This is only useful if you have line numbers in your program -- which are turned off by default. To turn them on, do the following:
Click Configure and Options.
Click on Java to get Figure 2.33. Do not click on the expand plus.
Check the Show line numbers box and click OK.
Figure 2.33
In terms of program output, we want the text output to open up in its own window. By default it just shows up at the General Output window at the bottom of the screen. You will be writing programs whose output will not fit in this small window. To make the output show up in its own window, do the following:
Click Configure and Options.
Click JDK Tools.
Open the Tool Type pulldown window and select Run Application.
Highlight <default> and click Edit to get Figure 2.34.
Remove the check in Capture output by the arrow.
Click OK.
Figure 2.34
The Task Viewwindow list a sequence of compile errors. This list is not very practical. Frequently, one error can compound other errors and create many messages. It is far more practical to focus on the first error that is created and a clear indication where that error is detected. This is not done well by the Task Viewoutput window. The Build Output window is much more useful. To prevent the Task View window from showing up, do the following:
Click Configure and Options.
Click the expand plus in front of Workspace to get the Figure 2.35 display.
Remove check of Activate window after the build process.
Click OK.
Figure 2.35
2.8 Text Output With println
If JCreator has been set up properly, you should see the display in figure 2.36 when you load Java0201.java.
Figure 2.36
While figure 2.36 shows you exactly what is on the screen, it has a couple problems. The program itself is what we want to focus on and that is hard to see. Also, complete Graphics User Interface (GUI) displays consume a lot of computer memory and also take up a lot of space on the pages for printed versions of this book. Program examples will be shown in a table box followed by a second table box for the program output. Java0201.java is shown again in this format in figure 2.37. The program source code will be shown in an arial font style and the program execution output will be shown in new courier font style.
We will now continue and focus on the elements of text output. As a matter of fact, we are only looking at output. Program input is actually more complex than program output.
Figure 2.37
// Java0201.java
// This program demonstrates text output with println.
// Note how the file name, Java0201, is the same as the
// class identifier Java0201.
// Make sure that you observe "case-sensitivity".
public class Java0201
{
public static void main (String args[])
{
System.out.println("Hello World!");
}
}
Figure 2.38
First I wish to clear up one possible point of confusion. When text programs are executed in JCreator, the words Press any key to continue... are automatically added to the end of the output. This is shown in figure 2.38. Once you press a key the output window will close.
The time has come to take a closer look at a Java program and start to digest what is happening. Program Java0201.java is displayed yet again in figure 2.39, but this time, numbers are supplied for each line in the program to make an easy reference. Please realize that the numbers are not part of the program.
Figure 2.39
#1 // Java0201.java
#2 // This program demonstrates text output with println.
#3 // Note how the file name, Java0201, is the same as the
#4 // class identifier Java0201.
#5 // Make sure that you observe "case-sensitivity".
#6 public class Java0201
#7 {
#8 public static void main (String args[])
#9 {
#10 System.out.println("Hello World!");
#11 }
#12 }
Line Numbers
Brief explanation of the program statement
Lines #1 - #5
These five statements are comments for the program. The comments are not compiled into bytecode, nor will they ever be executed. The two // indicate what follows is a comment.
Line #6
This statement starts your program. Use the Java keywords public class and follow them with the program name.
Line #7
This is the opening brace of the program. Braces contain program blocks.
Line #8
Every application program has a main segment. For now you will use the public static void main (String args[ ])heading with every application program.
Line #9
This is the opening brace of the main module block.
Line #10
Here is the actual program statement that executes something. The keywords System.out.println display the characters placed between the double quotes that follow.
Line #11
This is the closing brace of the main module block.
Line #12
This is the closing brace of the program block.
A program language cannot use human language. Human language is idiomatic, ambiguous, and the meanings of words change. When I first learned English, grass was something you mowed, bad was coming home after curfew and gay was fun loving and spirited. A program written with those words forty-five years ago would not do very well today.
Writing programs has close similarities to writing an essay. There is an important creative part that revolves around telling a story, debating a point or explaining a concept. An essay is made up of individual sentences that follow proper sentence structure, and each sentence is made up of individual words. It is not possible to create an effective sentence without knowing the meaning of the words that make up the sentence. Likewise in a program language you need to know the meaning of the special words that perform some specific purpose. Right now we shall call all the special words used by Java, keywords.
Java Keywords and Program Statements
A Java keyword is a word that has a special meaning in
a program or performs a special function.
Two or more keywords combine to make a program
statement.
Keywords in Java are case-sensitive. This means that
print is a Java keyword, which is not the same as Print.
Have you seen many keywords so far? You certainly have and these keywords include public, class, static, void, main, String and System.out.println. This is already a pretty good size list for starters. At this stage assume that all these keywords, except for System.out.println are necessary in every program and an explanation of their purpose will come at a later time.
In this section you need to learn about println. You did notice that println is attached to some other keywords with a period separation. System.out precedes println and you probably suspect that the periods indicate some type of relationship. You are quite right and System.out means the output of the system. The third keyword, println,displays output and provides a carriage-return/line-feed (crlf), as is shown by program Java0202.java, in figure 2.40.
Figure 2.40
// Java0202.java
// This program demonstrates how to display four lines of text
// using the <println> keyword.
public class Java0202
{
public static void main(String args[])
{
System.out.println("Line 1");
System.out.println("Line 2");
System.out.println("Line 3");
System.out.println("Line 4");
}
}
The program output shows that each println statement generates output on its own line. You might mistakenly think that this is caused by the fact that there are four println statements or four separate lines. Such an assumption is logical, but incorrect. Check out the next program example in figure 2.41. This program is almost identical to the previous program. There is one small, significant difference. Two println keywords are now changed to keyword print.
Figure 2.41
// Java0203.java
// This program demonstrates the difference between <print> and <println>.
// The <println> command adds a "line feed" after the output display.
public class Java0203
{
public static void main(String args[])
{
System.out.print("Line 1");
System.out.print("Line 2");
System.out.println("Line 3");
System.out.println("Line 4");
}
}
Figure 2.41 Continued
In program Java0203.java there are four separate program statements for each print and println keyword, but the output is displayed on two lines. The print keywordgenerates output without a carriage return and the println keyword does include a carriage return.
Do you also notice in the output that the actual characters that are displayed are the same characters that you see in the program statements between double quotes after the println or print keywords? You may decide that it is necessary for println or print to finish the statement with parentheses that contain some string of characters to be displayed. This is not always a requirement. Program example Java0204.java, in figure 2.42, includes one program statement where println is followed by only a set of empty parentheses. It appears that such an "empty" println statement still generates a carriage return.
Figure 2.42
// Java0204.java
// This program shows how to skip a line between statements.
// Using <println> with empty parentheses will generate
// a carriage-return/line-feed.
public class Java0204
{
public static void main (String args[])
{
System.out.println("Text Output on Line 1");
System.out.println();
System.out.println("Text Output on Line 3");
}
}
System.out.println and System.out.print
Both keywords println and print generate an output display of characters contained between double quotes.
Both println and print follow keywords System.out.
println("Java is an island in Indonesia.") will display:
Java is an island in Indonesia.
print("Java is an island in Indonesia.") will also display:
Java is an island in Indonesia.
The keyword println generates an output display followed by a carriage-return/linefeed (crlf).
The keyword print generates an output display without a crlf.
The statement System.out.println(); generates a
crlf, meaning skip a line, without any other output display.
2.9 Program Compile Errors
One of the most difficult aspects of computer programming for beginning students is handling error messages. Chapter 2 is not the place to explain program errors in detail, but you will see two program examples to give you an idea how the Java compiler responds when a program does not compile. The first example shows an error that occurs when a program's file does not match its class name.
You have learned or observed that every Java program appears to have a statement like public class Java0205. You may also have observed that the name, which follows class,called an identifier, is the same name as the source code file name. Basically, you accept such a directive and do not get too excited.
The next program example is stored as program Java0205.java. This source code is compiled into bytecode using the exact same procedure as any of the previous programs, and you probably do not expect any indication of errors. Figure 2.43 shows that the name following class is now Boohiss, which is noticeably different from the convention of using Java0205. Any ideas what the output will be? Are you expecting a few lines of text following the logic of the println keyword? Or do you expect maybe something else? Most observant students will know something is happening. Why does Mr. Schram make such a big deal over this class name and file name if it would not make any difference?
Figure 2.43
// Java0205.java
// This program demonstrates that the file name of a program
// and the public class name must be identical.
// This program will not compile.
public class Boohiss
{
public static void main (String args[])
{
System.out.println("The bytecode file name");
System.out.println("will be the same as the");
System.out.println("public class identifier.");
}
}
Figure 2.44 shows the output of program Java0205.java. Output may be an incorrect term. You are treated to an error message, which tells you in no uncertain terms that the file name and the class name should be identical.
Figure 2.44
File Names and Class Names
The external file name of your program must be identical to the public class name inside your program, minus the java extension. For example:
If you use public class Howdy in your program then
you must save the program with file name Howdy.java.
The next program example is a more typical example of a program with some small error that prevents the creation of a bytecode file. You do need to realize that the compiler first checks to see if the program is written with correct program statements and then proceeds to the second step by creating a bytecode file. Program Java0206.java, in figure 2.45 does not compile. Can you see what is wrong?
Figure 2.45
// Java0206.java
// This program has an intentional mistake.
// The output window indicates an error and the program does not execute.
// Many error messages provide important clues to help fix the problem.
public class Java0206
{
public static void main (String args[])
{
System.out.println("In English...");
System.out.println("Every sentence ends with a period (.)");
System.out.println("In Java...")
System.out.println("Every statement ends with a semicolon (;)");
}
}
Your main mission in this chapter is to learn how to compile and execute programs. The previous two program examples are provided to let you know that executing a program will not be possible unless the compile stage completed successfully. If you see error messages then execution will not be possible.
Program Java0206.java contained a small error. At the end of a statement some required punctuation, a semi-colon, was left out. Java program statements all need to end with semi-colons. If you look at the error message, you will note that the Java compiler did a good job identifying the problem.
2.10 The Responsible Use of Computers
Computers have been made simpler in so many ways. Tedious computations are now performed by computers. Creating any type of writing is so much simpler with a word processor. International travel reservations can be made in minutes, rather than in days. Communication with anybody in the world is now instantly possible and it is very cheap. Information about any conceivable topic can be found on the Internet. And yes, let us not forget that there is now an explosion of electronic games that can be played on computers.
Unfortunately, computers can be used incorrectly as well. Electronic software is easy to copy and many people are tempted to help themselves to a free copy of software. Electronic transfer of money can be abused and computers have created a level of white-collar crimes that were unimaginable before. The Internet provides connections for millions of people, but it also makes it possible to collect private information from people. A whole new criminal area of identity theft has evolved. Computers are marvelous tools, but at the start of this course when you are about to learn some serious computer information, you need to stop and think about the responsibility and consequences of using computers.
This chapter section is designed to make you think and discuss some important computer issues. Do not take this topic lightly. I have experienced many students who have lost hundreds of hours of computer work, because they neglected to back up their efforts. I know several students, who have felony records because they made some seriously bad decisions with their computer knowledge. The evening news also reports cases regularly of naive young teenagers who put their private information on the Internet and find themselves getting involved with adults who take advantage of children who are clueless about the consequences of providing private information to an unknown audience.
Using computers responsibly involves two major categories. What can happen to your computer and you personally and what can you do to other computers and other people. Hopefully, this section will make you realize that you have a tremendous amount of control over using computers properly, and you will neither be a victim nor cause somebody else to become a victim.
Protect Your Computer From the Environment
Computers and computer information are vulnerable. Get used to it. Any electronic device, computers included, does poorly when it is mishandled. Computers should not get too hot or too cold. They should not be dropped down a stair case. You think I am kidding? I have observed three occasions where a student dropped a laptop computer down a staircase. I have seen a student lift up a laptop by the power cord, only to watch it become unplugged and obey the laws of gravity. I have seen a student walk on top of a computer. I have seen a student walk off with a computer connected to a power cord and watch the computer slip out off the holding hands and fall down. I have observed multiple cases of drinks that spilled on computer keyboards, making the keyboard very sticky at best and totally non-functional at worst.
Be aware. For starters do not place a computer where it can fall from a desk or table. Place cords in such a way that people will neither trip nor pull computers down. Do not keep drinks of any kind anywhere near a computer.
Physical damage to a computer happens, but it is not the biggest problem. The number one source of grief for many people, especially students, is loss of data. All computer data is stored in some electronic fashion. For starters the essay you are writing is only stored in the Random Access Memory (RAM) of the computer. The RAM holds information while the computer is powered up. If there is a power outage, no matter how brief, you information will be gone. If you cleverly forget to save your work then it will also be gone. Everything you create needs some type of permanent storage. Your data can be stored on a hard drive, CD, jump drive, network or a second computer. All these devices store the information even when the computer is turned off, but information is still vulnerable. Hard drives do "crash" and CDs can become dirty or become lost. It is wise to have a second backup for anything important.
Please realize the following: it is very human to think that problems only happen to other people. Other people have accidents. Other people drop their computers. Other people have bad hard drives and lose data. I have actually seen a person get ready to pump gas with a burning cigarette in the same hand as the gas hose. He told me it was fine, because he did it before and nothing happened. The poor kid was not familiar with the "fat chance" theory.
Aside from saving programs regularly and then backing up all your data to some secondary backup device, is there something else you can do? Yes, there is. You can use a "battery backup" system. Such a system is much more than an extension cord with some power surge protection. The battery backup system provides power surge protection and keeps the computer turned on when there is power failure. This allows you to safely store your data. Many of these systems also have Automatic Voltage Regulation (AVR), which protects your computer from "dirty" electricity that has over-voltage and under-voltage periods.
Protect Your Computer From Viruses
Computer viruses are a fact of life. Do you actually know what a computer virus is? It is a special program that has two qualities. First, there is the duplication part. A computer virus can attach itself to your computer, search for email addresses and happily spread to computers on your email address book. The virus can also travel to other computers connected to your computer. So far the virus has only traveled and duplicated. The second part of a virus is the payload. The payload is the actual part of the virus that executes a program and does potential harm. There are mild viruses, which only display some silly message. There are also nasty viruses, which delete files on a hard drive, shut down the computer, alter information and cause major headaches to people who rely on computers.
Why do viruses exist? Well there are people with too much time on their hands who apparently have reasons - in their minds - to give major grief to other people. Sometimes computer programmers, who were fired, sabotage computers with a time-delay virus. This happened to Eastern Airlines in the Eighties. Six months after a major computer programmer was fired, the airline reservation computers lost all their data. Not a single passenger was confirmed on any flight. There are also military reasons. During the Cold War, there were hundreds of computer scientists employed by the USSR to create viruses that would handicap computer use in the West. During the first Iraq war, the United States sold computer equipment to France and France in turn sold this equipment to Iraq. The equipment was sold with a time-delay virus. The day that the U.S. attacked Iraq, the virus disabled the anti-aircraft computer programs in Baghdad. U.S. planes could fly over Baghdad with anti-aircraft missiles paralyzed by ineffective software.
Today almost all computers come equipped with some type of virus software. Frequently, people think that they have proper protection. Here is the problem. All anti-virus software comes with a virus definitions file. This file is pretty much guaranteed to be outdated by the time the software arrives in the store and is sold. All anti-virus software alert computer users to get virus updates, but many people ignore these warnings. Do keep in mind that bad things only happen to other people. The better anti-viruses software automatically updates your computer at regular intervals. New viruses are created at an alarming rate.
There are still other access problems invading your computer. Special software, called spyware, snoops around your computer and tries to record information. The spyware may be used for various purposes, but one immediate effect of this extra software is a computer slowdown. There also is your good friend SPAM. SPAM are annoying, unwanted email messages and other miscellaneous pop-up windows, that can slow your computer down tremendously. Most modern email programs include protection against SPAM and spyware.
Protect Your Computer From Improper Access
In the business world and at school, computers are frequently turned on, logged in and then computer users runs off to go to the bathroom, make come copies, get a drink, get a donut, meet with other people or any other reason that removes them from their computers. While they are gone, their computers can be accessed. In this day, it is easy to slip in a "jump drive", which is a miniature memory stick that plugs into a Universal Serial Bus (USB) port. These memory sticks are small, but they can hold up to 2 GBs of memory or more and that is plenty of space to store all kinds of data from your computer.
People with some sophisticated knowledge also know how to make your computer remotely accessible. Later, in their own environment, your computer is accessed and you will not even realize what is happening.
In this day-and-age of laptop computers, access becomes simpler. It is easy to steal a laptop computer. During the last school year, on the last day of school, in my own classroom, a computer was stolen. All laptops look pretty much the same. A few have some personal stickers on the laptop, but the reality is that the action of placing a laptop computer in a backpack is a normal action. It does not look suspicious. In this case, a student left the classroom to talk to a student in an adjacent class, to put together an end-of-year team project. When the student returned at the end of class, his laptop computer was gone.
In a school and business environment, technological devices look very similar. The laptop charger and power cords look all alike. There are different brands of jump drives, but the same brands look identical. Frequently, people use CDs without a label on them. What does this all mean? You can easily lose your stuff, because perfectly honest people confuse your property with their property. In other words put labels on your CD, mark your computers, mark your chargers, mark your jump drives.
The Ethical Use of Computer Software
It is easy to be outraged when somebody steals your property, copies your files, sends you annoying email and invades your computer with nasty viruses. Is proper behavior different in the other direction? It used to amaze me when my wife had child care that parents had no difficulty dropping off sick children. He is only a little sick with a small fever. I do not think he will infect anybody, was a common statement heard in the morning at drop off time. Yet if the child would become sick, there would follow a major crime scene investigation to determine which offending child has infected their child.
What happens if your friend has a new game, a new word processing program or any other new type of software? You sure like that new software, but you cannot afford it. At this point the brain kicks in with its brilliant rationalization skills and minutes later you find it completely justified to convince your friend into a copy. "What hurt is there? It is only one copy and the company won't miss that single copy." Another popular rationalization is to claim that the company charges too much for the software. You, the noble person you are, will fight this tyranny by acquiring the software for free. That will teach the company a lesson.
There is an irony here. Department store merchandise costs more because the cost of shoplifting is added the merchandise cost. Likewise, software would actually be quite a bit cheaper if everybody purchased an honest copy for themselves. Is it surprising that so many people think that this is just fine? Perhaps not, if you consider the "what is a conscience" story.
Some years ago I was reading a book of Native American Indian stories. In one story a young Indian boy asks his father what a conscience is. The father replies that a conscience helps you to tell right from wrong. The son then asks how does a conscience manage to help a person to know what is right. The father replies:
My dear son, every person is born with a conscience. The conscience is a triangle inside your body, located close to your heart. The three edges of the triangle are very sharp. Anytime that you do something wrong, the triangle turns. As the triangle turns, the sharp edges cause pain. You feel this pain when you behave incorrectly. The worse your deed,the faster the triangle turns, causing greater pain.
The son appears puzzled and tells his dad that he understands how the conscience works, but he is confused. The boy says that he has seen several people who have performed major misdeeds and they did not seem bothered by any pain. The father looks solemn and becomes very serious.
You are very observant and very correct for one so young. Yes there are people who commit great sins frequently and yet, they seem unconcerned about the gravity of their acts. You see, the conscience turns a lot when people sin, but the frequent turning makes the sharp edges dull. Soon the triangle can turn freely inside the person and there is no longer pain. It is a great tragedy when somebody has done so much wrong that the conscience is no longer able to help people realize how wrong their actions are.
Software is sold with simple information about licensing. I have purchased a copy of Microsoft Office Teacher Edition 2003. It states directly on the front of the box, inside a conspicuous green star, that the product is licensed for noncommercial use on up to 3 home PCs. That is pretty simple to understand.
Hacking and Other Misdeeds
There are people who think that visiting other networks and other computers is quite innocent. The innocence is based on the fact that no attempt is made to transfer money illegally. No attempt is made to acquire any private information to assume some else's identity to acquire credit cards and other such evils. No these folks are very nice people - so they claim - who happen to do a little bit of innocent hacking into other systems. Besides, if somebody is dumb enough to allow easy access to their computer then they deserve this hacking business.
You may or may not accept this type of explanation, but there is a fundamental problem. There are plenty of hackers who have sufficient knowledge to break into computer systems. Frequently, this knowledge is based on hacking software that is downloaded from the Internet. You now have somebody who is smart enough to figure out how to break into a system with some special program, but in reality these hackers have no clue how their tools work. You can assist somebody else to do considerable damage to computer systems by releasing viruses you do not even realize are attached to the free hacking programs.
There are other problems, which are not hacking. Consider the following. There was a student five years ago who decided to send an email message to all the teachers in the school. This was not hacking. The email addresses of teachers are advertised on the school's web site. His message was the following:
I know where you are and I know what you are doing.
Many teachers were relaxed and responded to come over and help cut the grass or grade papers. Other teachers were scared and went to the police feeling they were stalked. A day later the young man, who was having some fun, found himself arrested and he was in a legal nightmare for the next three months. As a minor everything was eventually dismissed in some fashion. He thought that his clever prank had gone away. A year later he was a senior student and suddenly found out that not a single teacher in his school was willing to write a positive college recommendation for him.
Computer Vandalism
I will finish this section with vandalism deeds that are quite common. Stealing computers is not such a common problem. It is much more common that keys are altered on a keyboard. It is also common that goofy, unwanted programs appear on computers. Sometimes students alter window titles and replace them with some clever message, usually with an improper choice of vocabulary. This type of misbehavior is minor in its effect, but it is annoying and time-consuming to clean up the mess.
2.11 Summary
Sun Microsystems provides free software to compile and execute Java programs. The Java Development Kit (JDK) can be found on Sun's website at http://java.sun.com. The current version (June, 2007) finished by Sun is Version 6.0 update 3.
The Java program language is designed to create full-fledged program applications for industry, as well as applets that will operate inside a web page. Normally, an application is a larger program than an applet. However, an applet is not necessarily a small program.
The secret of Java's success is the use of both a compiler and an interpreter. First, the Java compiler is used to create an intermediate stage in program translation, called bytecode. Second an interpreter is used to translate and execute the bytecode. Sun created multiple interpreters for different platforms. The interpreter is called a Java Virtual Machine (JVM). There are three distinct steps in creating a Java program.
The Java compiler and Java interpreter translate and then execute existing programs. You still need some tools to write the Java source code. It is possible to write code with any text editor and then use the command prompt to provide commands for compiling and executing. It is easier to use an Integrated Development Environment (IDE) like JCreator to assist in program writing. JCreator can be downloaded for free if you use the light edition. JCreator can execute both application programs and applet programs. You need to create a special web page that imports the Java bytecode applet file.
The different components of a program were explained and you saw that a program uses keywords in program statements. Keywords have special meaning to a program. In particular, you looked at the keywords System.out.print and System.out.println. Both keywords display text output. Keyword println adds a carriage-return/line-feed (crlf) to the output statement.
The Java compiler checks to see that every program statement is written with correct syntax before a bytecode file is created. When mistakes are made, the compiler generates error messages about these mistakes.
Computers must be used in a responsible manner. First, care must be taken that a computer is not harmed physically or stolen. Computers are vulnerable and can be easily damaged. Computer data is stored in areas that can be easily corrupted and all important data needs to be backed up in one or more storage areas, like hard drives, CDs or memory sticks. Computers also need up-to-date protection programs against viruses, spyware and SPAM.
Using copyrighted software may be simple, but it is unethical. All software have license agreements that state if the software is free, licensed for one user, multiple users or an entire site, like a school or company. Many people hack into computers, supposedly for fun, unaware that they are inflicting damage with unknown computer hacking programs.