Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Arvind Chari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48642
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Winston Gutkowski
Bartender
Pie
Posts: 10226
58
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Posts: 48642
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic