wood burning stoves 2.0*
The moose likes Java in General and the fly likes How IDE compiles a java file ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How IDE compiles a java file ?" Watch "How IDE compiles a java file ?" New topic
Author

How IDE compiles a java file ?

naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

I wonder how an IDE like Eclipse compile and run a .java file ?

they (IDE) know about jdk installed in system.
they create a source file(.java) and save it on system.

How they compile .java into .class file ??
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Some IDEs may come with their own compiler. Otherwise, when you install or configure the IDE, you point it to your JDK installation, and it invokes javac from there just like you would on the command line.
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

my point is that even after knowing the location of jdk installed directory , i cannot compile a file without using command line .I have to open command line and then invoke javac from there .

how can i do it without invoking command line , of course ,apart form using an IDE?



As i pass "javac Myclass.java" to command line .It seems unlikely that an IDE will open command line and then compile a file from there. ?


So how IDE do it ??.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

It's certainly possible that the IDE is invoking javac via Runtime or ProcessBuilder. That would actually be my first guess.. On the other hand, I think for the last few versions, the JDK has included compiler classes, so maybe it's using those.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

naveen yadav wrote:my point is that even after knowing the location of jdk installed directory , i cannot compile a file without using command line .I have to open command line and then invoke javac from there .

Yes, that's how it normally works when you compile a Java source file manually.

naveen yadav wrote:how can i do it without invoking command line , of course ,apart form using an IDE?

The Java compiler included in the JDK does not have a GUI. The only way to use it directly is from a command line prompt.

naveen yadav wrote:As i pass "javac Myclass.java" to command line .It seems unlikely that an IDE will open command line and then compile a file from there. ?

Eclipse has its own built-in Java compiler. It does not use the Java compiler in the JDK at all. Other IDEs call the Java compiler from the JDK and show its output in a custom console view. Just because you normally use a command prompt window to run the Java compiler, that doesn't mean that it is always necessary to have a command prompt window to run javac.exe. IDEs can just run javac.exe in the background and get the output from the compiler without you seeing any command prompt window.

Also, the Java compiler has an API so that it can be called from a Java program via the API. This API is in the package javax.tools.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

Thanks Jesper de Jong.




Regards
naveen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How IDE compiles a java file ?
 
Similar Threads
Give commands of command line from gui
using eclipse for java
migrate codes generated in windows IDE to unix environment
Class Path
JDOM