Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Help understanding three things JVM , .java, .class?

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Help understanding three things JVM , .java, .class?

    I know their exist machine, assembler, higher language "code". My question is understanding what is happening when i'm compiling a .java file and how is it different using an IDE vs. using a text editor in terminal and running javac in the command line.

    QUESTIONS:

    1.)
    What is JVM? Is this some add on or utility you get off homebrew that runs when your in terminal? What directory can I look in to see if I have JVM which I know I already do but would like to see for myself.

    2.)
    From what I understand when I write my program in my '.java file' I have to compile it. I thought when I was compiling all I was doing was checking for mistakes in my code. Now from what I've read in my text book I'm actually creating a java bytecode executable file which is a '.class file'? I have no idea what this means.

    3.)
    In my program ".java file" I defined a class and then a main. For example below I defined a class 'Welcome' and a main. Therefore, my main question is why am I creating another 'class' using the command 'javac ProgramName'. Am I confusing a 'class' with a '.class file'?

    import javax.swing.JOPtionPane;
    public class Welcome{
    public static void main(String [] args){
    JOPtionPane.showMessageDialog(null, "Welcome");
    }
    }

    4.)
    Furthermore, I know in Xcode and Netbeans when I finish writing a program and compile it, the program runs great "if no errors are found". I've opened up terminal and navigated to the program file and see that in this file contains a 'build' directory and a 'src' directory. The 'build' directory contains a '.class' and the 'src' directory contains the '.java'. What is happening when I compile a program in an IDE like Netbeans or Xcode and how is it similar to what is happening in terminal when i have to enter the javac command.

    FYI when I'm compiling a program in terminal I am using TextMate to write a .java program. Then I have to compile it in terminal using javac to get a .class and then to run I type the command java followed by the name of program.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help understanding three things JVM , .java, .class?

    1)
    A: Java Virtual Machine - A program that runs Java programs - A search engine will provide more details
    B: The JVM has nothing to do with the terminal. Think of it as a translator between the operating system on the machine in question and the Java program the user wishes to execute
    C: Where ever Java is installed. Depends on too many things to say exactly, and basically could have been installed just about anywhere. Consult the respective OS for the default location
    - To A and B, spend some time with your favorite search engine for details and try to ask more specific questions if you have any, a forum isn't the place for such a lengthy explanation

    2)
    Yes, compiling a .java file produces a .class file. The .class file is what the JVM understands, where the .java file is what people generally work with

    3)
    Yes you are confusing the two. What you end up with is your "class" in a file with the special extension "class".

    4)
    Too many options to list all details. Each "compiler" may do things a bit differently, but the end result is what is important, the .class files
    IDE's can provide colored text, highlighting, folding, spell checking, code completion... too many options to list... Again, it all boils down to the .class files in the end.

  3. The Following User Says Thank You to jps For This Useful Post:

    syregnar86 (August 3rd, 2013)

Similar Threads

  1. Need help understanding Java
    By Jafke104 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 30th, 2013, 10:52 PM
  2. Not understanding this java output...
    By kowaii in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 28th, 2013, 05:33 PM
  3. Greetings! Java - err JVM language!
    By concerto49 in forum Member Introductions
    Replies: 4
    Last Post: November 20th, 2012, 12:42 PM
  4. could not open `C:\Program Files\Java\jre6\lib\amd64\jvm.cfg
    By miaaa00 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 29th, 2011, 12:45 AM
  5. Java is resetting my variables to zero, and other mysterious things
    By schcrosby in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 12th, 2010, 09:50 PM

Tags for this Thread