When you first invoke the Command prompt option within Windows NT,
you are left at the Command prompt.
Microsoft(R) Windows NT(TM)
(C) Copyright 1985-1996 Microsoft Corp.
C:\>
The "C:\" indicates the current drive and directory. To list the files
within that directory, use the "dir" command.
C:\>dir
...
04/04/00 13:21 <DIR> Projects
11/28/99 17:25 2,251 Readme.txt
04/03/00 16:56 226 regbackup.bat
02/11/99 11:32 657 s2v
10/22/99 13:58 330 sampleitosmsgs.txt
03/08/00 19:21 <DIR> samples
04/04/00 15:29 11,264 Scrap (2).shs
04/04/00 15:28 11,264 Scrap.shs
10/18/99 13:30 6,517 STGPROF.TXT
10/20/99 10:07 3,623 STGSTRING.bak
11/04/99 15:54 5,105 STGSTRING.CPP
10/21/99 13:08 694 STGSTRING.h
10/21/99 15:37 13,523 STGSTRING.obj
10/21/99 13:08 3,959 STGSTRING.~CP
05/25/00 10:13 <DIR> TEMP
11/18/99 14:18 188,731 twsrc.log
01/14/00 19:45 <DIR> usr
05/23/00 18:46 <DIR> vp4
05/17/00 17:45 <DIR> WINNT
05/12/00 18:34 3,939 winzip.log
09/28/98 23:27 <DIR> wrk
75 File(s) 274,306,694 bytes
206,605,312 bytes free
To get just the names of the files and subdirectories, use "dir /w" (for
"wide").
C:\>dir /w
...
mdmfdctk.log [mks]
[Msinput] [MSOffice]
[Multimedia Files] [My Documents]
[My Download Files] Mystorage.stg
MyStore.stg neobox.htm
[NT_SP3] ODBCINST.CNT
ODBCINST.HLP pagefile.sys
[Perl] pkzip.exe
PRIVPROF.BAK PRIVPROF.TXT
problems [Program Files]
[Projects] Readme.txt
regbackup.bat s2v
sampleitosmsgs.txt [samples]
Scrap (2).shs Scrap.shs
STGPROF.TXT STGSTRING.bak
STGSTRING.CPP STGSTRING.h
STGSTRING.obj STGSTRING.~CP
[TEMP] twsrc.log
[usr] [vp4]
[WINNT] winzip.log
[wrk]
75 File(s) 274,306,694 bytes
206,605,312 bytes free
There are too many files here for me to keep track. I'm not going to develop
anything new in this directory. Previously, I'd created a subdirectory to
keep new Java projects separate from everything else. For my own purposes, I
called this directory "C:\usr\jwr\java" but I could have given it any legal
name.
I can change to this other directory using the "cd" or "chdir" (change
directory) command.
C:\>cd usr\jwr\java
C:\usr\jwr\java>
Since I was at the root ("\") of the C: drive I could have used "cd
c:\usr\jwr\java" or "cd \usr\jwr\java" with the same effect. Notice that the
prompt changes to reflect what my new currect directory is.
This directory is supposed to be empty. I can verify that using the "dir"
command again.
C:\usr\jwr\java>dir
Volume in drive C has no label.
Volume Serial Number is FCDB-B118
Directory of C:\usr\jwr\java
05/25/00 11:12 <DIR> .
05/25/00 11:12 <DIR> ..
2 File(s) 0 bytes
206,601,216 bytes free
There are two subdirectories listed. "." is a shorthand reference to the
current subdirectory, "c:\usr\jwr\java". ".." is a shorthand reference
to the parent subdirectory, "c:\usr\jwr".
This subdirectory is going to the "top" of my java project hierarchy.
However, I don't want to make the mistake of starting to create files here.
Instead, I'm going to keep each project in a separate file. I don't have to
be too original to this. So, I just use today's date in YYMMDD format.
I can create a directory for today using the "md" or "mkdir" (make directory)
command.
C:\usr\jwr\java>md 000525
This create directory "c:\usr\jwr\java\000525", but doesn't change my current
directory to that one. To change directories, I have to use the "cd"
command.
C:\usr\jwr\java>cd 000525
C:\usr\jwr\java\000525>
Now, I am where I want to create my source files.
I can create Java source files using any text editor. The Windows operating
system comes with two. One is "Notepad" with which you might be familiar
from the Windows graphical environment. Another is "Edit" which works in
the command console mode. When you invoke "Edit", the text editor opens in
"full screen" mode within the current window. You can toggle the window view
between windowed and "full monitor" using the "ALT-ENTER" keystrokes.
C:\usr\jwr\java\000525>edit JWRHello.java
File Edit Search Options Help
+------------------------------- JWRHELLO.JAV ---------------------------------+
¦_ ?
¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ?
¦? ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦?¦
MS-DOS Editor <F1=Help> Press ALT to activate menus ¦ 00001:001
Java programming involves the creation of "classes". I start coding the
class. Because it is so easy to lose track of braces, I always add braces in
pairs, and then go back to add any additional code between the braces.
public class JWRHello
{
_
}
Classes are composed of "members". This class only needs one member, the
main() method that will be invoked by the Java runtime environment.
public class JWRHello
{
public static void main(String[] args)
{
_
}
}
Methods are composed of statements. The only statement this method needs is
one that sends "Hello, world!" to standard output. When I'm all done, this
is what the screen looks like:
File Edit Search Options Help
+------------------------------- JWRHELLO.JAV ---------------------------------+
¦public class JWRHello ?
¦{ ¦
¦ public static void main(String[] args) ¦
¦ { ¦
¦ System.out.println("Hello, world!"); ¦
¦ } ¦
¦} ¦
¦ ¦
¦ ¦
¦ ¦
¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ?
¦? ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦?¦
MS-DOS Editor <F1=Help> Press ALT to activate menus ¦ 00005:041
To save the file, I press ALT to activate the menus, "F" to drop down the
"File" menu, and then press "S" (for "save") or "A" for "save as".
File Edit Search Options Help
++----------------+------------- JWRHELLO.JAV ---------------------------------+
¦¦ New ¦llo ?
¦¦ Open... ¦ ¦
¦¦ Save ¦id main(String[] args) ¦
¦¦ Save As... ¦ ¦
¦+----------------¦ntln("Hello, world!"); ¦
¦¦ Print... ¦ ¦
¦+----------------¦ ¦
¦¦ Exit ¦ ¦
¦+----------------+ ¦
¦ ¦
¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ?
¦? ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦?¦
F1=Help ¦ Saves current file ¦ 00005:041
If I invoke the "Save As..." command, I'll get a chance to rename the file.
While there is something wrong with the name of the file, I'll just save it
for now and change it later.
File Edit Search Options Help
+------------------------------- JWRHELLO.JAV ---------------------------------+
¦public class JWRHello ?
¦{ +--------------- Save As ----------------+ ¦
¦ public static vo¦ +-------------------------+ ¦ ¦
¦ { ¦ File Name: ¦JWRHELLO.JAV ¦ ¦ ¦
¦ System.out.pri¦ +-------------------------+ ¦ ¦
¦ } ¦ C:\USR\JWR\JAVA\000525 ¦ ¦
¦} ¦ Dirs/Drives ¦ ¦
¦ ¦ +--------------+ ¦ ¦
¦ ¦ ¦ .. ? ¦ ¦
¦ ¦ ¦ [-A-] ¦ ¦
¦ ¦ ¦ [-C-] ¦ ¦ ¦
¦ ¦ ¦ [-D-] ¦ ¦ ¦
¦ ¦ ¦ [-E-] ¦ ¦ ¦
¦ ¦ ¦ [-I-] ¦ ¦ ¦
¦ ¦ ¦ [-M-] ? ¦ ¦
¦ ¦ +--------------+ ¦ ¦
¦ +----------------------------------------¦ ¦
¦ ¦ < OK > < Cancel > < Help > ¦ ¦
¦ +----------------------------------------+ ¦
¦ ¦
¦ ?
¦? ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦?¦
F1=Help Enter=Execute Esc=Cancel Tab=Next Field Arrow=Next Item
I exit from the editor using the "Files|Exit" menu command. This puts me
back at the "DOS prompt". I can verify that the new file exists by using the
"dir" command.
C:\usr\jwr\java\000525>dir
Volume in drive C has no label.
Volume Serial Number is FCDB-B118
Directory of C:\usr\jwr\java\000525
05/25/00 11:22 <DIR> .
05/25/00 11:22 <DIR> ..
05/25/00 11:24 125 JWRHELLO.JAV
3 File(s) 125 bytes
206,600,704 bytes free
This is not quite what I wanted. The editor has truncated the file name that
I gave it initially, and made everything upper case. This would work
eventually, but could become confusing. For the moment, I want the filename
to be "JWRHello.java" exactly.
I can modify the name of a file with the "rename" command.
C:\usr\jwr\java\000525>rename jwrhello.jav JWRHello.java
I can verify that the file was renamed, by using the "dir" command again.
C:\usr\jwr\java\000525>dir
Volume in drive C has no label.
Volume Serial Number is FCDB-B118
Directory of C:\usr\jwr\java\000525
05/25/00 11:25 <DIR> .
05/25/00 11:25 <DIR> ..
05/25/00 11:24 125 JWRHello.java
3 File(s) 125 bytes
206,600,704 bytes free
The file exists, but does it contain what I wrote? Since this is a text
file, I can view the contents by having the command processor type them to
the screen, using the "type" command.
C:\usr\jwr\java\000525>type jwrhello.java
public class JWRHello
{
public static void main(String[] args)
{
System.out.println("Hello, world!");
}
}
Ah.... the quintessential Java application. However, before I can see what
it does, I need to compile the file and then execute the resulting class
file.
Before I can do that, I need to modify the "path" and the "classpath" to
ensure that the Java development environment is available. I've previously
created a batch file to handle this somewhat tedious task. It's located in
the root directory, with the name "j12.bat". I can verify what it does by
typing the contents to the screen.
C:\usr\jwr\java\000525>type \j12.bat
PATH=C:\jdk1.2.2\BIN;%PATH%
SET CLASSPATH=.;C:\jdk1.2.2\lib
This file sets the path and classpath to the development environment
provided with JDK 1.2.2.
I invoke the batch file by just entering its name at the command line. I
don't need to include the ".BAT" extension. However, since the file is not
located in the current directory, or on the path, I need to tell the command
processor where the file is located. In this case, all I need do is affix a
backslash to the name.
C:\usr\jwr\java\000525>\j12
C:\usr\jwr\java\000525>PATH=C:\jdk1.2.2\BIN;C:\Perl\bin;c:\mks\mkssi;c:\mks\mksn
t;C:\WINNT\SYSTEM32;C:\WINNT;C:\PROGRA~1\BORLAND\CBUILDER\BIN;C:\Program Files\R
ational\common;C:\BC5\BIN;C:\PROGRA~1\BORLAND\DELPHI4\BIN;C:\PROGRA~1\BORLAND\VB
ROKER\BIN;C:\PROGRA~1\BORLAND\VBROKER\JRE\BIN
C:\usr\jwr\java\000525>SET CLASSPATH=.;C:\jdk1.2.2\lib
I can test to see if the Java compiler is now available simply by entering
"javac" without any arguments. Since it's supposed to be on the path, I
don't need to tell the processor where it is.
C:\usr\jwr\java\000525>javac
Usage: javac <options> <source files>
where <options> includes:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-O Optimize; may hinder debugging or enlarge class files
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-target <release> Generate class files for specific VM version
Since the compiler is available, I can compile my source file. I make sure
that the name of the file matches the class name in a case-sensitive manner.
I also have to include the ".JAVA" extension.
C:\usr\jwr\java\000525>javac JWRHello.java
If there are errors, I would have to edit the source code again. No response
from the compiler indicates no syntactic errors. I can verify that the class
file was created with the "dir" command.
C:\usr\jwr\java\000525>dir
Volume in drive C has no label.
Volume Serial Number is FCDB-B118
Directory of C:\usr\jwr\java\000525
05/25/00 11:31 <DIR> .
05/25/00 11:31 <DIR> ..
05/25/00 11:31 423 JWRHello.class
05/25/00 11:24 125 JWRHello.java
4 File(s) 548 bytes
206,594,048 bytes free
The class file has been created. You cannot do anything with this file by
itself. It contains Jcode to be interpreted by the Java virtual machine. I
need to invoke a Java interpreter to do something with the file.
As in the case of the compiler, I can test to make sure that the interpreter
is on the path by just entering "java" by itself.
C:\usr\jwr\java\000525>java
Usage: java [-options] class [args...]
(to execute a class)
or java -jar [-options] jarfile [args...]
(to execute a jar file)
where options include:
-cp -classpath <directories and zip/jar files separated by ;>
set search path for application classes and resources
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version
-? -help print this help message
-X print help on non-standard options
Since the Java interpreter seems to be present, I can test my program by
invoking the class with the interpreter. I don't need to use all of the
options to make this simple program work. All that is required for a command
line paramter is the name of the class (without the "class" extension).
C:\usr\jwr\java\000525>java JWRHello
Hello, world!
That's it. Everything is working. I end the session by exiting from the
command console.
C:\usr\jwr\java\000525>exit
|