Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

javac and compiled class file

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Where would the compiled class file be usually geenrated?

As per K & B,

By default, the compiler puts a .class file in the same directory as the .java source file.



Consider the below case:



And in this case, if I compile from MyProject directory where would the class be generated?

myProject> javac source/MyClass.java

Larsen.
 
Author
Posts: 116
11
Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you compile from the myProjects directory and you want the class file to be compiled into the sources directory use should use the following command:

javac source/MyClass.java

However if you want the code to be compiled into a specific directory (for example the classes directory) you must specify it with the -d option tag like so:

javac -d classes source/MyClass.java

As you can see the K&B book is correct:

By default, the compiler puts a .class file in the same directory as the .java source file.

 
Larsen Raja
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shouldn't javac source/MyClass.java be creating class file in myProjects directory?
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Larsen Raja wrote:Shouldn't javac source/MyClass.java be creating class file in myProjects directory?


By default, the compiler puts a .class file in the same directory as the .java source file.

 
Larsen Raja
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I conclude that always class files will be created in the source folder of .java file when compiled without -d option and from any directory?
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javac - The Java Compiler says -

Unless you specify the -d option, the compiler places each class file in the same directory as the corresponding source file.



Regards,
Dan
 
Larsen Raja
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
 
I think she's lovely. It's this tiny ad that called her crazy:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic