tags:

views:

151

answers:

5

whenever they say run a .class file in JVM. do they mean with the command "java" in the terminal.

or can you click on it to open it?

+5  A: 

Yes, if you have the JRE installed, java should be the JVM.

mdm
+1  A: 
  1. yes, you use the java command to launch an instance of the JVM or java virtual machine.

  2. depending on your operating system you could hook something up to double click a class file, what is your os?

pstanton
Mac os x. but if the .class is not a Swing application. It just use system.out.println. How will it be displayed when i double click the .class file then?
weng
i'm not great with mac os, but it should be possible to launch a terminal window.
pstanton
+3  A: 

A java file is compile into a class file, which is a bunch of java bytecode. The JVM is the thing that can execute java bytecode.

java is a command line tool that is part of a java runtime environment (JRE) that knows how to start a java virtual machine, load and execute your class file.

Dave Paroulek
+2  A: 

The Java JVM can be packaged in different ways and started with various executables.

The standard way that most developers start the JVM is indeed with the java.exe. However, this is a command line program, so you need to provide it with extra detail: the name of the class that contains main, and often the classpath which is used to find the classes to load.

In most operating systems, clicking the Java icon wouldn't do anything since it will merely run the executable without any parameters, and the executable will just exit without running anything. If you want to double-click in Windows, create a shortcut and add the relevant command line parameters to the command after the java.exe part.

Uri
he's on a mac..
pstanton
A: 

As mentioned in other posts the java command, or executable can be used to create a running JVM. But there are other ways you find a JVM, which are usually finding java for you via your JAVA_HOME such as running tomcat (a web server for java, sometimes called a "container"), Java WebStart which synchs a java distro to your local system and launches it in a JVM and Java Applets (old school attempt at to broaden the use of java on the web where Java is being run directly within the browser). Essentially they all create a JVM via calling java.exe or one of its siblings in the JRE (eg. javaw.exe).

harschware