This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes java- can i somehow run previously compiled java bytecode from a new Java program 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 » Beginning Java
Bookmark "java- can i somehow run previously compiled java bytecode from a new Java program" Watch "java- can i somehow run previously compiled java bytecode from a new Java program" New topic
Author

java- can i somehow run previously compiled java bytecode from a new Java program

Arvind Chari
Greenhorn

Joined: Jul 26, 2011
Posts: 8
Hello all,

Is it possible to first compile a set of Java source code files into Byte code, and later run that bytecode-- not directly, but by adding commands to another java program-- such that this new java program (in its various classes/functions) runs the previously compiled java bytecode?

If this is possible, then what is/are the required command(s) to do this?

Thanks,
Arvind.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Yes. Create a class Foo in your current directory, compile it and remove the .java file. Then try this sort of thing:-You do that sort of thing all the time when you use an external .jar; it has .class files in and often no .java files.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

That is how most applications are packaged and deployed at the customer's end(i.e. jar files and packaged classes). Rarely would one deliver java sources. What do you think happens when you write the simplest of Java statements? For example:



Obviously, you will never find the actual Integer source file anywhere in your system. That is exactly how this language is meant to be used. Write and compile once, run anywhere and everywhere.


~ Mansukh
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7552
    
  18

Arvind Chari wrote:Is it possible to first compile a set of Java source code files into Byte code, and later run that bytecode-- not directly, but by adding commands to another java program-- such that this new java program (in its various classes/functions) runs the previously compiled java bytecode?

The basic answer - as has already been given - is: Yes.

However, I suspect that your question may not be as simple as it sounds.

Why don't you tell us what you want to do, rather than how you want to do it?

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Mansukhdeep Thind wrote: . . . Obviously, you will never find the actual Integer source file anywhere in your system. . . .
He might not, but I shall. Inside your Java installation folder you will find a file called src.zip. Unzip that, loook inside the java folder, then inside the lang folder and voilà!
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

He might not, but I shall.
Lolz... Hahaha!! When I said "you", I meant Arvind. Who can stop you maestro Ritchie? And if you unzip it, you will corrupt the installation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java- can i somehow run previously compiled java bytecode from a new Java program
 
Similar Threads
i have a question
waht role of JIT in JVM
java platform independent?
what is the difeerence between jdk and jre?
compilation vs interpretation?