• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

.class won't open, what do I need to download?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically I made a very simple program just to print out Hello world! I ran the Hello.java and I got the Hello.class file, when I now try to run this again from the command prompt and expect it to output "hello world!" it just pops up saying:

Windows cannot open this file
- select a file to open with
- find a program online

what can I do in order to run and execute this program?

Thanks - Kieran.

 
Marshal
Posts: 79969
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
What instruction are you using at the command line? You are supposed to write

java Hello

…or whatever your class is called.
We have a useful FAQ, which will probably answer all your questions about it.
 
Sheriff
Posts: 28328
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kieran, welcome to the Ranch!

The short answer is, you don't do that. But the much longer (and more useful) answer is one of the pages right here: How to create your first Java program. Check it out, work your way through it, and ask any follow-up questions here.
 
kieran white
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks:)

I did Hello.java and the first time it made the Hello.class and when I do it again it just pops up asking you what program to run it with
 
kieran white
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
None of the links work:(
 
Paul Clapham
Sheriff
Posts: 28328
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In what way do they not work?
 
Campbell Ritchie
Marshal
Posts: 79969
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul C and I both posted the same link, and it worked when I tried it a minute ago.
If you have a .class file, you must have installed Java™ correctly. What you are supposed to do is navigate to your directory where you saved your Java™ work. I recommend you create a folder as shown here. You only need the mkdir instruction once. You can give it any name you wish. You give these instructions in this order:-

mkdir java
cd java
javac Hello.java
java Hello

Obviously if you are already in the correct folder, you only need the two lines starting “javac”. If you have a .class file, you must have got the javac instruction to work already. It does no harm to run javac twice, however.
 
kieran white
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the page just didn't open correctly on my phone.

I'm following the instructions and now when I type Javac it says it's not recognized as a internal or external command, the only way to prevent this is by putting C:\Java\jdk1.7.0_40\bin\javac rather then C:\Java\jdk1.7.0_40
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kieran white wrote:the page just didn't open correctly on my phone.


Then open the page on a computer, that makes it a lot easier to read than on a small phone screen.

kieran white wrote:I'm following the instructions and now when I type Javac it says it's not recognized as a internal or external command, the only way to prevent this is by putting C:\Java\jdk1.7.0_40\bin\javac rather then C:\Java\jdk1.7.0_40


To get rid of this problem, set the PATH variable as described in the JDK installation instructions.
 
kieran white
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have done that so my PATH variable reads C:\WINDOWS\system32;C:\WINDOWS;C:\Java\bin (C:\java\bin is the location when everything is)
however now when I type in Javac it says:
Error: Could not find or load main class com.sun.tools.javac.Main


When I actually get past this bit where do I save my programs, in a completely different file or the same one?
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kieran white wrote:however now when I type in Javac it says:
Error: Could not find or load main class com.sun.tools.javac.Main


That's a strange error, and indicates that something is wrong with your JDK installation. Did you accidentally remove some jar file from the JDK?
 
kieran white
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think so I followed the steps and it's not working
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please double check if you have tools.jar under your JDK (not JRE) installation directory and copy paste the path to tools.jar here
On my system its located at JDK_HOME/lib
 
kieran white
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:Please double check if you have tools.jar under your JDK (not JRE) installation directory and copy paste the path to tools.jar here
On my system its located at JDK_HOME/lib



I can't find JDK in the file Java, I have bin, db, include, jre, lib and some copyright and read me things
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try uninstalling the JDK and installing it again. It looks like something is wrong with your JDK installation.
 
kieran white
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unistalled it and re installed still the same though
Is there anything else which can fix it?:/
 
Campbell Ritchie
Marshal
Posts: 79969
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did you install it?
What happens when you give the following four instructions at a command line:-

echo %PATH%
echo %CLASSPATH%
java -version
javac -version

?
 
kieran white
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Where did you install it?
What happens when you give the following four instructions at a command line:-

echo %PATH%
echo %CLASSPATH%
java -version
javac -version

?



C:\Users\Kieran>echo %path%
C:\WINDOWS\system32;C:\WINDOWS;C:\Java\bin

C:\Users\Kieran>echo %classpath%
%classpath%

C:\Users\Kieran>java -version
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) Client VM (build 24.0-b56, mixed mode, sharing)

C:\Users\Kieran>javac -version
Error: Could not find or load main class com.sun.tools.javac.Main
 
Campbell Ritchie
Marshal
Posts: 79969
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only one which looks wrong is the last. Have you tried uninstalling and reinstalling Java?
 
Campbell Ritchie
Marshal
Posts: 79969
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
…with a new download?
 
kieran white
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll try again
 
kieran white
Greenhorn
Posts: 11
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
been playing around with it and I finally think it works thanks a lot guys
 
Campbell Ritchie
Marshal
Posts: 79969
396
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic