Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

programmatic invocation of Javac

Thread view: 
Roedy Green - 17 Feb 2006 11:43 GMT
I have heard in JDK 1.6 wil be a new way to invoke the Javac compiler
as a class and feed it source directly as strings.   I could not find
any reference to this. Anyone got an URL or the keywords to find it?
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Timo Stamm - 17 Feb 2006 13:16 GMT
Roedy Green schrieb:
> I have heard in JDK 1.6 wil be a new way to invoke the Javac compiler
> as a class and feed it source directly as strings.   I could not find
> any reference to this. Anyone got an URL or the keywords to find it?

http://java.sun.com/javase/6/docs/api/javax/tools/JavaCompilerTool.html

Timo
Heiner Kücker - 18 Feb 2006 01:04 GMT
> Roedy Green schrieb:
>> I have heard in JDK 1.6 wil be a new way to invoke the Javac compiler
>> as a class and feed it source directly as strings.   I could not find
>> any reference to this. Anyone got an URL or the keywords to find it?
>
> http://java.sun.com/javase/6/docs/api/javax/tools/JavaCompilerTool.html

I miss a file system independent way to compile random created strings.

The created string have to be package independent or have to use an
temporarly
or for this compilation way reserved package.

Furthermore is neccessary to load the compiled class instantly.

It's self-evident to unload or rather to reload the compiled class
if a newer version exist.

Diese Grammatik wurde Ihnen praesentiert von
"Doener mit alles, 1,99 Euro auf der Altendorfer Strasse in Essen".

Signature

Heiner Kücker
www.heinerkuecker.de
www.control-and-command.de

Roedy Green - 18 Feb 2006 19:45 GMT
On Sat, 18 Feb 2006 02:04:25 +0100, "Heiner Kücker"
<mail@heinerkuecker.de> wrote, quoted or indirectly quoted someone who
said :

>I miss a file system independent way to compile random created strings.
that is not hard. Ensuring with 100% surely they are unique is harder.

See http://mindprod.com/jgloss/pseudorandom.html#STRINGS

Quoting from it:

Sometimes you want a random String to use as an
almost unique identifier. You could use code like this:


// generating random hex String up to 16 characters long

private static Random wheel = new Random(); // seed with time of day

// ...

/* To get numeric strings with  digits 0-9 try this: */
String almostUniqueAndRandom = Long.toString( wheel.nextLong() &
Long.MAX_VALUE );

/* generate random hex Strings of form
* "0" .. "7fffffffffffffff", a maximum 16 characters long.
* representing 0..Long.MAX_VALUE
* Note there is no such method as Random.nextLong( long ),
* so you have to trim the result to 0..Long.MAX_VALUE yourself.
* To get strings with letters a-f and digits 0-9 try this: */
*/
String almostUniqueAndRandom = Long.toHexString( wheel.nextLong() &
Long.MAX_VALUE );

/* To get strings with letters a-z and digits 0-9 try this: */
String almostUniqueAndRandom = Long.toString( wheel.nextLong() &
Long.MAX_VALUE , 36 );

But what about collisions? How likely are you to  run into problems
with uniqueness? In most cases it is highly unlikely you will  get
duplicates even though Sun's generator generates many more collisions
than a  theoretically perfect true random number generator. Internally
Sun's nextLong  uses only a 32-bit generator and it does not cycle
through all possible 32-bit  patterns. I have written code to compute
the theoretical possibility of a  collision with a perfect true number
generator, and a simulator that exercises Sun's generator and tracks
how well it performs.

 
The code is posted at
http://mindprod.com/jgloss/pseudorandom.html#STRINGS
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 18 Feb 2006 20:19 GMT
>http://java.sun.com/javase/6/docs/api/javax/tools/JavaCompilerTool.html

That Javadoc is so frustrating. The classes don't have public
constructors, AND Sun keeps  it "secret" where they have hidden static
factories.

I would like it if Javadoc did something to strongly encourage the
documenting of factory methods in the place where the constructor
would usually go.

on the class without a constructor you could say

@factory com.mindprod.example.Builder.create( long );

you could have multiple @factory entries.

You could also use the term @factory on a method by itself, declaring
it is a factory for its return type. That would generate Javadoc
notion both on the method that implement the factory and the Classes
it produces.

Details to be worked out so that it does not generate entries on
classes it could never actually generate even if it generates their
interfaces.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas Hawtin - 19 Feb 2006 08:24 GMT
>> http://java.sun.com/javase/6/docs/api/javax/tools/JavaCompilerTool.html
>
> That Javadoc is so frustrating. The classes don't have public
> constructors, AND Sun keeps  it "secret" where they have hidden static
> factories.

Fortunately the JavaDocs were created with -use.

http://download.java.net/jdk6/docs/api/javax/tools/class-use/JavaCompilerTool.html
http://download.java.net/jdk6/docs/api/javax/tools/class-use/Tool.html

A few years ago I started a job by documenting the public API of the
company product. Unfortunately it used Collection for returning
collections. That meant I had to supplement the JavaDocs with
additional, untidy use information. The API was changed before release
to use arrays. With generics that would have been unnecessary.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Roedy Green - 19 Feb 2006 11:14 GMT
On Sun, 19 Feb 2006 08:42:49 +0000, Thomas Hawtin
<usenet@tackline.plus.com> wrote, quoted or indirectly quoted someone
who said :

>Fortunately the JavaDocs were created with -use.
>
>http://download.java.net/jdk6/docs/api/javax/tools/class-use/JavaCompilerTool.html
>http://download.java.net/jdk6/docs/api/javax/tools/class-use/Tool.html

This is so nuts. How long has it been there. I have been wanting this
since day 1 and never realised it was right under my nose.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas Weidenfeller - 20 Feb 2006 08:45 GMT
>> http://download.java.net/jdk6/docs/api/javax/tools/class-use/JavaCompilerTool.html
>> http://download.java.net/jdk6/docs/api/javax/tools/class-use/Tool.html
>
> This is so nuts. How long has it been there. I have been wanting this
> since day 1 and never realised it was right under my nose.

The "Use" links are there since at least J2SE 1.3. They have been
mentioned here a few times.

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

James McGill - 17 Feb 2006 20:51 GMT
> I have heard in JDK 1.6 wil be a new way to invoke the Javac compiler
> as a class and feed it source directly as strings.   I could not find
> any reference to this. Anyone got an URL or the keywords to find it?

Concrete example:

http://www.javalobby.org/java/forums/m91985882.html

Is it actually implemented, or merely proposed in Mustang?
jamesahart79@gmail.com - 17 Feb 2006 21:39 GMT
I'm curious.  The only comment at JavaLobby was to ask what people
would use this API for.  While I'm not as skeptical as the commenter, I
would like to ask people in this forum what practical tasks this tool
would be good for.  More concretely, what have you done that would have
benefitted from having this?
James McGill - 17 Feb 2006 23:31 GMT
> More concretely, what have you done that would have
> benefitted from having this?

Weblogic ejbc, every JSP compiler that I know about, and Hibernate, all
do dynamic generation of java code.  

It might be useful as a more straightforward approach to problems that
are in the space where BCEL lives.  Also, it occurs to me that such a
feature might be interesting to developers of IDE's, preprocessors, or
compilers.  

The JSR gives some rationale for the API, and it does make some sense.
There's a push to abstract the compiler away from specific dependencies,
particularly, the ones that require javac to be a platform-specific
process, and that require the input to javac to be "files" on a "file
system", idioms that aren't universal.  

James
Roedy Green - 18 Feb 2006 20:36 GMT
>I'm curious.  The only comment at JavaLobby was to ask what people
>would use this API for.  While I'm not as skeptical as the commenter, I
>would like to ask people in this forum what practical tasks this tool
>would be good for.  More concretely, what have you done that would have
>benefitted from having this?

see http://mindprod.com/jgloss/javacompilertool.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.