Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Self-Deletion

  1. #1
    Member Andrew R's Avatar
    Join Date
    Jul 2013
    Location
    San Pedro Sula, Honduras
    Posts
    58
    My Mood
    Inspired
    Thanks
    11
    Thanked 1 Time in 1 Post

    Lightbulb Self-Deletion

    Hello forums!

    I've opened this thread to discusss "self deletion" in Java.

    It is perfectly possible, but has a trick to it. Obviously, you can't delete a file that is running. We'd have to send a scheduled delete request to the shell of the OS. (though its bad architecture since you're program is dependant on an specific platform) anyways that can easily be forseen.

    Anything that is being run cannot be deleted as it is a process in use. What you could do (and this is dirty, bad architecture) is use Runtime.exec() to (on windows) use the "AT" command to schedule a delete command on your java code files. Again, this is not the best idea and it's platform dependant (so you'd have to have a way to do this on linux too - cron would do it).
    -from another forum

    I'd say to use the ProcessBuilder instead of the Runtime.exec(), because it is very limmited.

    Some people are using this

    public static void main(String[] args) throws Throwable {
    File f = new File("DeleteMe.jar");
    f.deleteOnExit();
    }
    The reason why I've started to look at this option is because, the program I am working with, generates 2 copies of itself, and has one of the deletes the original, but it generates several unsyncronized problems, which thread and waiting would not prevent it to a 100%. So I rather have each program take care of itself, sending a delete request on itself upon conclusion of its instructions.

    Ideas, advice, comment?

    I appreciate your feedback. Meanwhile.. I'd be google-ing and trying to apply it.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Self-Deletion

    This seems like a bad idea. Why do you need to do this? Seems a bit fishy to me...
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member Andrew R's Avatar
    Join Date
    Jul 2013
    Location
    San Pedro Sula, Honduras
    Posts
    58
    My Mood
    Inspired
    Thanks
    11
    Thanked 1 Time in 1 Post

    Default Re: Self-Deletion

    The program simulates living cells (biology). When it "divides" there is no original. Nothing fishy, just being creative here.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Self-Deletion

    That is interesting. I just question why you want to do this using file creation and deletion. Couldn't you do the same thing with objects in a single program without worrying about kludgy file manipulations? What benefit do you get by using files instead of Objects?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Member Andrew R's Avatar
    Join Date
    Jul 2013
    Location
    San Pedro Sula, Honduras
    Posts
    58
    My Mood
    Inspired
    Thanks
    11
    Thanked 1 Time in 1 Post

    Default Re: Self-Deletion

    Couldn't you do the same thing with objects in a single program without worrying about kludgy file manipulations? What benefit do you get by using files instead of Objects?
    It is not intended to be a game by the way, for that I'd rather use objects.

    Instead of having the object as "as a cell" contained in a program "as environment", I want the program "as a cell" contained in an OS environment "as environment".

    Objects obviously occupy memory, but they don't have a "bodily representation" like a .class file to be able to exist.

    If I'd like to use something fishy, I would've looked into quine programming instead.

    These are just the baby steps. I've figured out how simulate "communication" between programs, assign them a purpose, read other .java fragments and use trial-and-error until code's prediction matches with the debugging the fragments of code, keep record of results, until it rewrittes the code for future use.

    The logic is quite easy, just a little bit extense. I didn't know much about file manipulation in Java yet, I need to wait 2 weeks till I start learning that at the University.

    I am just trying to simulate living cells. And I certainly need some safeguards to avoid infite looping from duplication.

    I'll code another program that monitors the activity.

    --- Update ---

    So yeah, I need to know how to get a program delete itself. Instead of having one of their child programs to delete it, it causes some problems, files get deleted before another program's instructions get to use them. That's the sort of problem I am trying to avoid here. I'd rather have each program delete itself after its done.

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Self-Deletion

    Quote Originally Posted by Andrew R View Post
    It is not intended to be a game by the way, for that I'd rather use objects.
    I figured it wasn't a game, but I'm still not sure what benefit you get by using files.

    Quote Originally Posted by Andrew R View Post
    Instead of having the object as "as a cell" contained in a program "as environment", I want the program "as a cell" contained in an OS environment "as environment".

    Objects obviously occupy memory, but they don't have a "bodily representation" like a class to be able to exist.
    I don't quite know what you mean by any of this, but an Object can be a collection of data structures that serve as a "bodily representation". If you're going to eventually introduce mutation, using a data structures that encodes the behavior seems more reasonable than mutating actual code. Again, this is exactly the kind of stuff lisp was built for.

    Quote Originally Posted by Andrew R View Post
    I am just trying to simulate living cells. And I certainly need some safeguards to avoid infite looping from duplication.

    I'll code another program that monitors the activity.
    There are a bunch of algorithms that simulate biological processes. I would maybe look into how they operate before you rely too heavily on what sounds like an overly-complicated process involving files.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Member Andrew R's Avatar
    Join Date
    Jul 2013
    Location
    San Pedro Sula, Honduras
    Posts
    58
    My Mood
    Inspired
    Thanks
    11
    Thanked 1 Time in 1 Post

    Default Re: Self-Deletion

    I see. I don't know anything about lisp. I am using what I know, which is why I am using Java, it may be kind of a bottle neck but I rather do it, than wait long enough to lose interest. I don't know about any of these algorithms you are talking about (except quines).

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Self-Deletion

    Quote Originally Posted by Andrew R View Post
    I see. I don't know anything about lisp. I am using what I know, which is why I am using Java, it may be kind of a bottle neck but I rather do it, than wait long enough to lose interest. I don't know about any of these algorithms you are talking about (except quines).
    My only point is that I don't think you're approaching this the right way. Creating a self-deleting program is a pretty bad code smell, which you've probably seen if you've googled the problem. I'm not trying to criticize you; I think the project sounds interesting, but there is almost definitely a better way to accomplish your goals.

    You might want to look into natural algorithms including particle swarm optimization, evolutionary algorithms, genetic algorithms, and even ant colony optimization. They involve creating copies of individuals and running them in an environment, and none of them do it by using self-deleting programs.

    I think you should take a step back and examine your goals and think about other ways to accomplish them. Trying to use self-deleting programs is probably a dead end. But it's up to you.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9
    Member Andrew R's Avatar
    Join Date
    Jul 2013
    Location
    San Pedro Sula, Honduras
    Posts
    58
    My Mood
    Inspired
    Thanks
    11
    Thanked 1 Time in 1 Post

    Default Re: Self-Deletion

    Besides, Java has a broad community and platform support as well.

    Do you have any resources of knowledge I can get my hands on? I would certainly start reading about it if I knew where to look and what to read. Any suggestions then?

  10. #10
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Self-Deletion

    Quote Originally Posted by Andrew R View Post
    Besides, Java has a broad community and platform support as well.
    I'm not arguing that you entirely switch over to lisp. But if this kind of stuff is something you're interested in, it would definitely be worthwhile to check out how it's done in lisp. You're trying to pound a nail in using a screwdriver. You might as well look at how people use a hammer to accomplish the goal.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #11
    Member
    Join Date
    Sep 2013
    Posts
    102
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Default Re: Self-Deletion

    I would look into temporary file execution. From the conversation here it seems to me Andrew that you are attempting to imitate biological processes to study them or learn in the process of creating something of equal value? But the best representation of genetic code is code, thus the physical would represent the physical. The combination of nucleotides is binary equivalent, and physical maintenance/input would be the computer (Organelles: monitor, essentially output/ Glycocalyx: inputs/ smaller components (transistors, capacitors) mirroring smaller portions of the cell (Cytoplasms' many smaller process that make things possible)).

Similar Threads

  1. [SOLVED] file deletion/renaming not successful, don't think I have any streams open
    By Bottleskup in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 21st, 2011, 04:14 PM

Tags for this Thread