简体   繁体   中英

How do you compile the Hello World program for Java?

I am at step 6 in the process of installing JDK onto windows using instructions from this website .

When I attempt to “Set the Current Drive to the drive where you saved your source file Hello.java” by typing “c:”, nothing happens (the instructions indicate that something like C:\\xxx> should appear).

I have saved the hello world file in the C: directory as indicated in the previous step (step 5).

I am trying to start learning Java and any help would be appreciated.

I would suggest you to go for an IDE like eclipse or Netbeans for learning Java as you are learning you should focus more on language basics than configuration try use Eclipse IDE its opensource and very good for Java development and my preference too .

http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/marsr

Try this link which makes Hello world easy

http://www.java-made-easy.com/java-hello-world.html

To write a "Hello World" program follow these steps:

Start Eclipse.
Create a new Java Project:
File->New->Project.
Select "Java" in the category list.
Select "Java Project" in the project list. Click "Next".
Enter a project name into the Project name field, for example, "Hello World Project".
Click "Finish"--It will ask you if you want the Java perspective to open. (You do.)
Create a new Java class:
Click the "Create a Java Class" button in the toolbar. (This is the icon below "Run" and "Window" with a tooltip that says "New Java Class.")
Enter "HelloWorld" into the Name field.
Click the checkbox indicating that you would like Eclipse to create a "public static void main(String[] args)" method.
Click "Finish".
A Java editor for HelloWorld.java will open. In the main method enter the following line.
     System.out.println("Hello World");
Save using ctrl-s. This automatically compiles HelloWorld.java.
Click the "Run" button in the toolbar (looks like a little man running).
You will be prompted to create a Launch configuration. Select "Java Application" and click "New".
Click "Run" to run the Hello World program. The console will open and display "Hello World".

you need to enter this command to navigate to C:\\ drive (I'm not sure if this is case sensitive or not, just to be safe maintain case sensitivity)

cd C:\

after that enter

dir

to confirm whether your file is there.

Then use javac to compile

Make a directory (example C:\\myjava) then save your Hello.java file inside the myjava folder. Open your command prompt and type cd c:\\myjava. Then type javac Hello.java to compile your code.

1)After Installing JDK, Make Sure Java_Home Path is set. Find it Here!

2)After that, Create a new file at Desktop and name it "MyFirstJavaProgram.java"

3) Right click and open newly created file in notepad. 4) Insert following code into it.

public class MyFirstJavaProgram {

   /* This is my first java program.
    * This will print 'Hello World' as the output
    */

   public static void main(String []args) {
      System.out.println("Hello World"); // prints Hello World
   }
}

5) To Compile that program, open command prompt and browse its current path to Desktop.

6) Write command "javac MyFirstJavaProgram.java"

7) to watch output of your program write command "java MyFirstJavaProgram" your output will be at console.

You need to enter the following command:

C:\Users>cd\

It will navigate you to the C: drive then apply the command to navigate to the folder where you saved your source file C:\\xxx

C:\ >cd xxx

then you will get..

C:\xxx>  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM