Results 1 to 3 of 3
- 01-27-2010, 12:57 AM #1
Member
- Join Date
- Aug 2009
- Posts
- 24
- Rep Power
- 0
Java method to run code from string
I know that this sounds a little weird, but is there anyway to take a string that is a string of java code, and run it. like if I had the string Program and it had the contents:
and then i wanted to run the code within the string, is that possible? If so how would I do that? thanks!Java Code:import java.util.Scanner; public class Main { public static void main(String[] args) { System.out.println("What is your name?"); Scanner in = new Scanner(System.in); String str = in.nextLine(); } }
- 01-27-2010, 01:06 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
There are lots of scripting languages for Java. If you want the string to be executed as Java code then BeanShell could do what you want.
- 02-02-2010, 10:33 PM #3
Member
- Join Date
- Aug 2009
- Posts
- 24
- Rep Power
- 0
Similar Threads
-
Pass String[] into method in different class
By Swankee in forum New To JavaReplies: 19Last Post: 09-28-2009, 05:30 PM -
Invoking method from String
By Supamagier in forum Advanced JavaReplies: 12Last Post: 05-29-2009, 09:21 AM -
Entering string in a loop with method
By Konex in forum New To JavaReplies: 3Last Post: 03-01-2009, 07:33 AM -
Method for String to int conversion
By Java Tip in forum Java TipReplies: 0Last Post: 01-02-2008, 06:35 PM -
String replace method
By venkata.tarigopula in forum Advanced JavaReplies: 1Last Post: 07-10-2007, 08:14 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks