compile « string « Java Data Type Q&A

1. What happens at compile and runtime when concatenating an empty string in Java?

This is a question that arose mostly of pure curiosity (and killing some time). I'm asking specifically about Java for the sake of concreteness. What happens, in memory, if I concatenate a ...

2. From compilation to runtime, how does Java String encoding really work

I recently realized that I don't fully understand Java's string encoding process. Consider the following code:

public class Main
    public static void main(String[] args)

3. Compile Java source code from a string?

Is there a way for a running Java program to compile Java source code (passed as a string)?

Class newClass = Compiler.compile ("class ABC { void xyz {etc. etc. } }");
Ideally, any ...

4. Converting a string value to an unkown (at compile time) object type

I have a class type and I have a value in a string:

Class<?> type = Integer.class // <-- in reality, that type is 

5. Can't Get Program to Compile

Pretty new to Java programming, but I'm having trouble getting this to run. I want to read in a word using the StringBuffer class, then reverse it. I am fairly unfamiliar ...

6. Compile a java program given in a String

I want to conduct a little experiment, and generate a java program in a String (the experiment is itself in Java). Now I want to test whether it compiles or not. ...

8. Is there a simple way to compile a source code String programmatically?

I have a String that has source code (1.6): full class in it. I've look around... javassist: can't find a way to do full class--looks like it just does parts of one. Also, doesn't support jdk 1.5/6 features janino: doesn't support new jdk 1.5/1.6 features jdk 1.6 ToolProvider.getSystemJavaCompiler(): Messy and looks like it is strictly file based unless maybe you could ...

10. error [Ljava.lang.String.... when compiling

String[] aa = { "question aa" }; String[] bb = { "question bb"}; String[] cc = { "question cc"}; String[] dd = { "question dd"}; String[][] questions = { aa, bb, cc, dd }; int leng = questions.length; for (int i = 0; i < leng; i++) { int rand = (int) (Math.random() * leng); System.out.print(questions[rand]); System.out.print(" "); }

12. pattern.compile with brackets inside string

thanks to all..I am a bit confused now following the thread.. I have tried a few combination from your posts, but perhaps not in the correct manner.. indeed, I would also need to capture "I am going home (tomorrow), and so on".. I could use a simple string.contains method, but that would give me a true value even is the string ...

13. String error. Won't compile program properly.

14. Compile a string

I have a file with about 30K lines of text. Someone created models with a Genetic Algorithm and stored the results in the file. They are all mathematical results express in java code. For instance a line may look like this: Math.pow(variable,2) + Math.sin(angle) * 9.845732 Each line is a model, we need to test these models and I was wondering ...

15. Weird compile issue - new String[]{,} should it compile?

Hi all, We found a weird looking glitch at work today that we're sure shouldn't compile. One of our String arrays had an extra comma but it still compiles. See: public class Test { public static void main(String[] args) { String[] stuff = new String[]{,}; String[] stuff2 = new String[]{"Foo", "Bar",}; System.out.println(stuff.length); System.out.println(stuff2.length); } } Why the heck does that compile? ...

16. Compile time string (MACRO)