473,322 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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 8071
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.