7

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?

ajsie
  • 77,632
  • 106
  • 276
  • 381
  • I am seriously wondering why this question has been downvoted?? I even think it should be upvoted because I don't think it is a bad question. – Alfred Jan 11 '10 at 21:01
  • my questions tend to be down-voted, i ask too much=) – ajsie Jan 11 '10 at 21:14
  • 1
    @noname: I Would guess it's the username rather than the question. – Uri Jan 12 '10 at 23:39

6 Answers6

5

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

mdm
  • 12,480
  • 5
  • 34
  • 53
4

A java file is compiled 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.

Upgradingdave
  • 12,916
  • 10
  • 62
  • 72
2

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
  • 88,451
  • 51
  • 221
  • 321
1
  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
  • 35,033
  • 24
  • 126
  • 168
  • 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? – ajsie Jan 11 '10 at 20:58
  • i'm not great with mac os, but it should be possible to launch a terminal window. – pstanton Jan 11 '10 at 20:59
0

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).

Community
  • 1
  • 1
harschware
  • 13,006
  • 17
  • 55
  • 87
0

a .CLASS file is Java bytecode. It is not strictly meant to be Java (some other languages have the same bytecode structure). JVM may refer to the command java or javaw. The only diffrence is that java is meant to run console applets while javaw is for window interfaces. For example, Minecraft (a major Java app) contains a standalone launcher (a native Windows application). It uses javaw because it has it's own special window container, etc.

adrian
  • 1,439
  • 1
  • 15
  • 23