Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    tarun mudgal is offline Member
    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0

    Default How to run the java code (javac problem)

    I've just downloaded the latest jdk(1.7) and going to start with programs but I'm stuck with the problem that how to run the code.
    It's a simple helloword program.

    Before posting here, I went through net (and the forum here) to resolve my problem but coundn't..

    I've added the javac folder directory to path variable.

    here's what it shows when I hit path command (to cmd)

    Microsoft Windows [Version 6.2.8250]
    (c) 2012 Microsoft Corporation. All rights reserved.

    C:\Users\Sachin>path
    PATH=C:\Program Files\Common Files\ArchestrA\;C:\Program Files\PC Connectivity S
    olution\;C:\Windows\system32;C:\Windows;C:\Windows \System32\Wbem;C:\Windows\Syst
    em32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\100\Tools\Bin
    n\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Java\jdk
    1.7.0_05\bin

    C:\Users\Sachin>
    the last path above is the directory for java jdk.

    One more thing, when I entered "C:\Program Files\Java\jdk
    1.7.0_05\bin\javac.exe" (without quotes), it throws the error

    Microsoft Windows [Version 6.2.8250]
    (c) 2012 Microsoft Corporation. All rights reserved.

    C:\Users\Sachin>C:\Program Files\Java\jdk1.7.0_05\bin\javac.exe
    'C:\Program' is not recognized as an internal or external command,
    operable program or batch file
    How to run the java code (javac problem)-java_error.jpg

    [I'm using Win8 consumer preview if anyhow it is needed to resolve the problem]

    KINDLY SEE POST#4 for current issues ( How to run the java code (javac problem) )

    I've attached a pic of what I've done. Please let me know what I'm doing wrong and how to resolve it all.
    thanks
    Last edited by tarun mudgal; 06-30-2012 at 07:37 PM.

  2. #2
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    3

    Default Re: How to run the java code (javac problem)

    If you added the java directory to your path, you don't need to type out the entire directory. Just type in javac followed by the name of the class file you are trying to compile.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: How to run the java code (javac problem)

    C:\Program' is not recognized
    Notice the "not recognzed" command was the symbol before the space,not the full path.(MS put the space in the folder name to catch people). What followed the space ws considered as arguments to the program.
    Try again but enclose the path to the command in"s.


    It's hard to copy and paste from an image. Try copying from the console:

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    Last edited by Norm; 06-30-2012 at 07:13 PM.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    tarun mudgal is offline Member
    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0

    Default Re: How to run the java code (javac problem)

    Quote Originally Posted by Norm View Post
    Notice the "not recognzed" command was the symbol before the space,not the full path.(MS put the space in the folder name to catch people). What followed the space ws considered as arguments to the program.
    Try again but enclose the path to the command in"s.


    It's hard to copy and paste from an image. Try copying from the console:

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    Thanks. That was a "space" issue but now the problem "E:\javac" is not recognised... arises. (The source file is in local disc E)
    How to run the java code (javac problem)-java_error1.jpg

    I'm pasting here whatever cmd was showing
    Microsoft Windows [Version 6.2.8250]
    (c) 2012 Microsoft Corporation. All rights reserved.

    C:\Users\Sachin>"C:\Program Files\Java\jdk1.7.0_05\bin\javac.exe"
    Usage: javac <options> <source files>
    where possible options include:
    -g Generate all debugging info
    -g:none Generate no debugging info
    -g:{lines,vars,source} Generate only some debugging info
    -nowarn Generate no warnings
    -verbose Output messages about what the compiler is doing
    -deprecation Output source locations where deprecated APIs are u
    sed
    -classpath <path> Specify where to find user class files and annotati
    on processors
    -cp <path> Specify where to find user class files and annotati
    on processors
    -sourcepath <path> Specify where to find input source files
    -bootclasspath <path> Override location of bootstrap class files
    -extdirs <dirs> Override location of installed extensions
    -endorseddirs <dirs> Override location of endorsed standards path
    -proc:{none,only} Control whether annotation processing and/or compil
    ation is done.
    -processor <class1>[,<class2>,<class3>...] Names of the annotation processors
    to run; bypasses default discovery process
    -processorpath <path> Specify where to find annotation processors
    -d <directory> Specify where to place generated class files
    -s <directory> Specify where to place generated source files
    -implicit:{none,class} Specify whether or not to generate class files for
    implicitly referenced files
    -encoding <encoding> Specify character encoding used by source files
    -source <release> Provide source compatibility with specified release

    -target <release> Generate class files for specific VM version
    -version Version information
    -help Print a synopsis of standard options
    -Akey[=value] Options to pass to annotation processors
    -X Print a synopsis of nonstandard options
    -J<flag> Pass <flag> directly to the runtime system
    -Werror Terminate compilation if warnings occur
    @<filename> Read options and filenames from file


    C:\Users\Sachin>E:\javac createfirstprogram.java
    'E:\javac' is not recognized as an internal or external command,
    operable program or batch file.

    C:\Users\Sachin>

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: How to run the java code (javac problem)

    'E:\javac' is not recognized
    Why is the E:\ path there? The error says that the OS can not find a javac.exe file in the E: folder

    Did you try either the full path or no path?
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    tarun mudgal is offline Member
    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0

    Default Re: How to run the java code (javac problem)

    Quote Originally Posted by Norm View Post
    Why is the E:\ path there? The error says that the OS can not find a javac.exe file in the E: folder

    Did you try either the full path or no path?
    E is the disc where the source file exist.
    so I tried E:\javac createfirstprogram.java
    where createfirstprogram is the name of the source file. Am I doing anything wrong?

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: How to run the java code (javac problem)

    E:\javac
    That tells the OS to look in E: for the javac.exe file.

    You should use the cd (change directory) command to get to the folder with the source file.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    tarun mudgal is offline Member
    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0

    Default Re: How to run the java code (javac problem)

    Quote Originally Posted by Norm View Post
    That tells the OS to look in E: for the javac.exe file.

    You should use the cd (change directory) command to get to the folder with the source file.
    I tried this
    Microsoft Windows [Version 6.2.8250]
    (c) 2012 Microsoft Corporation. All rights reserved.

    C:\Users\Sachin>javac E:\createfirstprogram.java

    C:\Users\Sachin>javac E:\createfirstprogram.java

    C:\Users\Sachin>
    The command did work but I didn't get the output (that is to print the string) whereas a "class" file was created after the command at the directory of the source file.

    here's the error I'm getting when I try to change the directory to "E:" (where the source file is located)
    javac: file not found: createfirstprogram.java
    How to run the java code (javac problem)-java_error2.jpg

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: How to run the java code (javac problem)

    Sorry, the cd doesn't work for directories. Just enter the drive letter:
    For example, here I entered: e:
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    D:\Norms\Norms Tools>e:

    E:\>
    Last edited by Norm; 07-01-2012 at 08:12 PM.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    tarun mudgal is offline Member
    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0

    Default Re: How to run the java code (javac problem)

    Quote Originally Posted by Norm View Post
    Sorry, the cd doesn't work for directories. Just enter the drive letter:
    For example:
    The same thing happens as I said above (a file with the same name as the source file but with "class" extension is formed at the directory of the source file).
    please help

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: How to run the java code (javac problem)

    The same thing happens
    It shouldn't be the same thing if you enter a different command.

    a file with the same name as the source file but with "class" extension is formed at the directory of the source file
    That is the normal results for when you compile a program.

    please help
    Can you explain what the problem is now?
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    tarun mudgal is offline Member
    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0

    Default Re: How to run the java code (javac problem)

    Quote Originally Posted by Norm View Post
    That is the normal results for when you compile a program.
    It seemed normal to me too but the output(that it should have printed "hello world" string) is not observed anywhere.

    Here is the command I used...
    Microsoft Windows [Version 6.2.8250]
    (c) 2012 Microsoft Corporation. All rights reserved.

    C:\Users\Sachin>E:

    E:\>javac createfirstprogram.java

    E:\>
    Please tell what wrong I'm doing.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: How to run the java code (javac problem)

    There are two steps you must do:
    One is compile the .java file into a .class file using the javac command.
    The other step is to execute the .class file by using the java command:
    java createfirstprogram
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    tarun mudgal is offline Member
    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0

    Default Re: How to run the java code (javac problem)

    Quote Originally Posted by Norm View Post
    There are two steps you must do:
    One is compile the .java file into a .class file using the javac command.
    The other step is to execute the .class file by using the java command:
    java createfirstprogram
    Resolved!
    thanks a lot sir.

  15. #15
    tarun mudgal is offline Member
    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0

    Default Re: How to run the java code (javac problem)

    One more thing... Are there any compilers (GUI) available for java. Moreover do netbeans also work the same way as this javac works? (I've heard about netbeans but haven't tried yet)
    thanks

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: How to run the java code (javac problem)

    There could be other compiilers for java. I don't know of them, I use javac.
    Netbeans is an IDE.
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    tarun mudgal is offline Member
    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0

    Default Re: How to run the java code (javac problem)

    Quote Originally Posted by Norm View Post
    There could be other compiilers for java. I don't know of them, I use javac.
    Netbeans is an IDE.
    Could you please tell the difference between the two (compiler and IDE)?
    thanks

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: How to run the java code (javac problem)

    Do a google on IDE.
    A compiler only compiles.
    If you don't understand my response, don't ignore it, ask a question.

  19. #19
    jitu.ideas2it is offline Member
    Join Date
    Apr 2012
    Posts
    7
    Rep Power
    0

    Default Re: How to run the java code (javac problem)


  20. #20
    b4viral is offline Member
    Join Date
    Jul 2012
    Posts
    17
    Rep Power
    0

    Default Re: How to run the java code (javac problem)

    Quote Originally Posted by tarun mudgal View Post
    Could you please tell the difference between the two (compiler and IDE)?
    thanks
    for IDE..

    When developing software, programmers tend to rely on integrated development environments (IDEs). An IDE provides important time-saving functionality, such as syntax checking, code assist and re-factoring. With syntax checking, the IDE will alert you if you have typed a command incorrectly. The term code assist refers to the ability of the IDE to suggest completions to a piece of code that you are working on. For example, if a locally scoped variable is named maximumLikelihoodEstimator and you wish to use this variable in an expression that you are typing, then you can invoke the code assist function to obtain a list of identifiers to choose from. As you type in characters, the list is narrowed to match only those identifiers that match with the characters you have so far entered. Re-factoring functionality allows you to change the name of an identifier in one part of the code, and have the IDE change the name as it occurs throughout the entire code base. These and other time saving functions make IDEs highly useful tools for developers.


    for more as the moderator suggested GOOGLE

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 7
    Last Post: 08-29-2011, 07:35 PM
  2. Replies: 0
    Last Post: 02-21-2011, 12:50 PM
  3. Replies: 1
    Last Post: 11-03-2010, 09:49 AM
  4. error while compile code using javac
    By suri in forum New To Java
    Replies: 3
    Last Post: 01-20-2010, 10:10 AM
  5. source code of 'javac'?
    By Pooja Deshpande in forum Advanced Java
    Replies: 2
    Last Post: 06-04-2008, 12:24 PM

Tags for this Thread

Posting Permissions

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