⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch35.htm

📁 Java_by_Example,初级经典例子哦,珍藏版本
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<HTML><HEAD><TITLE>developer.com - Reference</TITLE><META NAME="Author" CONTENT="developer.com"><META NAME="Keywords" CONTENT="javascript, ActiveX, VRML, Push, channel,push channel, applet, directory, news, community, developer, internet,intranet, java, java applet, J++, javabeans, java products, tools, javatools, JDK, java development kit, java development environment, JIT,JavaPlan, enterprise tools, JVM, Java Virtual Machine, Java resources, API,browser, java documentation, CDF, Common Desktop Format, RDF, ResourceDescription Framework, Netcaster, Netcast, Castanet, meta-language, metadata,solaris, Solaris, SUN, CGI, Perl, Oracle, database, network, Netscape API,Apache, apache, SSL, mSQL, Netscape, Fasttrack, FastTrack,industry standard, ActiveX bridge, web, internet, site, sitedesign, microsoft, active server pages, asp, iis, nt, win95, 95, html, cgi,frontpage, business, corporate, vbscript, javascript, activex, isapi,database, access, sql, server, www, 3.0, 3.01, 3.02, 3.03, 3.04, 4.0,4.0b2, 4.01, 4.03, 4.04, connection, online, commerce, publisher,publishing, publish, webmaster, dynamic html, dhtml, windows 98, netscape,netscape software, shareware, magazines, jobs, japan, free, freeware, freestuff"><META NAME="description" CONTENT="Developer.com is the leading onlineservice for developers. It includes Gamelan, the official directory for Java, as wellas news, information, tutorials, and directories for other Internet technologiesincluding ActiveX, JavaScript, perl, VRML, Java Beans, push technologies, andother Internet and intranet technologies. Developer.com is also the home ofDeveloper Direct, the Professional Developer's Store, where developers canpurchase and download thousands of Web, authoring and other developmentproducts at some of today's lowest prices."><META NAME="distribution" CONTENT="global"><META NAME="resource-type" CONTENT="document"><META NAME="language" CONTENT="en"></HEAD><BODY BACKGROUND="/images/curve_r-wide.gif" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#DD0000" VLINK="#999999" ALINK="#FF0000"><TABLE><TR><TD VALIGN=TOP WIDTH=120><A HREF="/" ><IMG SRC="/images/masthead_r.gif" WIDTH="100" HEIGHT="78" BORDER="0"ALT="Developer.com Logo"></a></TD><TD><a target="resource window" href="http://adserver.developer.com/cgi-bin/accipiter/adclick.exe/AREA=DCBAN.REF/DT=null"><img src="http://adserver.developer.com/cgi-bin/accipiter/adserver.exe/AREA=DCBAN.REF/DT=null" HEIGHT="60" WIDTH="468" ALT="Click here to support our advertisers"><BR><CENTER>Click here to support our advertisers</CENTER></a></TD></TR></TABLE><!--outer table--><TABLE><!--outer table--><TR><!--outer table--><TD VALIGN="TOP"><!--navbar info --><table><tr><td><A HREF="http://www.developerdirect.com/" ><IMG SRC="/images/button_s.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><b>SHOPPING</b></font></a></td></tr><tr><td><A HREF="/community/jobs/c_jobs.html"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>JOB BANK</B></font></a></td></tr><tr><td><A HREF="http://www.classifieds2000.com/cgi-cls/display.exe?Developer+computer+searchcomputercategories"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>CLASSIFIEDS</B></font></a></td></tr><tr><td><A HREF="/directories/directories.html"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>DIRECTORIES</B></font></a></td></tr><tr><td><A HREF="/reference/"><IMG SRC="/images/button_r.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>REFERENCE</B></font></a><br><a href="/reference/r_library.html"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000">Online Library</a></font></td></tr><tr><td><A HREF="/classroom/"><IMG SRC="/images/button_r.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>LEARNING CENTER</B></font></a></td></tr><tr><td><A HREF="/journal/"><IMG SRC="/images/button_n.gif" width="15" height="11" BORDER="0"><B><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000">JOURNAL</font></B></a></td></tr><tr><td><A HREF="/news/"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><b>NEWS CENTRAL</b></font></a></td></tr><tr><td><A HREF="/downloads/"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><b>DOWNLOADS</b></font></a></td></tr><tr><td><A HREF="/community/" ><IMG SRC="/images/button_c.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>COMMUNITY</B></font></a></td></tr><tr><td><A HREF="/calendar/"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><b>CALENDAR</b></font></a></td></tr><tr><td><A HREF="/about/"><IMG SRC="/images/button_a.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><b>ABOUT US</b></a></font></td></tr></table><table><tr><td><form action="/subscribe/list.cgi" method=post ><img src="/images/rule.gif" width="100" height="2"><br><B><FONT FACE="Arial, Helvetica" SIZE="-1">Journal:</b></font><br><input name='email' value='your e-mail' size="11"><input type='hidden'  name='state' value='Subscribe'></td></tr><tr><td><input type='submit' value='Subscribe'><br><font size="-1">Get the weekly email highlights from the most popular journal for developers!<br><a href="http://www.developer.com/subscribe.html">Current issue</a><img src="/images/rule.gif" width="100" height="2"><input type='hidden' name='name' value='New Subscriber'></FORM></td></tr></table><!--/navbar--><font size="-1"><A HREF="http://www.developer.com">developer.com</a><BR><A HREF="http://www.developerdirect.com">developerdirect.com</a><BR><A HREF="http://www.htmlgoodies.com">htmlgoodies.com</a><BR><A HREF="http://www.javagoodies.com">javagoodies.com</a><br><A HREF="http://www.jars.com">jars.com</a><BR><a href="http://www.intranetjournal.com">intranetjournal.com</a><br><a href="http://www.javascripts.com">javascripts.com</a><br></font><!--outer table--></TD><!--outer table--><TD VALIGN="TOP"><BLOCKQUOTE><P><img src="/images/header_r.gif" width="440" height="50"><P><MAP NAME ="header_r2.gif.map"><AREA SHAPE ="RECT"      HREF ="/reference/author.html"      COORDS ="361,0,440,29"><AREA SHAPE ="RECT"      HREF ="/reference/basic.html"      COORDS ="254,0,360,29"><AREA SHAPE ="RECT"      HREF ="/reference/help.html"      COORDS ="183,0,251,29"><AREA SHAPE ="RECT"      HREF ="/reference/cool.html"      COORDS ="100,0,181,29"><AREA SHAPE ="RECT"      HREF ="/reference/mybook.html"      COORDS ="0,0,100,29"></MAP><MAP NAME ="header_r1.gif.map"><AREA SHAPE ="RECT"      HREF ="/reference/personalize.html"      COORDS ="339,0,439,29"></MAP><p><font face="Arial,Helvetica" size="-1" color="#006666"><A HREF="/reference/r_library.html"><B>All Categories</A> :</B><b><A HREF="/reference/r_java.html">Java</A></b></font><p><META><H1><FONT SIZE=6 COLOR=#Ff0000>Chapter&nbsp;35</FONT></H1><H1><FONT SIZE=6 COLOR=#Ff0000>Using the Interpreter</FONT></H1><HR><P><CENTER><B><FONT SIZE=5><A NAME="CONTENTS">CONTENTS</A></FONT></B></CENTER><UL><LI><A HREF="#WhattheInterpreterDoes">What the Interpreter Does</A><LI><A HREF="#RunningtheInterpreter">Running the Interpreter</A><UL><LI><A HREF="#KeepingFilesUptoDate">Keeping Files Up to Date</A><LI><A HREF="#SettingtheClassPath">Setting the Class Path</A><LI><A HREF="#SwitchingOnVerboseOutput">Switching On Verbose Output</A><LI><A HREF="#ExampleRunninganApplicationwithVerboseOutput">Example: Running an Application with Verbose Output</A><LI><A HREF="#GettingHelp">Getting Help</A></UL><LI><A HREF="#Summary">Summary</A><LI><A HREF="#ReviewQuestions">Review Questions</A><LI><A HREF="#ReviewExercises">Review Exercises</A></UL><HR><P>When you're running applets from within a Web browser, you don'thave to be concerned with the Java interpreter and how it executesJava programs. However, the only way to run Java Standalone applicationsis by loading them directly into the interpreter. These meanstyping a command line in much the same way you did for compilingfiles. The command line not only tells the Java interpreter whichprogram you want to run, but also the command-line options youwant to use when running the program. In this chapter, you studythe Java interpreter in detail.<H2><A NAME="WhattheInterpreterDoes"><FONT SIZE=5 COLOR=#Ff0000>What the Interpreter Does</FONT></A></H2><P>As you learned in the previous chapter, the Java compiler convertsyour Java source code into a .CLASS file. Unlike the files createdby a C compiler, which creates output files that are executableonly on a specific type of computer, this .CLASS file is in aspecial format that is transportable between various computersystems. A .CLASS file contains byte-code information that representsthe commands in your original source code.<P>The key to this intersystem transportability is the Java interpreter.Although a Java byte-code file can be run on any Java-compatiblesystem, the Java interpreter must be created specifically foreach system that needs to run Java programs. Therefore, the Javainterpreter for the Macintosh will not run on a Windows system,even though both systems can execute the same byte-code file.<P>In the previous chapter, you saw a figure that illustrated therelationship between Java source-code files, compilers, byte-codefiles, and the different interpreters. Figure 35.1 reprints thatfigure for your convenience in this discussion.<P><A HREF="f35-1.gif"><B> Figure 35.1 : </B><I>The relationship between the various components of the Java system.</I></A><P><P>When the user installs Java on his system, he must install thecorrect version for that system. Once the installation is complete,the user can connect to the Internet and view any Java appletsthat may be contained in the Web pages he downloads. These appletsare interpreted and executed automatically by Java, thanks tothe connection between the Java-compatible browser and the Javasystem.<P>The only time the user must be concerned with the interpreterdirectly is when he wants to run a Java application, which isrepresented in the same kind of byte-code (.CLASS) file as anapplet. The difference is that Java standalone applications cannotbe executed from within a Web browser. Instead, the user runsthem from his system's command line, invoking the interpreter&quot;by hand,&quot; as it were.<H2><A NAME="RunningtheInterpreter"><FONT SIZE=5 COLOR=#Ff0000>Running the Interpreter</FONT></A></H2><P>In <A HREF="ch32.htm" >Chapter 32</A>, &quot;Writing Java Applications,&quot; you gota brief look at the process of creating and running Java standaloneapplications. In that chapter, you learned that you can run aJava application with the following command:<BLOCKQUOTE><PRE>java filename</PRE></BLOCKQUOTE><P>In this command, <TT>filename</TT> is the name of the application's.CLASS file. For example, if you wanted to run an applicationcalled MyApp, your command line would look like this:<BLOCKQUOTE><PRE>java MyApp</PRE></BLOCKQUOTE><P>Notice that, unlike the compiler, the interpreter doesn't requirethe source file's extension. In fact, if you include the fileextension, the interpreter generates an error (Figure 35.2). Thisis because the interpreter is not able to tell the differencebetween a fully qualified class name (which uses dots) and a filename with an extension (which also uses a dot). Also, the interpreterexpects upper- or lowercase letters in a file name. The file nameMyApp, MYAPP, and myapp are all different to Java's interpreter.<P><A HREF="f35-2.gif"><B> Figure 35.2 : </B><I>Unlike the compiler, the Java interpreter will not accept file extensions.</I></A><P><P>Like the compiler, the Java interpreter recognizes a set of command-lineoptions that you can use to tailor the how the interpreter runs.Those options are listed in Table 35.1.<BR><P><CENTER><B>Table 35.1&nbsp;&nbsp;Command Options for the JavaInterpreter.</B></CENTER><P><CENTER><TABLE BORDER=1 WIDTH=80%><TR VALIGN=TOP><TD WIDTH=166><I><B>Option</B></I></TD><TD WIDTH=424><I><B>Description</B></I></TD></TR><TR VALIGN=TOP><TD WIDTH=166><TT>-checksource</TT></TD><TD WIDTH=424>Instructs the interpreter to run the compiler on files that are not up to date.</TD></TR><TR VALIGN=TOP><TD WIDTH=166><TT>-classpath path</TT></TD><TD WIDTH=424>Determines the path in which the compiler looks for classes.</TD></TR><TR VALIGN=TOP><TD WIDTH=166><TT>-cs</TT></TD><TD WIDTH=424>Same as <TT>-checksource</TT>.</TD></TR><TR VALIGN=TOP><TD WIDTH=166><TT>-D</TT></TD><TD WIDTH=424>Instructs the interpreter to set a property value.</TD></TR><TR VALIGN=TOP><TD WIDTH=166><TT>-debug</TT></TD><TD WIDTH=424>Runs the debugger along with the application.</TD></TR><TR VALIGN=TOP><TD WIDTH=166><TT>-help</TT></TD><TD WIDTH=424>Displays the commands you can use with the interpreter.</TD></TR><TR VALIGN=TOP><TD WIDTH=166><TT>-ms x</TT></TD><TD WIDTH=424>Specifies the amount of memory allocated at startup.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -