i want to do a compiler but, now i am stuck in the compilation part,
suppose that i want to compile "cool.java" that is located in the bin directory, what shold i do??
help please

Recommended Answers

All 8 Replies

Read the "Getting Started" Tutorial. And don't save anything to the "bin" directory (or any other directory inside of the jdk directory).

thanks for replying
I have done the compilation part using the Java Compiler Api

but can any 1 know how to run the generated class file??

thanks

Well you need to properly read the introduction of Java where authors of various books have mention how to compile and run your first program in Java.

Anyway, if you have compiled the .java source code to .class file, and you want to run it, then you need to verify whether java command is available in your PATH environment variable or not. Follow the steps given below:

1) Open a command prompt and type java.

2) If it says java not found and you have installed jdk/jre, then you need to manually set the PATH.

3) To manually set the PATH, type on your command prompt
set JAVA_HOME=C:\Program Files\Java\Jdk1.6.0_1
set PATH=%PATH%;JAVA_HOME

4) To execute cd to whatever directory your .class is present. Suppose it is present in D:\demo and .class is Hello.class

5) Then type java Hello

6) And you'll see your program is executing

7) In some cases, you might get an exception "NoClassFoundException" then you are required to set the CLASSPATH variable.

8) Type set CLASSPATH=.

9) Then type java Hello
//.means current working directory. So when searching for class, Java class loader will look into current working directory (D:\demo) and execute the Hello program

Well you need to properly read the introduction of Java where authors of various books have mention how to compile and run your first program in Java.

Anyway, if you have compiled the .java source code to .class file, and you want to run it, then you need to verify whether java command is available in your PATH environment variable or not. Follow the steps given below:

1) Open a command prompt and type java.

2) If it says java not found and you have installed jdk/jre, then you need to manually set the PATH.

3) To manually set the PATH, type on your command prompt
set JAVA_HOME=C:\Program Files\Java\Jdk1.6.0_1
set PATH=%PATH%;JAVA_HOME

4) To execute cd to whatever directory your .class is present. Suppose it is present in D:\demo and .class is Hello.class

5) Then type java Hello

6) And you'll see your program is executing

7) In some cases, you might get an exception "NoClassFoundException" then you are required to set the CLASSPATH variable.

8) Type set CLASSPATH=.

9) Then type java Hello
//.means current working directory. So when searching for class, Java class loader will look into current working directory (D:\demo) and execute the Hello program

you really dont understand..

i am making a compiler.and not compiling

any 1 can help me to run the class generated??

you really dont understand..

i am making a compiler.and not compiling

any 1 can help me to run the class generated??

No need to be harsh this way.

Your first post sound as english is not your first language and you do not provide a proper explanation. Secondly only beginners really put any code in "bin" folder as they can't or do not want to figure out how to set up PATH and CLASSPATH for Java.

Your question "any 1 know how to run the generated class file??" sounds like begginer call for help. I hope that you learn from your mistake and next time provide good explanation.

Well for using Java Compiler API you can refer to the following link http://www.javabeat.net/javabeat/java6/articles/java_6_0_compiler_api_1.php.

But as you already told that you have succeeded in compilation and now wants to execute then simply use the java command.

If in case you want to write your own VM for running the compiled .class file then please refer to the following open source projects. They will help you get started:

1) OpenJDK
2) Apache Harmony
3) Kaffe from http://www.kaffe.org/.

No need to be harsh this way.

Your first post sound as english is not your first language and you do not provide a proper explanation. Secondly only beginners really put any code in "bin" folder as they can't or do not want to figure out how to set up PATH and CLASSPATH for Java.

Your question "any 1 know how to run the generated class file??" sounds like begginer call for help. I hope that you learn from your mistake and next time provide good explanation.

feel so offended??

commented: Bad attitude... -1

Well for using Java Compiler API you can refer to the following link http://www.javabeat.net/javabeat/java6/articles/java_6_0_compiler_api_1.php.

But as you already told that you have succeeded in compilation and now wants to execute then simply use the java command.

If in case you want to write your own VM for running the compiled .class file then please refer to the following open source projects. They will help you get started:

1) OpenJDK
2) Apache Harmony
3) Kaffe from http://www.kaffe.org/.

i have done the progrm, thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.