472,358 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

Self Modifying Code

How do you write self modifying code in Java?

Japcuh
(Just Another Perl C Unix Hacker)
http://www.catb.org/~esr/faq/hacker-howto.htm#what_is
..0.
...0
000
Jul 17 '05 #1
16 7910
Japcuh wrote:
How do you write self modifying code in Java?


What do you mean by "modify?" A Java program can
extend itself by loading new classes on the fly, if
that suits your needs.

--
Er*********@sun.com

Jul 17 '05 #2
On 2 Jul 2004 12:31:17 -0700, ja****@gmail.com (Japcuh) wrote or
quoted :
How do you write self modifying code in Java?


You can't modify a class once it has been loaded, but you can create a
similar class and load that.

You can do it by generating Java source and compiling that on the fly
to byte codes, or by generating JVM byte codes directly.

See http://mindprod.com/jgloss/eval.html
http://mindprod.com/jgloss/jasm.html
http://mindprod.com/jgloss/javacexe.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Jul 17 '05 #3
ja****@gmail.com (Japcuh) wrote in news:3a8cbb2e.0407021131.55805361
@posting.google.com:
How do you write self modifying code in Java?


You may want to check out the Java code generation library cglib:
http://cglib.sourceforge.net/

Best Regards
Kristian Larsen
Jul 17 '05 #4
kjc
No, but this could be done in Smalltalk blind folded.

Japcuh wrote:
How do you write self modifying code in Java?

Japcuh
(Just Another Perl C Unix Hacker)
http://www.catb.org/~esr/faq/hacker-howto.htm#what_is
.0.
..0
000


Jul 17 '05 #5
On Sat, 03 Jul 2004 15:49:21 GMT, kjc <ks*****@elp.rr.com> wrote or
quoted :
No, but this could be done in Smalltalk blind folded.

Japcuh wrote:
How do you write self modifying code in Java?


Is it a problem that you sometimes do it accidentally?

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Jul 17 '05 #6
> ja****@gmail.com (Japcuh) wrote in news:3a8cbb2e.0407021131.55805361
@posting.google.com:
How do you write self modifying code in Java?


http://java.sun.com/developer/techni...leases/j2se15/

The metadata bit of this seems to suggest that in future releases of
java, you'll be able to generate actual source code on the fly.
Jul 17 '05 #7
Thanks for all the help.

Japcuh
(Just Another Perl C Unix Hacker)
http://www.catb.org/~esr/faq/hacker-howto.htm#what_is
..0.
...0
000
Jul 17 '05 #8
an************@gmail.com (Andrew Chambers) wrote in message news:<f3************************@posting.google.co m>...
ja****@gmail.com (Japcuh) wrote in news:3a8cbb2e.0407021131.55805361
@posting.google.com:
How do you write self modifying code in Java?


http://java.sun.com/developer/techni...leases/j2se15/

The metadata bit of this seems to suggest that in future releases of
java, you'll be able to generate actual source code on the fly.


I think the metadata is for hints for documentation generation.

I could be wrong.

But I'd hate to work out a security system for Java if they allow the
code to modify itself. Dynamically extending classes is plenty.
Jul 17 '05 #9
kjc <ks*****@elp.rr.com> wrote in message news:<5A*****************@fe1.texas.rr.com>...
No, but this could be done in Smalltalk blind folded.
You can use Java Reflection which is Java's counterpart to Smalltalk's
perform: concatenate some strings to create an existing method name
and call that method. Or you can use the command pattern and add
commands as required to a list and execute them sequentially.

Cheers, Oliver
Japcuh wrote:
How do you write self modifying code in Java?

Japcuh
(Just Another Perl C Unix Hacker)
http://www.catb.org/~esr/faq/hacker-howto.htm#what_is
.0.
..0
000

Jul 17 '05 #10
Check out this package:

http://jakarta.apache.org/bcel/
"Japcuh" <ja****@gmail.com> wrote in message
news:3a**************************@posting.google.c om...
How do you write self modifying code in Java?

Japcuh
(Just Another Perl C Unix Hacker)
http://www.catb.org/~esr/faq/hacker-howto.htm#what_is
.0.
..0
000

Jul 17 '05 #11
ja****@gmail.com (Japcuh) wrote in message news:<3a**************************@posting.google. com>...
How do you write self modifying code in Java?

Japcuh
(Just Another Perl C Unix Hacker)
http://www.catb.org/~esr/faq/hacker-howto.htm#what_is
.0.
..0
000


It's nowhere near as easy as it is in Perl.

If you look at JDBC you'll see that there's a call to Class.forName()
to load the driver class. That may be of use to you. It's sort of an
'import' on the fly.
Jul 17 '05 #12

"Japcuh" <ja****@gmail.com> wrote in message
news:3a**************************@posting.google.c om...
How do you write self modifying code in Java?

Japcuh
(Just Another Perl C Unix Hacker)
http://www.catb.org/~esr/faq/hacker-howto.htm#what_is
.0.
..0
000


Look up "Javassist" on google. Its what JBoss 4.0 uses to do dynamic aspect
weaving and dynamic remote proxy generation among other things. By the way,
for those who have used cglib, can you point toward some good online docs?
I have been unable to find any I found adequate. Javassist has pretty good
docs however.

l8r, Mike N. Christoff

Jul 17 '05 #13
ja****@gmail.com wrote...
How do you write self modifying code in Java?


If it's truly self-modifying, good luck debugging it.
Jul 17 '05 #14
Entropy <en*****@domain.invalid> scribbled on the stall wall:
ja****@gmail.com wrote...
How do you write self modifying code in Java?


If it's truly self-modifying, good luck debugging it.


the simple answer is "you can't"...self modifying code hasn't really been
feasible since the fortran 4 days...or maybe in C but that is still
platform dependent.

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 17 '05 #15
no***@uber.usachoice.net wrote...
Entropy <en*****@domain.invalid> scribbled on the stall wall:
ja****@gmail.com wrote...
How do you write self modifying code in Java?


If it's truly self-modifying, good luck debugging it.


the simple answer is "you can't"...self modifying code hasn't really been
feasible since the fortran 4 days...or maybe in C but that is still
platform dependent.


I recall the capacity of LISP-like functional languages (ie, Scheme)
to dynamically generate new functions and apply them.

It was a long time ago when I sat in that class, however, and I've
never used such a language outside of the classroom.
Jul 17 '05 #16


Wiseguy wrote:
Entropy <en*****@domain.invalid> scribbled on the stall wall:
ja****@gmail.com wrote...
How do you write self modifying code in Java?


If it's truly self-modifying, good luck debugging it.

the simple answer is "you can't"...self modifying code hasn't really been
feasible since the fortran 4 days...or maybe in C but that is still
platform dependent.


Java "modifies itself" every time it loads a new class
definition. An important point is that the decision to load
a class is made at run time, not at a "link time."

A Java program can even generate an array of bytecodes
at run time, turn them into a class, and create objects of
that class; see defineClass() in java.lang.ClassLoader.

--
Er*********@sun.com

Jul 17 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: qwweeeit | last post by:
Hi all, when I was young I programmed in an interpreted language that allowed to modify itself. Also Python can (writing and running a module, in-line): fNew =open("newModule.py",'w') lNew=...
2
by: Joel Jose | last post by:
agreed the 'mutation engine' by dark avenger was a real deadly master-code piece.., but then.. if one could create a self mutating code..in real time then i think it would just b the most...
18
by: Ralf W. Grosse-Kunstleve | last post by:
My initial proposal (http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html) didn't exactly get a warm welcome... And Now for Something Completely Different: class autoinit(object):...
13
by: Robin Becker | last post by:
When young I was warned repeatedly by more knowledgeable folk that self modifying code was dangerous. Is the following idiom dangerous or unpythonic? def func(a): global func, data data =...
12
by: AES | last post by:
Can an HTML web page dynamically modify its own code? (without resort to Java or any other non-HTML complexities) That is, is there any provision in HTML such that a single "Next" button on a...
10
by: jon | last post by:
I am a beginner C programmer, this is actually my first programming lanugage, besides html, cgi, and javascript. I am looking for a way to make an .exe file, or a copy of my own file. I have tried...
5
by: IUnknown | last post by:
Ok, we are all aware of the situation where modifying the folder structure (adding files, folders, deleting files, etc) will result in ASP.NET triggering a recompilation/restart of the application....
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.