Find the answer to your Linux question:
Results 1 to 7 of 7
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2006
    Location
    Viet Nam
    Posts
    6

    Arrow How to run file .class by gcj?


    I use gcj to complie file hello.java . But i can't run it.
    How to run file hello.class by gcj??

  2. #2
    Linux Newbie DeoXMAN's Avatar
    Join Date
    Jul 2005
    Location
    Azerbaijan, Germany
    Posts
    154
    java hello.class
    doesn't work?
    Karabakh - I will be back

  3. #3
    Just Joined!
    Join Date
    Oct 2006
    Location
    Viet Nam
    Posts
    6

    Arrow

    So how can i run file java programs? Can you give me some ways? Thanks so much!

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Quote Originally Posted by little_fire
    So how can i run file java programs? Can you give me some ways? Thanks so much!
    Read DeoXMAN's answer to your post. The command is java yourClassFile.class, obviously replacing "yourClassFile" with the name of your actual Class.
    Registered Linux user #270181

  6. #5
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Location
    Wisconsin
    Posts
    942
    java hello.class won't work, because the JVM will then try to load a class called class in package (and therefore subdirectory) hello. The correct usage is java hello.

    Also, I thought gcj was a Java to native compiler?
    Flies of a particular kind, i.e. time-flies, are fond of an arrow.

    Registered Linux User #408794

  7. #6
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Quote Originally Posted by Javasnob
    java hello.class won't work, because the JVM will then try to load a class called class in package (and therefore subdirectory) hello. The correct usage is java hello.
    You're correct. I haven't launched a java app from the command line in a while.

    Also, I thought gcj was a Java to native compiler?
    No. It's the GNU version of Sun's javac, which really doesn't *compile*, so much as translates the sourcecode into Java bytecode, which can then be interpreted by the JVM.
    Registered Linux user #270181

  8. #7
    Linux Engineer Zelmo's Avatar
    Join Date
    Jan 2006
    Location
    Riverton, UT, USA
    Posts
    1,001
    -->
    My reading of Debian's package description for gcj is that it can create either bytecode or machine code. It does bytecode by default, so assuming that's how the OP used it, then java hello should run it.

    Of course, this is all very contingent on the content of the source code, and exactly how it was compiled.
    Stand up and be counted as a Linux user!

Posting Permissions

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