📄 your first cup of java (for win32).mht
字号:
<P><FONT size=3D-1>So, you've heard that with the =
Java=20
programming language, you can "write once, run =
anywhere."=20
This means that when you compile your program, you =
don't=20
generate instructions for one specific platform. =
Instead,=20
you generate Java bytecodes, which are instructions =
for the=20
Java Virtual Machine (Java VM). If your =
platform--whether=20
it's Windows, UNIX, MacOS, or an Internet =
browser--has the=20
Java VM, it can understand those=20
bytecodes.</FONT></P></TD></TR></TBODY></TABLE></TD>
<TD vAlign=3Dtop rowSpan=3D2> </TD></TR>
<TR>
<TD vAlign=3Dtop>Your first program, =
<CODE>HelloWorldApp</CODE>,=20
will simply display the greeting "Hello world!". To create =
this=20
program, you will: =20
<UL>
<LI><B>Create a <FONT color=3D#990099>source =
file</FONT>.</B> A=20
source file contains text, written in the Java =
programming=20
language, that you and other programmers can understand. =
You can=20
use any text editor to create and edit source files. =
<BR> =20
<LI><B>Compile the source file into a <FONT=20
color=3D#990099>bytecode file</FONT>.</B> The =
<I>compiler</I>,=20
<CODE>javac</CODE>, takes your source file and =
translates its=20
text into instructions that the <I>Java Virtual Machine=20
</I>(Java VM) can understand. The compiler converts =
these=20
instructions into a bytecode file. <BR> =20
<LI><B>Run the program contained in the bytecode =
file.</B> The=20
Java interpreter installed on your computer implements =
the Java=20
VM. This interpreter takes your bytecode file and =
carries out=20
the instructions by translating them into instructions =
that your=20
computer can understand. </LI></UL>
<P>
<CENTER><IMG height=3D218 alt=3D""=20
=
src=3D"http://java.sun.com/docs/books/tutorial/figures/getStarted/helloWo=
rld.gif"=20
width=3D465 align=3Dbottom NATURALSIZEFLAG=3D"3"></CENTER>
<P></P></TD></TR></TBODY></TABLE>
<P><IMG height=3D16 alt=3D""=20
=
src=3D"http://java.sun.com/docs/books/tutorial/figures/getStarted/arrow.g=
if"=20
width=3D13><FONT size=3D-1><A=20
=
href=3D"http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32=
.html#top">top</A></FONT>=20
<BR>
<HR align=3Dleft width=3D"70%">
<A name=3D2a></A>
<H2><FONT face=3D"Arial, Helvetica, sans-serif" =
color=3Dred>a.</FONT> <FONT=20
face=3D"Arial, Helvetica, sans-serif">Create a Source =
File.</FONT>=20
</H2></FONT>
<BLOCKQUOTE>To create a source file, you have two options:=20
<UL>
<LI>You can save the file <CODE><A=20
=
href=3D"http://java.sun.com/docs/books/tutorial/getStarted/application/ex=
ample/HelloWorldApp.java"=20
target=3Dsource><FONT=20
color=3D#bb000f><CODE>HelloWorldApp.java</CODE></FONT></A><A =
=
href=3D"http://java.sun.com/docs/books/tutorial/getStarted/application/ex=
ample/HelloWorldApp.java"><IMG=20
height=3D11 alt=3D"(in a .java source file)"=20
=
src=3D"http://java.sun.com/docs/books/tutorial/images/sourceIcon.gif"=20
width=3D11 align=3DabsMiddle border=3D0></A></CODE> on your =
computer and=20
avoid a lot of typing. Then, you can go straight to <A=20
=
href=3D"http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32=
.html#2b">step=20
b</A>.<BR><BR>
<LI>Or, you can follow these longer instructions: </LI></UL>
<P><B><FONT color=3D#ff0000>1.</FONT></B> Start NotePad. In a =
new=20
document, type in the following code:</P>
<TABLE cellSpacing=3D2 cellPadding=3D2 width=3D500 border=3D1>
<TBODY>
<TR>
<TD width=3D"100%"><PRE>/**
* The HelloWorldApp class implements an application that
* displays "Hello World!" to the standard output.
*/
public class HelloWorldApp {
public static void main(String[] args) {
// Display "Hello World!"
System.out.println("Hello World!");
}
}
</PRE></TD></TR></TBODY></TABLE>
<BLOCKQUOTE> =20
<TABLE cellSpacing=3D0 cellPadding=3D10 width=3D450 =
border=3D1>
<TBODY>
<TR bgColor=3D#ffffcc>
<TD bgColor=3D#ffffdb>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D402 =
border=3D0>
<TBODY>
<TR>
<TD width=3D"77%"> <B><FONT=20
face=3D"Arial, Helvetica, sans-serif"><FONT=20
color=3D#990000>Be Careful When You=20
Type</FONT></FONT></B></TD>
<TD width=3D"13%"><IMG height=3D30 alt=3D""=20
=
src=3D"http://java.sun.com/docs/books/tutorial/figures/getStarted/typeA.g=
if"=20
width=3D30></TD>
<TD width=3D"10%"><IMG height=3D30 alt=3D""=20
=
src=3D"http://java.sun.com/docs/books/tutorial/figures/getStarted/typea2.=
gif"=20
width=3D30></TD></TR></TBODY></TABLE>
<P><FONT size=3D-1>Type all code, commands, and file =
names=20
exactly as shown. The Java compiler and interpreter =
are=20
<I>case-sensitive</I>, so you must capitalize=20
consistently.</FONT></P>
<CENTER>
<P><CODE>HelloWorldApp <IMG height=3D19 alt=3D""=20
=
src=3D"http://java.sun.com/docs/books/tutorial/figures/getStarted/notequa=
l.gif"=20
=
width=3D20> helloworldapp</CODE></CENTER></P></TD></TR></TBODY></TAB=
LE></BLOCKQUOTE><B><FONT=20
color=3D#ff0000>2.</FONT> </B>Save this code to a file. From =
the menu=20
bar, select <FONT color=3D#990099>File</FONT> > <FONT=20
color=3D#990099>Save As</FONT>. In the <FONT =
color=3D#990099>Save=20
As</FONT> dialog box: </BLOCKQUOTE>
<UL>
<UL>
<LI>Using the <FONT color=3D#990099>Save in</FONT> drop-down =
menu,=20
specify the folder (directory) where you'll save your file. =
In this=20
example, the directory is <CODE>java</CODE> on the =
<CODE>C</CODE>=20
drive.=20
<LI>In the <FONT color=3D#990099>File name</FONT> text box, =
type=20
<CODE>"HelloWorldApp.java"</CODE>, including the double =
quotation=20
marks.=20
<LI>From the <FONT color=3D#990099>Save as type</FONT> =
drop-down menu,=20
choose <FONT color=3D#990099>Text Document</FONT>. =
</LI></UL></UL>
<BLOCKQUOTE>When you're finished, the dialog box should look =
like=20
this:=20
<P>
<CENTER><IMG height=3D165 alt=3D""=20
=
src=3D"http://java.sun.com/docs/books/tutorial/figures/getStarted/saveas.=
gif"=20
width=3D426 align=3Dbottom NATURALSIZEFLAG=3D"3"></CENTER>
<P></P>Now click <FONT color=3D#990099>Save</FONT>, and exit =
NotePad.=20
</BLOCKQUOTE><IMG height=3D16 alt=3D""=20
=
src=3D"http://java.sun.com/docs/books/tutorial/figures/getStarted/arrow.g=
if"=20
width=3D13><FONT size=3D-1><A=20
=
href=3D"http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32=
.html#top">top</A></FONT>=20
<BR>
<HR align=3Dleft width=3D"70%">
<H2><A name=3D2b></A><FONT face=3D"Arial, Helvetica, =
sans-serif"><FONT=20
color=3D#ff0000>b. </FONT>Compile the Source File.</FONT></H2>
<BLOCKQUOTE>
<P>From the <FONT color=3D#990099>Start</FONT> menu, select =
the <FONT=20
color=3D#990099>MS-DOS Prompt</FONT> application (Windows =
95/98) or=20
<FONT color=3D#990099>Command Prompt</FONT> application =
(Windows NT).=20
When the application launches, it should look like this:</P>
<P>
<CENTER><IMG height=3D120 alt=3D""=20
=
src=3D"http://java.sun.com/docs/books/tutorial/figures/getStarted/dos.gif=
"=20
width=3D489 align=3Dbottom NATURALSIZEFLAG=3D"3"></CENTER>
<P></P>
<P>The prompt shows your <I>current directory</I>. When you =
bring up=20
the prompt for Windows 95/98, your current directory is =
usually=20
<CODE>WINDOWS</CODE> on your <CODE>C</CODE> drive (as shown =
above) or=20
<CODE>WINNT</CODE> for Windows NT. To compile your source code =
file,=20
change your current directory to the directory where your file =
is=20
located. For example, if your source directory is =
<CODE>java</CODE> on=20
the <CODE>C</CODE> drive, you would type the following command =
at the=20
prompt and press <FONT color=3D#990099>Enter</FONT>:</P>
<BLOCKQUOTE>
<TABLE cellSpacing=3D2 cellPadding=3D0 border=3D1>
<TBODY>
<TR>
<TD width=3D"100%"><CODE> cd=20
=
c:\java </CODE></TD></TR></TBODY></TABLE></BLOCKQUOTE>
<P>Now the prompt should change to =
<CODE>C:\java></CODE>.</P>
<BLOCKQUOTE>
<HR align=3Dleft>
<B>Note: </B>To change to a directory on a different drive, =
you must=20
type an extra command. <BR> =20
<TABLE cellSpacing=3D2 cellPadding=3D0 width=3D486 =
border=3D0>
<TBODY>
<TR>
<TD width=3D"50%"><IMG height=3D68 alt=3D""=20
=
src=3D"http://java.sun.com/docs/books/tutorial/figures/getStarted/extrast=
ep.gif"=20
width=3D198> </TD>
<TD width=3D"50%">As shown here, to change to the=20
<CODE>java</CODE> directory on the <CODE>D</CODE> =
drive, you=20
must reenter the drive, =
<CODE>d:</CODE></TD></TR></TBODY></TABLE>
<HR align=3Dleft>
</BLOCKQUOTE>
<P>If you enter <CODE>dir</CODE> at the prompt, you should see =
your=20
file.</P>
<P>
<CENTER><IMG height=3D260 alt=3D""=20
=
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -