Aim: To be able to use the 'command line interface' (CLI) without any 'integrated development environment' (IDE).1. Configuring your development environment (context): 1.1. In your home folder, create a working subfolder 'OOPractice'. Note carefully the location of this working folder. (eg: <myWorkLoc> = 'C:\Users\eholohan\Desktop') ___________________________________________ | | |___________________________________________| You can find this location path as follows: Right-click on folder icon Click 'Properties' Copy 'Location' value1.2. Find the location of your 'Java Development Kit' folder. (eg: <myJdkLoc> = 'C:\Program Files\Sun\SDK\jdk') ___________________________________________ | | |___________________________________________| Hint: It is usually under 'C:\Program Files\Java'1.3. In <myWorkLoc> create a subfolder 'myOOProjects' In <myWorkLoc>\myOOProjects use WordPad to create a batch file 'setMyJavaEnv.bat' containing: @echo off cls echo Setting my OO working-environment variables echo. set WORK_HOME=<myWorkLoc> set JAVA_HOME=<myJdkLoc> set PATH=%JAVA_HOME%\bin;%PATH%
echo My working location is %WORK_HOME% echo. echo My installed JDK location is %JAVA_HOME% echo. echo My PATH is %PATH% echo. pause Test 'setMyJavaEnv.bat' 2. Developing your first demo OO project: 2.1. In <myWorkLoc>\myOOProjects create a subfolder 'myDemoProject' In <myWorkLoc>\myOOProjects\myDemoProject use WordPad to create a stub Java source file 'MyDemoMain.java' containing: //MyDemoMain.java package myDemoProject; public class MyDemoMain{ //Class attribute private static String myName = "<myName>"; //Methods public static void displayGreeting() { System.out.println( "\t" + "Greetings, " + myName + ", from MyDemoMain class!" ); } public static void main(String[] args) { displayGreeting(); } } //class MyDemoMain2.2. In <myWorkLoc>\myOOProjects use WordPad to create a batch file 'compileMyDemoProject.bat' containing:
@echo off cls call setMyJavaEnv.bat echo. echo. echo Compiling 'MyDemoMain.java' source code echo (Checking syntax, Generating bytecode) echo. echo on call javac myDemoProject\MyDemoMain.java @echo off echo. dir myDemoProject echo. pause Invoke 'compileMyDemoProject.bat' and check that the file 'MyDemoMain.class' has been generated.2.3. In <myWorkLoc>\myOOProjects use WordPad to create a batch file 'runMyDemoProject.bat' containing:
@echo off cls call setMyJavaEnv.bat echo. echo. echo Running myDemoProject.MyDemoMain class echo. echo on call java myDemoProject.MyDemoMain @echo off echo. echo. pause If step 2.2 was successful, invoke 'runMyDemoProject.bat' and check that its output is as expected. 这个是用文本运行的例子,我们老师教的。 以后只要改相应的文件名就可以了。
without any 'integrated development environment' (IDE).1. Configuring your development environment (context):
1.1. In your home folder, create a working subfolder 'OOPractice'.
Note carefully the location of this working folder.
(eg: <myWorkLoc> = 'C:\Users\eholohan\Desktop')
___________________________________________
| |
|___________________________________________| You can find this location path as follows:
Right-click on folder icon
Click 'Properties'
Copy 'Location' value1.2. Find the location of your 'Java Development Kit' folder.
(eg: <myJdkLoc> = 'C:\Program Files\Sun\SDK\jdk')
___________________________________________
| |
|___________________________________________| Hint: It is usually under 'C:\Program Files\Java'1.3. In <myWorkLoc> create a subfolder 'myOOProjects' In <myWorkLoc>\myOOProjects use WordPad to create a batch file
'setMyJavaEnv.bat' containing: @echo off
cls
echo Setting my OO working-environment variables
echo.
set WORK_HOME=<myWorkLoc>
set JAVA_HOME=<myJdkLoc>
set PATH=%JAVA_HOME%\bin;%PATH%
echo My working location is %WORK_HOME%
echo.
echo My installed JDK location is %JAVA_HOME%
echo.
echo My PATH is %PATH%
echo.
pause Test 'setMyJavaEnv.bat'
2. Developing your first demo OO project:
2.1. In <myWorkLoc>\myOOProjects create a subfolder 'myDemoProject' In <myWorkLoc>\myOOProjects\myDemoProject use WordPad to create
a stub Java source file 'MyDemoMain.java' containing: //MyDemoMain.java
package myDemoProject; public class MyDemoMain{
//Class attribute
private static String myName = "<myName>"; //Methods
public static void displayGreeting() {
System.out.println(
"\t" +
"Greetings, " +
myName +
", from MyDemoMain class!"
);
} public static void main(String[] args) {
displayGreeting();
}
} //class MyDemoMain2.2. In <myWorkLoc>\myOOProjects use WordPad to create a batch file
'compileMyDemoProject.bat' containing:
@echo off
cls
call setMyJavaEnv.bat
echo.
echo.
echo Compiling 'MyDemoMain.java' source code
echo (Checking syntax, Generating bytecode)
echo.
echo on
call javac myDemoProject\MyDemoMain.java
@echo off
echo.
dir myDemoProject
echo.
pause Invoke 'compileMyDemoProject.bat' and check that the file
'MyDemoMain.class' has been generated.2.3. In <myWorkLoc>\myOOProjects use WordPad to create a batch file
'runMyDemoProject.bat' containing:
@echo off
cls
call setMyJavaEnv.bat
echo.
echo.
echo Running myDemoProject.MyDemoMain class
echo.
echo on
call java myDemoProject.MyDemoMain
@echo off
echo.
echo.
pause If step 2.2 was successful, invoke 'runMyDemoProject.bat' and
check that its output is as expected.
这个是用文本运行的例子,我们老师教的。
以后只要改相应的文件名就可以了。