Results 1 to 5 of 5
  1. #1
    xael is offline Member
    Join Date
    Sep 2010
    Posts
    31
    Rep Power
    0

    Default Converting String to Usable code

    How would I make a method or a line of code from a string value? Say I typed in "i=1;" in a text field, is there a way to put that text in the compiling code? This is not about assigning values to variables, this is about being able to write a method in a running java program and then implement it. That would be awesome. Thanks in advance.

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    While I'm not 100% sure, I'm fairly certain this cannot be done.

    However, I must ask: Why do you wish to do this? A user could type an erroneous line of code and crash the application, or a malicious piece of code that manipulates the program in an undesirable way.

    PS: You could parse it as JavaScript if you wanted... http://download.oracle.com/javase/6/...ide/index.html

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,773
    Blog Entries
    7
    Rep Power
    21

    Default

    ... also you can have a look at BeanShell (google is your friend here).

    kind regards,

    Jos

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default

    Or the JavaCompiler class would allow you to create a java source program, compile it and execute it within a java program.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Converting string to byte[]
    By bobo67 in forum New To Java
    Replies: 12
    Last Post: 09-10-2010, 10:10 PM
  2. Converting to String
    By darek9576 in forum New To Java
    Replies: 1
    Last Post: 03-13-2010, 11:07 PM
  3. Is it OK to do this... (converting int to string)
    By Psyclone in forum New To Java
    Replies: 1
    Last Post: 02-16-2010, 06:51 PM
  4. Replies: 3
    Last Post: 03-19-2009, 05:01 AM
  5. Converting object to string
    By Preethi in forum New To Java
    Replies: 4
    Last Post: 06-14-2008, 04:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •