Is it possible to create class programatically?

Advertisement
I want to create a class from a string that contains java code.
For example: I have the following string
String code = "class HelloWorld{
public static void main(String [] args){
System.out.println("Hello World");
I wonder if I can convert it to java class programatically on runtime and use it.
Advertisement

Replay

* Main.java
package sometest;
import java.io.FileOutputStream;
import java.lang.Runtime;
* @author Ganesh
public class Main {
/** Creates a new instance of Main */
public Main() {
* @param args the command line arguments
public static void main(String[] args) throws Exception{
// TODO code application logic here
FileOutputStream fos = new FileOutputStream("HelloWorld.java");
String code = "class HelloWorld{ " +
"public static void main(String [] args){"+
"System.out.println(\"Hello World\"); " +
fos.write(code.getBytes());
java.lang.Runtime rt = java.lang.Runtime.getRuntime();
try {
rt.exec("javac HelloWorld.java");
System.out.println("Compile OK");
}catch (Exception e) {
System.out.println("Compile not OK");
try {
rt.exec("java HelloWorld");
System.out.println("Run OK");
}catch (Exception e) {
System.out.println("Run not OK");
System.out.println("OK");
this would work?

Is it possible to refer class files by mapping network drive?

Hi, Is it possible to refer class files from the server(By mapping network of client's server) and specify this in project setting. If yes, how? Right now I copied all class file needed, to 'myclasses' directory of jdevhome. this approach is working

Is it possible to create Resuable component in Swing

Can Some one tell me Is it possible to create Resuable component in Swing? I have around 100 applications and i have to create a common Component and I have to use for this to all 100 Applications. If possible can u send me code. Thanks Mohan KumarHi

Is it possible to create a panel with JavaScript?

Hi friends As I´m studying JavaScript and the user interface creation...would like to ask (more for curiosity): Is it possible to create a new panel for Illustrator using JavaScript? Or this is only possible using C++? (in the Window Class UI we have

Creating function without creating class

we can write stand-alone functions in c/c++ (without creating class) that is not possible in c++. but somebody told me there is a way to do this in Java. i could not believe. he did not tell me the way. is it really possible ?It is not possible to cr

Is it possible to create java standalone programs with java ME 8

Hi, Comparing java ME to java SE, I have the impression that midlets are similar to applets. When working with java SE, I usually make standalone programs. Now, I wonder if it is also possible to create also standalone programs for java ME, if the cl

Creating class via reflection

Hi, Is there a possibility to create dynamically class and add to it methods/fileds/annotaions etc. What I am thinking of is to create jpa entity class dynamiclly and use jpa provider to create table for it.Not with reflection, no. You need something

Is it possible to create .ncd file without using MAX?

Is it possible to create .ncd file without using MAX? I am trying to read the data given by hundreds of possible Arb. IDs on one of the CAN port without having to create it from the MAX. Thank youHi, the NI-CAN driver software does not provide functi

Is it possible to create vendors with same name and city in FK01?

Hi All, I need to create vendor through transaction FK01. I need to create two vendors: 1. Name-Abdul, City-Hyderabad, Country-India. 2. Name-Abdul, City-Hyderabad, Country-Pakistan. Is it possible to create in such a way. Please help. Thanks in adva

Is it possible to create WEB SERVICE in SAP 4.7

Hi guys, is it possible to create WEB SERVICE in SAP 4.7 ? i want to make a FM as web service enabled. plz advice. Regards pabiHi, The definitive (and in my experience only) documentation on this is at; http://help.sap.com/saphelp_47x200/helpdata/en/

Is it Possible to create custom Object type in configuration Tab

Hi , We have object type for table in Development Tab in SOLAR02 , is it possible to create a custom object type to represent the table object type in Configuration Tab. Please let me know the steps , if it is possible. Best Regards, SaravanaHi You a

Possibility of creating Settlement Rule in Background?

Hi Gurus,            When I am doing TECO of the Maintenance Order everytime I have to create Settlement Rule.            My settlement receiver Category (Cost Center) and Cost Center are fixed for  Order Type.            Is it possible to create Set

Is it possible to create export Data source on 0material DT

Hi guys, is it possible to create export datasource on 0material DT your help will be greatly appreciated. ThanksRealist, Its the normal procedure....after the option export datasource...select the datasource 8<0material> and assign it to an infosou

How do I create a "place" in iPhoto's Places list? Is this possible the way it's possible to create albums? Also, how do I assign a place to a photo or vice versa?

How do I create a "place" in iPhoto's Places list? Is this possible the way it's possible to create albums? Also, how do I assign a place to a photo or vice versa?Select a Photo in the iPhoto Window and click on the 'i' button lower right. This

Is it possible to create a workflow that exports PDF tables to Excel?

Afternoon all, I've seen that it's possible to export tabulated information within a PDF document to Excel (http://www.adobe.com/products/acrobat/pdf-to-excel-xlsx-converter.html) but this is a very manual process. I'm wondering if it's possible to c

Is is possible to create Socket using Java Stored Procedures/Function(Ora)?

Hello Friends, Is is possible to create Socket using Java Stored Procedures/Function in Oracle? OR How I can send a message from oracle to Java Desktop Application which is working like server program? Please Guide !!J3Ganesh wrote: Hello Friends, Is

Is it possible to create hotkeys?

I was wondering if it's possible to create hotkeys / shortcut keys / functions keys in Flex? I know you can do this in JavaScript, in the browser, by trapping keyboard event. There's also a JQuery extension that provides an easy API to do this. Thank

Is it possible to create an inbound delivery for STO in a 2 step process ?

Hi Experts, Is it possible to create an inbound delivery for STO in general (how do I get a vendor for a Plant. I have already assigned a plant to my vendor in vendor master - additional purchasing data, but it does not seem to work). In particular i

Is it possible to create a hyperlink in ERP report output

Is it possible to create a hyperlink in ERP report output connecting it to an outside application? Regards Sridharuser11996389 wrote: Is it possible to create a hyperlink in ERP report output connecting it to an outside application?It is possible for

What are the steps to create classes?

What are the steps to create classes?Hello. Here's one example applied to a BSP page. How to create your first OO Abap Class for a BSP Kind regards. BrunoRead other 3 answers