Walshe.faculty.mjc.edu



How to install and use Java from the command lineThese instructions are for Windows 10 computers.These instructions will NOT work on Windows 8, will NOT work on Windows 7, and will NOT work on Vista. Folks, who are using older machines, will have to use Google or YouTube to get instructions on how to install Java.Download and unzip this file: to the setUpJavaDevelopmentEnvironment folder.Double click setUpJavaDevelopmentEnvironment.batIf everything went well, you will see this:Begin photoEmpty window. The window has nothing in it.End photoClose the empty window by clicking on the X in the upper right corner of the window. Launch the cmd windowBegin photoUsing the Windows 10 search textbox for finding an application. The search textbox contains the word “cmd.” The first hit of the search is “Command Prompt App.”End photoCONTINUED ON NEXT PAGEIn the cmd window, type these commands:set PATH=%USERPROFILE%/Downloads/jdk-17/bin;%PATH%cd %USERPROFILE%/Documents/myJavaProjectsnotepad HelloWorld.javaEdit the contents of HelloWorld.java. Make it look like this: Begin photoA screenshot of Notepad with the code for Hello World.public class HelloWorld { public static void main(String args[]) { System.out.println("Hello World"); }}End photoCONTINUED ON NEXT PAGEIn Notepad, save the file.Begin photoScreenshot of Notepad. The top of the screen contains a menu bar. The menu “File” is selected. The menu item “Save” is selected.End photoGo back the cmd consoleBegin photoA screenshot of the task bar for Window 10. An arrow points to the icon for the cmd app (Command Prompt App).End photoIn the cmd console, type this command:javac HelloWorld.javaIMPORTANT: If any message pops up in the cmd console, then STOP!!! Go back to the editor, fix the problem, and try again.In the cmd console, type this command:java HelloWorldIf everything is ok, then you will see this in the cmd console.Hello WorldIf the cmd window is frozen (i.e. no new commands can be typed), then hold down the CTRL or CONTROL key and press the C key. This is known as a CONTROL-C.In the cmd console, type these commands:cd Gamenotepad Game.javaIn notepad, scroll down to find these 3 lines of code: public void paintFrame(Graphics g) { /* Type your code here */ }Change these 3 lines of code to look like this: public void paintFrame(Graphics g) { /* Type your code here */ g.setFont(new Font("Dialog",Font.BOLD,38)); g.drawString("Hello World",100,100); }In notepad, save the file.In the cmd console, type this command:javac Game.javaIMPORTANT: If any message pops up in the cmd console, then STOP!!! Go back to the editor, fix the problem, and try again.In the cmd console, type this command:java GameIf everything is ok, then you will see this:Begin photoScreenshot of a window. The window contains the words “Hello World.”End photoCONTINUED ON NEXT PAGEClose the empty window by clicking on the X in the upper right corner of the window. Another way to close the window is to go back to the cmd window, hold down the CTRL or CONTROL key and press the C key.OPTIONAL TASKS:Are you tired of having to type this every time a new cmd console is launched? set PATH=%USERPROFILE%/Downloads/jdk-17/bin;%PATH%Solution: Google or YouTube how to set the environmental path. You will want to add the FULL PATH to the jdk-17/bin folder to the environment path. You will also want to move this path up to the top of the environment path.Would you rather use a better editor?Solution: Download and install either notepad++ or Visual Studio CodeWould you rather use a Linux console instead of the cmd console?* mv Downloads/jdk-17 to “c:/Program Files/java”:* Google or YouTube how to set the environmental path. Add c:/Program Files/java/jdk-17/bin to the environment path. Move this path to the top of the environment path.* Install CygwinWould you rather use an IDE instead of a text editor?Install Eclipse ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download