📄 compile.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD> <TITLE>Java(TM) Language Basics, Part 1, Lesson 1: Compiling & Running a Simple Program</TITLE> <META NAME="AUTHOR" CONTENT="Monica Pawlan"> <META NAME="KEYWORDS" CONTENT="programming, basics, Java 2"> <META NAME="OWNER" CONTENT="Editorial/JDC"> <META NAME="revision" CONTENT="@(#)compile.src 1.23 03/09/00 JDC"> <STYLE TYPE="text/css"> <!-- CODE {font-family: Courier, Monospace; font-size: 12pt} PRE {font-family: Courier, Monospace; font-size: 11pt} --> </STYLE></HEAD><!-- Start Body Insert--><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" ALINK="#FF0000" VLINK="#660066"><!-- End Body Insert--><!-- Start PageTop Insert --><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="100%"> <TR ALIGN="CENTER" VALIGN="TOP"> <TD WIDTH="157" ALIGN="LEFT"> <IMG SRC="/images/pixel.gif" HEIGHT="40" WIDTH="40" ALT=""> <A HREF="http://java.sun.com/index.html"><IMG SRC="/images/javalogo52x88.gif" WIDTH="52" HEIGHT="88" ALT="Java Technology Home Page" BORDER="0"></A> <BR> <IMG SRC="/images/pixel.gif" WIDTH="157" HEIGHT="1" ALT=""></TD> <TD> <FORM NAME="seek1" METHOD="GET" ACTION="http://search.java.sun.com/query.html"> <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%"> <TR> <TD ALIGN="RIGHT"> <IMG SRC="/images/stripelt.gif" WIDTH="6" HEIGHT="14" ALT=""></TD> <TD WIDTH="100%"> <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%"> <TR> <TD BGCOLOR="#CC9966" WIDTH="100%"> <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD> </TR> <TR> <TD> <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD> </TR> <TR> <TD BGCOLOR="#CC9966"> <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD> </TR> <TR> <TD> <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD> </TR> <TR> <TD BGCOLOR="#CC9966"> <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD> </TR> <TR> <TD> <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD> </TR> <TR> <TD BGCOLOR="#CC9966"> <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD> </TR> </TABLE> </TD> <TD ALIGN="LEFT"> <IMG SRC="/images/stripert.gif" WIDTH="6" HEIGHT="14" ALT=""></TD> <TD> <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0"> <TR> <TD VALIGN="CENTER"> <A HREF="http://java.sun.com/a-z/index.html"><IMG SRC="/images/azindex.gif" BORDER="0" WIDTH="72" HEIGHT="11" ALT="A-Z Index"></A></TD> <TD VALIGN="CENTER"> <FONT FACE="Helvetica" SIZE="1"> <INPUT TYPE="text" SIZE="15" MAXLENGTH="128" NAME=qt></FONT></TD> <TD VALIGN="CENTER"> <INPUT TYPE="image" SRC="/images/search.button.gif" WIDTH="55" HEIGHT="14" ALT="Search" value="search" BORDER="0"></TD> </TR> </TABLE> </TD> </TR> </TABLE> </FORM> <P> <TABLE BORDER="0" WIDTH="100%" CELLPADDING="0" CELLSPACING="0"> <TR VALIGN="TOP"> <TD WIDTH="100%"><IMG SRC="/images/chiclet.row.gif" WIDTH="55" HEIGHT="18" ALT=""></TD> <TD ROWSPAN="4" ALIGN="RIGHT" WIDTH="152"> <A HREF="/developer/index.html"><IMG SRC="/images/developer.connection.header.gif" BORDER="0" HEIGHT="42" WIDTH="319" ALT="Java Developer Connection(SM)"></A></TD> </TR> <TR VALIGN="TOP"> <TD BGCOLOR="#FFFFFF" HEIGHT="1" WIDTH="100%"> <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD> </TR> <TR VALIGN="TOP"> <TD BGCOLOR="#CC9966" HEIGHT="1" WIDTH="100%"> <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD> </TR> <TR VALIGN="TOP"> <TD><A HREF="/developer/onlineTraining/"><IMG SRC="/images/online-training.gif" WIDTH="165" HEIGHT="22" ALT="Online Training" BORDER=0></A></TD> </TR> </TABLE> </TD> </TR></TABLE><!-- End PageTop Insert --><!-- Start NavBar Insert --><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="3" BGCOLOR="#FFFFFF" WIDTH="157" ALIGN="LEFT"><!-- tab categories --><TR><TD><A HREF="http://java.sun.com/products/"><IMG SRC="/images/side.tab.products.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Downloads, APIs, Documentation"></A></TD></TR><TR><TD><A HREF="/developer/index.html"><IMG SRC="/images/side.tab.developer.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Java Developer Connection"></A></TD></TR><TR><TD><A HREF="/developer/infodocs/index.shtml"><IMG SRC="/images/side.tab.docs.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Tutorials, Tech Articles, Training"></A></TD></TR><TR><TD><A HREF="/developer/support/index.html"><IMG SRC="/images/side.tab.support.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Online Support"></A></TD></TR><TR><TD><A HREF="/developer/community/index.html"><IMG SRC="/images/side.tab.community.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Community Discussion"></A></TD></TR><TR><TD><A HREF="http://java.sun.com/industry/"><IMG SRC="/images/side.tab.news.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="News & Events from Everywhere"></A></TD></TR><TR><TD><A HREF="http://java.sun.com/solutions"><IMG SRC="/images/side.tab.solutions.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Products from Everywhere"></A></TD></TR><TR><TD><A HREF="http://java.sun.com/casestudies"><IMG SRC="/images/side.tab.case.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="How Java Technology is Used Worldwide"></A></TD></TR><TR><TD> <DIV ALIGN="RIGHT"> <A HREF="/servlet/PrintPageServlet"><IMG SRC="/images/printbutton.gif" WIDTH="155" HEIGHT="25" ALT="Print Button" BORDER="0"></A> </DIV></TD></TR><TR><TD> </TD></TR><!-- End NavBar Insert --><!-- START SUB-NAV --><TR> <TD><!-- INSERT SUB-NAV INFO --> </TD></TR><!-- END SUB-NAV --></TABLE><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0"><TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><!-- Template Version 2.0 --><!-- ================== --><!-- Start Main Content --><!-- ================== --><TABLE><TR><TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif"> <A NAME="top"></A> <DIV ALIGN="RIGHT"> <FONT SIZE="-1"><A HREF="/developer/onlineTraining/index.html">Training Index</A></FONT> <H2>Java<FONT SIZE="-2"><SUP>TM</SUP></FONT> Programming Language Basics, Part 1<BR> <FONT SIZE="3">Lesson 1: Compiling and Running<BR> A Simple Program</FONT></H2> <FONT SIZE="-1">[<A HREF="index.html"><<BACK</A>] [<A HREF="index.html#contents">CONTENTS</A>] [<A HREF="prog.html">NEXT>></A>]</FONT></DIV><P>The computer age is here to stay. Households and businesses all over the world use computers in one way or another because computers help individuals and businesses perform a wide range of tasks with speed, accuracy, and efficiency. Computers can perform all kinds of tasks ranging from running an animated 3D graphics application with background sound to calculating thenumber of vacation days you have coming to handling the payrollfor a Fortune 500 company.<P>When you want a computer to perform tasks, you write a program.A program is a sequence of instructions that define tasks for the computer to execute.This lesson explains how to write, compile, and run a simple program written in the Java<FONT SIZE="-2"><SUP>TM</SUP></FONT> language (Java program) that tells yourcomputer to print a one-line string of text on the console. <P>But before you can write and compile programs, you need to understand what the Java platform is, and set your computerup to run the programs. <UL><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#platform">A Word About the Java Platform</A></FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#setup">Setting Up Your Computer</A></FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#simple">Writing a Program</A></FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#comp">Compiling the Program</A></FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#run">Interpreting and Running the Program</A> </FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#debug">Common Compiler and Interpreter Problems</A></FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#comm">Code Comments</A></FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#api">API Documentation</A></FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#more">More Information</A></FONT></UL><HR><A NAME="platform"></A><H3>A Word About the Java Platform</H3>The Javaplatform consists of the Java application programming interfaces (APIs) and the Java<A HREF="#TJVM"><SUP>1</SUP></A> virtual machine (JVM). <P><IMG SRC="./Art/platform.gif" WIDTH="147" HEIGHT="138" ALT="" ALIGN=LEFT>Java APIs are libraries of compiled code that you canuse in your programs.They let you add ready-made and customizable functionality tosave you programming time. <P>The simple program in this lesson usesa Java API to print a line of text to the console. The console printing capability is provided in the API ready for you to use; you supply the text to be printed. <P>Java programs are run (or interpreted) by another program called the Java VM. If you are familiar with Visual Basic or another interpreted language,this concept is probably familiar to you. Rather than running directly onthe native operating system, the program is interpreted by the Java VMfor the native operating system. This means that any computer system with the Java VM installed can run Java programs regardless of the computer system on which the applications were originally developed. <P>For example, a Java program developed on a Personal Computer (PC) with the Windows NT operating system should run equally well without modification on a Sun Ultra workstation with the Solaris operating system, and vice versa. <A NAME="setup"></A><H3>Setting Up Your Computer</H3>Before you can write and run the simple Java program in this lesson, youneed to install the Java platform on your computer system.<P>The Java platform is available free of charge from the <A HREF="http://java.sun.com/products/jdk/1.2/">java.sun.com</A> web site.You can choose between the Java® 2 Platform software for Windows 95/98/NT or for Solaris. The download page contains the information you need to install and configure the Java platform for writing and runningJava programs. <P><BLOCKQUOTE><HR><STRONG>Note:</STRONG> Make sure you have the Java platform installed and configured for your system before you try to write and run thesimple program presented next.<HR></BLOCKQUOTE><A NAME="simple"></A><H3>Writing a Program</H3>The easiest way to write a simple program is with a text editor.So, using the text editor of your choice, create a text file with the following text, and be sure to name the text file <code>ExampleProgram.java</code>. Java programs are casesensitive, so if you type the code in yourself, pay particularattention to the capitalization.</FONT><PRE>//A Very Simple Exampleclass ExampleProgram { public static void main(String[] args){ System.out.println("I'm a Simple Program"); }}</PRE><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -