• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic