Question:
Java .class file help please?
Diana
2010-01-26 07:21:54 UTC
I am working on a project for my college which asks me to create 2 files a .java file and a .class file. now the java file I can view with notepad but the .class file is viewed with internet explorer which is when i click on it it asks me to download the file and it wont work. how do I open the .class file I need to run it for errors before submitting the exam.

can you please? thanks a lot
Four answers:
fruitrounds
2010-01-26 07:48:31 UTC
This is how you run a .class file through Command Prompt.



Start > Control Panel > System > Advanced tab > Environment Variables > Click Path under 'System Variables' > Add the location of your Java bin directory to the beginning and end it with a semi-colon. > Click OK 3 times and close the Control Panel



My Java bin directory is at 'C:\Program Files\Java\jdk1.6.0_11\bin'



Open up Command Prompt and change the location of where it is looking to the location of the .java file.



This website has a bit of info on the 'cd' command to help you change the location

http://dosprompt.info/



If you want, you can compile a .java file through command prompt by typing 'javac .java'

Then to run the file, type 'java '



This might be a bit confusing, but I hope this helps.
R.F.
2010-01-26 07:36:48 UTC
A .class file is the compiled file of the source code .java file.

You can read a .java file because it's plain text, but a .class file is machine code so you can't read it. You can only run a .class file.



If you were able to compile the .java file into a .class file successfully then there are no syntax or compile errors.

To check for runtime or logic errors, you need actually run the program.



If the java program is an applet, you need to either use a java browser or create an HTML page that loads the applet .class file onto the web page and then load the web page on a web browser to run the applet.

Open up a Java Console to see if it gives any errors.



If the java program is an application, then go to a terminal or command prompt and type to run:



java NameOfClassFile



Any errors will be displayed on the terminal screen.
Mary
2016-05-26 17:13:27 UTC
Get NetBeans / java jdk bundle download. That will connect all the dots required to make the code text files into java class files.
Chris C
2010-01-26 07:55:37 UTC
You have to have the JRE installed and active on Internet Explorer in order to run the Java class. The ".class" file is a byte-code file, as opposed to a source file (.java), or an executable file (.exe, .com, .cmd, .bat).



Likewise, you can run a java class on the command line by opening a command windows (Start -> Run -> "cmd.exe"), and typing in "javac MyFile.class".


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...