Results 1 to 7 of 7
Like Tree2Likes
  • 1 Post By Norm
  • 1 Post By Norm

Thread: Why does'nt my command get compiled?

  1. #1
    rayan is offline Member
    Join Date
    Feb 2017
    Posts
    3
    Rep Power
    0

    Default Why does'nt my command get compiled?

    I have just tried to write my first program, and I keep receiving errors during the compiling process (I'm using the computer's command prompt). so I've just copy pasted this command from internet:

    public static void main(String[] args) {
    // Prints "Hello, World" in the terminal window.
    System.out.println("Hello, World");
    }
    }

    and here is what I got:

    C:\Program Files\Java\jdk1.9.0\bin>javac HelloWorld.java
    HelloWorld.java:1: error: error while writing HelloWorld: HelloWorld.class
    public class HelloWorld {
    ^
    1 error

    * the file's name is: HelloWorld.java
    any ideas why is it?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Why does'nt my command get compiled?

    First thing I see is that you are putting your files in the JDK's bin folder.
    You shouldn't be putting anything in that folder or any of the JDK's folders (there are some exceptions but not now for you).
    Create your own folder for your java files and use the full path to the javac command to execute the compiler.
    For example here is mine:
    C:\Program Files\Java\jdk1.8.0_60\bin\javac.exe -cp . -Xlint -Xdiags:verbose TestCode23.java
    Can you post the complete contents of the HelloWorld.java file wrapped in code tags? What you have posted is missing the class definition line that should be first thing in the source file. Strangely that line is shown at the end of the error message.
    rayan likes this.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    rayan is offline Member
    Join Date
    Feb 2017
    Posts
    3
    Rep Power
    0

    Default Re: Why does'nt my command get compiled?

    Sorry
    here it is:
    Java Code:
    public class HelloWorld {
       public static void main(String[] args) {
          // Prints "Hello, World" in the terminal window.
          System.out.println("Hello, World");
       }
    }
    I still don't get your example though. how should I address the file then?
    Last edited by Norm; 02-11-2017 at 09:32 PM. Reason: Added code tags

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Why does'nt my command get compiled?

    Create a folder for your java source files.
    Copy the .java files to your new folder
    Open a command prompt window and change to the new folder
    Enter the full path to the javac.exe file with your source file name:
    <Path to the javac.exe file> HelloWorld.java

    To save having to use the full path, add the path the the bin folder to the Path Environment variable.

    My example included some extra javac program options (they begin with -). Here is the commandline without the extra options
    C:\Program Files\Java\jdk1.8.0_60\bin\javac.exe TestCode23.java
    Last edited by Norm; 02-11-2017 at 09:37 PM.
    rayan likes this.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    rayan is offline Member
    Join Date
    Feb 2017
    Posts
    3
    Rep Power
    0

    Default Re: Why does'nt my command get compiled?

    Thanks
    This is the whole thing. I don"t know what I'm doing wrong

    Microsoft Windows [Version 10.0.14393]
    (c) 2016 Microsoft Corporation. All rights reserved.

    C:\Users\Miles>cd desktop

    C:\Users\Miles\Desktop>cd new folder

    C:\Users\Miles\Desktop\New folder>dir
    Volume in drive C has no label.
    Volume Serial Number is EEE8-EDEA

    Directory of C:\Users\Miles\Desktop\New folder

    02/12/2017 12:08 AM <DIR> .
    02/12/2017 12:08 AM <DIR> ..
    02/11/2017 10:51 PM 178 HelloWorld.java
    02/11/2017 10:48 PM 102 Juj.java
    2 File(s) 280 bytes
    2 Dir(s) 41,311,363,072 bytes free

    C:\Users\Miles\Desktop\New folder><C:\Program Files\Java\jdk1.9.0\bin\javac.exe> HelloWorld.java
    The system cannot find the file specified.

    C:\Users\Miles\Desktop\New folder>
    Last edited by rayan; 02-11-2017 at 09:53 PM.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Why does'nt my command get compiled?

    The <>s in post#4 are meta characters used to delimit a text and are not part of the command line.
    See the actual commandline I use in post#2

    Do you know about Environment variables? Putting the path to the javac.exe file in the Path variable would allow you to use just javac.exe and not the full path.
    https://docs.oracle.com/javase/8/doc....html#BABGDJFH
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Why does'nt my command get compiled?

    When java is installed it usually adds itself to the PATH.
    So what happens when you type javac -version on the command line?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. where do I find compiled bytecode?
    By Haal in forum New To Java
    Replies: 3
    Last Post: 03-24-2011, 05:15 PM
  2. servlet not compiled
    By rida in forum New To Java
    Replies: 1
    Last Post: 07-03-2010, 12:48 PM
  3. Where is it situated compiled classes?
    By artemff in forum New To Java
    Replies: 1
    Last Post: 12-27-2009, 02:43 AM
  4. Replies: 3
    Last Post: 12-12-2008, 02:44 PM
  5. Using compiled Classes
    By Mindhunter74 in forum NetBeans
    Replies: 17
    Last Post: 12-02-2008, 09:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •