Code to compile java program

hello,
i am studying msc(information systems) 2 years course.
this is my first semister.i am doing prof\ject in java.
TITLE:Designing editor for java in java.
I want to know how to compile a program written in the editor.i will feel very much happy,if u could tell me the suggestion.And alse running the class file.
thanking you...

Hi rajesh!
First you need a java development kit (jdk).
If you didn't get it yet you can download the actual version on this page (just search for "download").
If you've installed the jdk make sure that the path where you installed your jdk is set to your systems path value (windows)
you can put it in by editing your autoexec bat or by giving the following order to your dos box:
1.) PATH (returns the actual path settings)
2.) SET PATH old values, [...]\jdk\bin
After having done this you should reboot your system.
Now you can change the directory to your programs path and call:
JAVAC yourfile.java
this compiles your program
JAVA yourfile
(without any file extension!!) runs your program
It might be useful to download the API Documentation, where the jdk tools are all descripted!!
hope it helps,
Thof

Similar Messages

  • Compiling Java Program thro EXEC

    hi..
    I want to compile java programs programatically. I am using exec for that. The problem is there is a error in the i am no getting any message from that Process .will u help me how to solve this
    URGENT
    pyari
    Code Snippet
              try
                                  String command = "cmd /c javac -classpath c:\\j2ee\\home\\ejb.jar -d "+
                                  "c:\\javapr~1\\WeblogicEJBComplier\\tempBuild "+
                                  "C:\\j2ee\\home\\demo\\ejb\\cart\\CartClient.java";
         System.out.println(command);
         Runtime rnt = Runtime.getRuntime();
                                  Process prs = rnt.exec(command);
                                  BufferedReader bfr = new BufferedReader(new InputStreamReader(prs.getInputStream()));
                                  String str = bfr.readLine();
                                  System.out.println(str);
                                  while(str!=null)
                                       System.out.println(str) ;
                                       str = bfr.readLine();
              }catch(Exception eo)
                   System.err.println(eo);

    javac writes the errors in stderr, not in stdout.
    So replace getInputStream() with getErrorStream()...

  • HELP for Compile java programe !

    Hello All,
    i want to make java programe by which i can compile java programes
    and when i compile java programe from my programe then
    i shoul get compiled status means programe compile successfuly
    or not compile.
    if any example i m thanksfull.
    onlyforjava.

    how about if compile fail?
    the process obj seems return value 0 as it run successful.
    I haven't try this, but I have experienced the process obj returns 0 if the executed command has some routine to handle error cases, in which, error will not halt the system.
    So, I recommand the following scenario.
    1. let say, if your java is test.java. check the existence of file test.class.
    If, it exists, get its modified time.
    2. compile the java code with
    Procress p = Runtime.exec(new String[]{"javac", "test.java"});
    3. get the error string if any.
    InputStream in = new BufferedInputStream(p.getInputStream());int read;while ((read = in.read()) != -1){  System.out.println((char)read);}
    4. handle error with the exitValue
    if (p.exitValue() != 0){  System.out.println("warning.");}
    5. check again the file test.class if it is a newly created file.
    6. if it is newly created, compile success. Else, failed.

  • How to compile java programs in j2EE 1.4 SDK

    hi,
    i HAVE JUST INSTALLED NEW J2EE 1.4 SDK , IT HAS BEED INSTALLED SUCCESFULLY BUT I AM UNABLE TO COMPILE JAVA PROGRAMS WHICH I USED TO RUN IN SDK 1.4 ,OR EVEN NEW WRITTEN EXAMPLES. CAN ANYONE PLZ HELP ME.

    J2EE by itself is not capable of compiling Java. It requires that a J2SDK be installed first - this is what compiles and runs Java programs. Did you install the combination J2SDK and J2EE, or just the J2EE?
    If both are installed, then you should be able to compile and run as you used to..

  • Calling C code (exe ) from Java program

    Hi all,
    kindly help in giving a solution for calling C code (exe ) from Java program, i will be very thank full to u if any body can help in sending a code example
    bye

    You might need to consume the io operations on the Process...
    An excerpt from java.lang.Process:
    All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams (Process.getOutputStream(), Process.getInputStream(), Process.getErrorStream()). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.

  • Not able to compile java program

    Hi
       I a using Netweaver to deelope the java code.I have written a javaprogram .But when choose the option Run as
    a javaApplication it giving the following error
    Source locator  doesnot Exist:org.eclipse.jdt.debug.ui.javaSourceLocator

    Hi,
    I am able to compile and run perfectly Java programs. The steps goes as:
    1. File --> New --> Project --> Java --> Java Project --> give a <project name> --> Finish
    2. File --> New --> Class --> give a classname, and package name.
    3. Put main method and give a System.out.println("Hello");
    Source code:
    package com.i3l.trg;
    public class HelloWorld {
         public static void main(String[] args)      {
              System.out.println("Hello");          
    4.Goto Run --> Run As --> 2 Java Application.
    5. You will get a output as "Hello" in java console.
    Cheers!!!
    Sukanta Rudra
    PS: Liberally donate points.
    The full source code is

  • Compiling Java program from other java program

    Hi,
    How can I compile and capture the compilation result from another java program?
    Thanks

    As if I had seen somewhere a hint about being able to
    programatically compile with the help of the class
    sun/tools/javac/Main found in the tools.jar.I saw that article, too, but when I took a look at the JDK's source code, it became apparent that none of the classes in tools.jar are supported. Your program could break with any new version of the JDK.
    If you're still interested, here's the URL:
    http://java.sun.com/developer/JDCTechTips/2003/tt0722.html

  • Exception when running a compiled java program in DOS

    I'm new to programming in general and java in specific. I am using the jGrasp programming software, and successfully compile my program, but when I try to run it out of DOS (which I undesrtand is the purpose of java to begin with, unless I'm mistaken), I get an exception that looks exactly like this.....
    Exception in thread "main" java.lang.NoClassDefFoundError: keyboard/java
    Caused by: java.lang.ClassNotFoundException: keyboard.java
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    I realize I may just be missing something simple, as I've not been in the class for very long, but the book doesn't seem to have the answer. It is "Starting out with Java: Early Objects, Third Edition, by Tony Gaddis. Any help will be apprecieated. The program is below, it's really short.
    The program is a simple one to teach myself scanner input and an 'if' statement:
    *     basic input program
    import java.util.Scanner;
    public class keyboard
         public static void main(String[] args)
              String Class;
              int age;
              String race;
              char sex;
              String gender;
              Scanner keyboard = new Scanner(System.in);
              System.out.print("What class do you wish to be? ");
              Class = keyboard.nextLine();
              System.out.print("How old is your character? ");
              age = keyboard.nextInt();
              keyboard.nextLine();
              System.out.print("What sex is your character? M/F? ");
              gender = keyboard.nextLine();
              sex = gender.charAt(0);
              System.out.print("What race is your character? ");
              race = keyboard.nextLine();
              if (sex == 'M')
                   System.out.println("Today you will be playing a " + race + " " + Class +
                                                           " who is " + age + " years old at the start " +
                                                           "of his adventuring career!");
              if (sex == 'F')
                   System.out.println("Today you will be playing a " + race + " " + Class +
                                                           " who is " + age + " years old at the start " +
                                                           "of her adventuring career!");                                   
    }

    Childofheinlein wrote:
    I'm new to programming in general and java in specific. I am using the jGrasp programming software, and successfully compile my program, but when I try to run it out of DOS (which I undesrtand is the purpose of java to begin with, unless I'm mistaken), I get an exception that looks exactly like this.....
    So summerizing some of what was said before and some of that wasn't.
    jGrasp is a simplistic IDE. When you pop a dos window from it it sets up the windows correctly to run your program. When you open a regular command window you must do the same yourself.
    >
    Exception in thread "main" java.lang.NoClassDefFoundError: keyboard/javaJava runs "classes". The command that you typed above meant that you were trying to run a "file". Specifically the file "keyboard.java". The two are not the same. There is however a relationship. When the source code, in this case inside of "keyboard.java" is compiled it produces a file called "keyboard.class". Insided of the file there is a "class" called "keyboard". Notice that the name of the class does not have either .java nor .class on the end of it.
    The VM (the 'java' command) finds a "class" using the class path to search files of various types for the class (again keep in mind that files contain classes but they are not themselves classes.)
    You can add to the classpath using the Sun VM using either command line options or environment variables. As noted in some of the previous messages those are "-cp" and "CLASSPATH". It is important to note that that does NOT fully specify the class path. But for your purposes it is sufficient to think of it as doing so.
    The 'default' setting for the part of the class path that you normally set (like via '-cp') is the current directory which is specified by the ".". So normally the following are equivalent.
    java -cp . keyboard
    java keyboard
    The reason the VM could not find your class when you opened the dos window yourself is because you were in the wrong directory. If you had been in the directory with the file "keyboard.class" then it would have worked (if you have not messed with the environment variable "CLASSPATH".)
    So if your class file has the following location: c:\myapps\java\keyboard.class then you can do the following.
    1. Open a console window
    2. Type "cd c:\myapps\java"
    3. Type "java keyboard"
    If the above does not work then you are in the wrong directory or the env variable CLASSPATH has been set to something.

  • How to compile java programs? There is no javac for me!

    Hi, I'm starting to learn java and downloaded the java 1.4.0.1 standard edition from this website. However, after I installed the program, there is no javac to be found while there is a java.exe. I need javac to compile my program before I can interpret it but it is nowhere to be found!
    Did I download the wrong SDK version? I thank anyone in advance who can help me in the right direction!

    You must have the SDK to create programs. The Jre is a component of the SDK that can be downloaded separately if you only want to run programs.
    SDK downloads from here, use the row "Windows (all languages, including English)" and be sure to select the SDK COLUMN, not the JRE:
    http://java.sun.com/j2se/1.4/download.html

  • 32 bit compiled Java Program not connecting to 64 bit Oracle 11g

    Hi,
    I am using one java program to connect to Oracle 11g (64 bit version) using Oracle10g 32 bit client libraries using OCI calls. Below is the program. If I compile it using 64 bit Oracle 10g libraries ($ORACLE_HOME/lib and $ORACLE_HOME/rdbms/lib) , it perfectly connects to Oracle11g but when i compile it using $ORACLE_HOME/lib32 and $ORACLE_HOME/rdbms/lib32, it hangs and keeps trying and takes 100% cpu usage. it does nothing. Please suggest what is going wrong in the environment.
    ============================
    import java.sql.*;
    class dbAccess {
    public static void main (String args []) throws Exception
    Class.forName ("oracle.jdbc.OracleDriver");
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:oci8:@lvfd", "fde", "fde");
    // or oci7 @TNSNames_Entry, userid, password
    try {
    Statement stmt = conn.createStatement();
    try {
    ResultSet rset = stmt.executeQuery("select * from tab");
    try {
    while (rset.next())
    System.out.println (rset.getString(1)); // Print col 1
    } finally {
    try { rset.close(); } catch (Exception ignore) {}
    } finally {
    try { stmt.close(); } catch (Exception ignore) {}
    } finally {
    try { conn.close(); } catch (Exception ignore) {}
    ================================================

    >
    I am compiling like when LD_LIBRARY_PATH set to $ORACLE_HOME/lib32:$ORACLE_HOME/rdbms/lib32.
    javac -cp .:$ORACLE_HOME/jdbc/lib/ojdbc14.jar dbAccess.java
    as my program resides in current directory. I run it like :
    java -cp .:$ORACLE_HOME/jdbc/lib/ojdbc14.jar dbAccess
    Output: it hangs forever.
    I am compiling like when LD_LIBRARY_PATH set to $ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib
    javac -cp .:$ORACLE_HOME/jdbc/lib/ojdbc14.jar dbAccess.java
    as my program resides in current directory. I run it like :
    java -cp .:$ORACLE_HOME/jdbc/lib/ojdbc14.jar dbAccess
    Output: It gets connected and list all the tables as output.
    >
    The ojdbc14.jar file is for use with Java 1.4 VMs.
    Are you still using Java 1.4? If so, why?
    For Oracle 11g you should be using the latest JDBC jar file (ojdbc6.jar) and the latest version of Java 1.6.
    You are not only using an old JDBC driver and Java version but are also trying to mix 32 bit and 64 bit operations.
    I suggest you start using recommended practices and update your Java and JDBC versions and select EITHER 32 bit or 64 bit operations.
    See the Official JDBC FAQ for the details on the support available for various combinations of Oracle DB, Java and the JDBC drivers:
    http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html

  • Code to generate java program

    hello,
    i am studying msc(information systems) 2 years course.
    this is my first semister.i am doing prof\ject in java.
    TITLE:Designing editor for java in java.
    I want to know how to compile a program written in the editor.i will feel very much happy,if u could tell me the suggestion.And alse running the class file.
    thanking you...

    Take a gander at the java.lang.Runtime class - in particular the exec method. Invoke the compiler like you would on a DOS or Unix command line.
    You'll have to use a ClassLoader to make the JVM load - or reload, if it's already known to the JVM - the resulting class file.

  • Java code to read Java Program

    Hi,
    Is there any standard api to retrieve the java program's class name, method name, its parameter, code etc...
    My req is to write a java program that takes any java programme file as input and returns the class name, method name, parameter name and type etc...
    Thanks,
    Santhosh.

    Take a look at the annotation processor atp in the standard Java toolkit. It provides a framework for scanning Java source files visiting types, fields etc.
    Or you could get hold of javacc, which comes with an example schema for reading Java source.

  • Error compiling Java Program

    I am new to java programming.
    I recently took a java class. In the lab we created a simple program.
    The program was split up in two separate files.
    //Vehicle.java
    public class Vehicle {
         private double load;
         private double maxLoad;
              public Vehicle(double max_Load) {
                   load = 0.0;     
                   maxLoad = max_Load;
              public double getLoad(){
                   return load;
              public double getMaxLoad(){
                   return maxLoad;
              boolean addBox(double weight) {
                   if ((weight + load) > maxLoad)
                        return false;
                   else
                        load=weight+load;     
                        return true;
    }//end of class Vehicle
    on a complete separate file
    public class TestVehicle {
    public static void main(String[] args) {
    // Create a vehicle that can handle 10,000 kilograms weight
    System.out.println("Creating a vehicle with a 10,000kg maximum load.");
    Vehicle vehicle = new Vehicle(10000.0);
    // Add a few boxes
    System.out.println("Add box #1 (500kg) : " + vehicle.addBox(500.0));
    System.out.println("Add box #2 (250kg) : " + vehicle.addBox(250.0));
    System.out.println("Add box #3 (5000kg) : " + vehicle.addBox(5000.0));
    System.out.println("Add box #4 (4000kg) : " + vehicle.addBox(4000.0));
    System.out.println("Add box #5 (300kg) : " + vehicle.addBox(300.0));
    // Print out the final vehicle load
    System.out.println("Vehicle load is " + vehicle.getLoad() + " kg");
    when we complied the program we ONLY compiled TestVechile.java
    ( javac TestVechile.java) and BOTH the class compiled successfully. When I tried to compile the TestVehicle class at home I got an error at line 6 in TestVehicle.java.
    Please any help would be greatly appreciated.
    - Alex

    To compile TestVehicle.java, you need either Vehicle.java or Vehicle.class -- with neither of them, the compiler doesn't know whether "new Vehicle(10000.0)" is legal or not.

  • Problem compiling java programs

    when i run javc in command prompt it runs fine but when i try to compile any program through command prompt it gives following error:
    javac: file not found
    usage: java <options> <source file>
    use -help for list of attributes
    what shouls i do plz help

    yogiis wrote:
    when i run javc in command prompt it runs fine but when i try to compile any program through command prompt it gives following error:
    javac: file not found
    usage: java <options> <source file>
    use -help for list of attributes
    what shouls i do plz helpuse set path="path of java/jdk/bin folder with double quotes" then press enter
    otherwise if you are ussing windows system goto to my computer properties and use advanced tab then use environment variables, there use user/system variables and check is there any exisiting path named variable is there or not if there click on edit and use ; and paste the complete path there. press ok, apply. Then use the command.

  • Compiling java programs

    Hi,
    Does it matter whether you compile your java program (to be run as applets) using jdk 1.5 or 1.4 or 1.3? Am I right to say that as long as it's compiled successfully, it will run from any browser?
    Thanks :)

    No, but the compatibility isn't with the browser but with the "plugin" that the browser uses to run Java.
    Each new major released of Java introduces new features and extensions to the class library which won't be there if the version of the plugin is older than the compiling environment.
    Class files actually contain the release number of the compiler that generated them and the JVM checks that it can handle the release in question.
    In a production environment you don't use applet tags but more complex HTML which specifies the release of the plugin required and directs the user to download the appropriate one if it's not already installed.
    (Annoyingly Windows Internet Explorer doesn't handle this properly if the person running the browser isn't allowed to install software).

Maybe you are looking for