Results 1 to 9 of 9
- 02-22-2010, 01:57 AM #1
Why do you only compile the Test file?
Yes, I'm a newbie. But all texts seem to assume everyone understands only to compile and run the "Test.java" file and not to compile or run the other non-test files.
Sure, you only run the Test file because that's the main one... but I was under the impression that when you use the javac command, the compiler turns the java code into machine code.
Then... how can the machine use and read the other files if those were not compiled, a.k.a. javac-ed, a.k.a. not turned into machine code?
This has been bothering me for a while.
thanks!
- 02-22-2010, 04:30 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Each file understand by the PC in binaries, any other text cannot understand. Actually those binaries are also not directly understandable to the system, those 1s and 0s are convert into voltages on gates and work (send signals) accordingly.
Each application have there own conversion techniques, javac compilation do that in java and so on.
- 02-22-2010, 04:30 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Each file understand by the PC in binaries, any other text cannot understand. Actually those binaries are also not directly understandable to the system, those 1s and 0s are convert into voltages on gates and work (send signals) accordingly.
Each application have there own conversion techniques, javac compilation do that in java and so on.
- 02-22-2010, 06:15 AM #4
And so "javac" turns a .java file into something a machine can deal with.
But why can we "javac" just the nameTest.java file? The nameTest.java file accesses other .java files that we write, like name.java.
Why can the computer deal with both files we wrote, when we only compiled the nameTest.java one and did not compile the other files? Does it automatically compile every file with the java extension that is referenced in the test.java file? Is that why?Last edited by Java Riser; 02-22-2010 at 06:18 AM.
- 02-22-2010, 12:43 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,468
- Rep Power
- 16
javac turns a java file into byte-code, which is understandable by a JVM. The JVM turns that byte code into instructions the underlying machine can understand. This is why a Java program written and compiled on a Windows PC should still work on a Linux PC or a Mac, for example.
- 02-22-2010, 01:32 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
That's exactly what the Java compiler does; if a source file A.java depends on a file B.java the compiler notices the dependency; if it can find a file B.class that is newer than the source file B.java it doesn't compile B.java. Otherwise (the source is newer than the compiled form) it recompiles B.java again.
This all can only happen if javac can find the .class files and/or the .java source files. There are special flags that instruct the compiler where to find the .class files (the classpath (or cp) flag) and where to find the .java source files (the sourcepath flag).
Because of this behaviour javac isn't very suitable for the 'make' tool because sometimes it does more than it has been told to do and 'make' produces funny output that can be hard to understand ('ant' does a much better job).
kind regards,
Jos
- 02-23-2010, 01:57 AM #7
Thanks, that mystery is history!
- 02-23-2010, 02:17 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 02-23-2010, 02:20 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
can someone help me compile and build a jar file
By peahead in forum New To JavaReplies: 2Last Post: 02-06-2010, 04:05 PM -
JUnit Test??? What is it all about????? Please help!!
By nikosa in forum New To JavaReplies: 1Last Post: 08-03-2009, 05:31 PM -
Junit test
By alice in forum New To JavaReplies: 1Last Post: 06-14-2008, 01:24 AM -
Test Advisory Panel-Telecommute- Test your Java skills + share insights on Java tests
By michelle in forum Jobs OfferedReplies: 0Last Post: 04-05-2008, 12:38 AM -
Help with Java Compile File
By baltimore in forum New To JavaReplies: 1Last Post: 08-06-2007, 07:48 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks