Can I write and run simple java programs in Xcode

I need to write and run basic java programs on my mac. I would like to run it in Xcode, but I don't know how to set it up? Is there a way?

Read the following discussion from last month on here:
Can Xcode 4.5.1 compile/run java?

Similar Messages

  • How to compile and run a java program?

    I am getting this error message, what to do?
    Exception in thread "main" java.lang.NoClassDefFoundError:
    Thanks for you help.
    Ajay

    Hello,
    I believe that this error is caused because when you
    compile and run a java program, you have to use the
    same name that is next to public class. For example,
    the program name is next to the word public class.
    For example, if a program began like this:
    public class Concat
    then the name of the program in this case is Concat
    and when you compile it you type: javac Concat.java
    when you run it type: java Concat
    depending on the name of your program.and depending on whether the class is in a package. And depending on what directory you are currently in.
    Also depending on if you set your class path you might
    have to type the above like this: jdk1.2.1\bin\javac
    Concat.java to compile, and to run you would have to
    type jdk1.2.1\bin\java Concat where you would replace
    Concat with the name of your program and replace
    jdk1.2.1 with the name of your version of java, that
    is again if you do not have your classpath set. Hope
    this helps.Your examples have nothing to do with whether the CLASSPATH is set--only with whether the PATH is set. And, it may not be jdkXXX\bin. The path to the JDK (in this case, to javac and java executables) could be anything. Classpath should be set on the command line. The OP probably did NOT set a classpath on the command line (preferred), or in the environment variables.
    Also, make sure you did not forget to put:
    public static void main(String[ ] args)
    on the line underneath the line where it says "public
    class Concat" where Concat is the name of your
    program. Again, I hope this helps.Irrelevant (with the info we have from the OP so far). The error says that the JVM can't even find the class--not that the class doesn't have a main. The "main" referred to in the error message is within the JVM itself.
    OP: Did you fix your problem? If not, what directory are your files in? Are they in a package? What command are you typing to get that error? That is, please tell us your entire command line.

  • Stop and run a java program

    how can I stop then run a java program in java code?

    netcom_ wrote:
    You can do this from the command shell.I want to stop running the program by System.exit()Which will return a status code to the shell that launched your java app.
    then I would run the program lets say by command shell(in java),Huh?
    After your java app calls System.exit() you are back in the shell that launched the java app.
    The problem that all the code after the instruction
    System.exit is ignored so the command shell is not treated ,is there a solution,?You can use a shell script and use a loop.

  • How can I install and run a Windows program on my MacBook Pro/?

    How can I install and run a Windows program on my MacBook Pro?

    You have several options.
    1, Use a Virtual Machine like Vmware, Parallels etc... to Create a Virtual Windows Installation and Run your program in there.  A Virtual MAchine will runn in a Window on your Desktop and share your Mac's resources RAM HD space processor. Your MAc desktop will still be available while you run Windows install.
    http://www.parallels.com/
    2. Install Windows on a partition using Bootcamp. It will run a full installation of Windows you can boot into, and run your programs.  The Mac desktop will not available until your reboot the computer and start in OSx instead of Windows.
    https://www.apple.com/support/bootcamp/
    3. Use Wine /  Winebottler to run the Application without the need for a complete Windows installation.
    http://winebottler.kronenberg.org/

  • How can I compile and run other java classes from within an application?

    Hello there everyone! I really hope that someone can help me. I am writing a program that must be able to compile and run other java classes that are in different files, much like development environments like Kawa or Forte allow you to do.
    There has to be a way of doing this ( I hope!! ), but i can't seem to find it!!
    I have tried using this command to compile:
    Runtime.getRuntime().exec ("c:\\programs\\javac className.java");
    ...and this one to run:
    Runtime.getRuntime().exec ("c:\\programs\\java className");
    ...but neither works!!! I can compile and run classes that are in the same file as my application, but I can't get it to work at all for files in different directories or files.
    PLEASE, PLEASE, PLEASE help me - i've run out of ideas, and i need this to be working in 3 days!!!
    Thank you very much for any help anyone can give me, I really appreciate it!! Thanks again!!
    Adrian ( ...in distress!! )

    public class JavaCompiler{
       public static void main(String[] args)throws Exception{ //sorry bout the laziness
          if(args == null || args.length != 1){
             System.out.println("Usage: java JavaCompiler MyClass.java");
             System.exit(0);
          String className = args[0];
          Runtime rt = Runtime.getRuntime();
          Process p = rt.exec("javac " + className); //consider setting cpath for this
          p.waitFor();
          //now try to run after it is done.
          p = rt.exec("java " + className.substring(0, (className.length() - ".java".length()));
          p.waitFor();
          //do some other stuff
    }This should get you going. You may consider looking into the System.getProperty() method in order to determine the type of OS it is running on in order to findo out what command to run. I know that the sun tool listed above is nice, but by my understanding the sun tools provided are not guaranteed to stay the same. I'm no expert on this matter, but that is one of the reasons there is no API documentation for those tools. Also, I don't believe those tools come packaged with the JRE. (Of course if you are making an IDE it will be expected that the user has an sdk installed. Good luck with figuring this thing out.

  • How can I install and run the Java Telephony API

    Hello!
    I have downloaded the Java Telephony API but I couldn't find the installation notes for installing it on my PC (Win2000).
    Can anyone help me?

    Since the package is downloaded as just .class files just set your classpath like you normally would if you were creating your own package...I personally would install the class file version...run a sample program and see if this works...

  • Open and run saved java program

    using eclipse 4.5.0
    I am rank newbie to programming; so my question may seem trivial. Google has not provided me with a solution that I can successfully follow.
    Because I am using various sources to learn Java, I have created custom folders within the Workspace folder to make the projects easier for me to find. I have successfully created the "hello world" program. It is saved to C:/users/<myname>/workspace/my dummies practice folder. I don't know if this is part of the problem; therefore I am including this detail.
    I have loaded the program into the IDE to run it again. When I right click in the editor and choose run as, ant build displays, without an option to run as Java application.
    What have I done wrong, or what can I do to correct this?
    Thanks for your replies.

    On 07/29/2015 12:26 PM, Will Klem wrote:
    > I solved my own problem. Moving the program files to the default
    > Workspace folder yields the desired results. Being new at this, I did
    > not realize (or even think) that the saved programs must be in the same
    > parent directory as the Eclipse folder. Will I find that this is common
    > to all IDEs?
    >
    > Thanks for taking the time to read my post anyway.
    No, there must have been something wrong with your original workspace.
    You would do well to follow vogella.de's tutorial on Eclipse to orient
    yourself to workspaces, projects, etc.
    Best of luck.

  • Problem with execution and running a Java program

    Good evening,
    I have downloaded the jdk-1_5_0_05-windows-i586-p.exe and installed it on my PC.A folder Java has been created.Now,I need an editor in order to type the program,execute it and run it.I have a shell named Cygwin which includes the nano editor.I copied the folder Java into the cygwin folder C:\cygwin\home\user\Java.
    I open the shell.Do the following steps:
    user@owner ~
    $ cd Java
    user@owner ~/Java
    $ ls
    jdk1.5.0_05 jre1.5.0_04
    user@owner ~/Java
    $ cd jdk1.5.0_05/
    user@owner ~/Java/jdk1.5.0_05
    $ ls
    COPYRIGHT LICENSE.rtf bin jre src.zip
    HelloWorldApp.java README.html demo lib
    LICENSE THIRDPARTYLICENSEREADME.txt include sample
    user@owner ~/Java/jdk1.5.0_05
    $ javac HelloWorldApp.java
    bash: javac: command not found
    user@owner ~/Java/jdk1.5.0_05
    $ java HelloWorldApp
    Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
    What am I supposed to do in order to execute the program?
    Thanks in advance!

    Well,following your advice I did :
    user@owner ~/Java/jdk1.5.0_05
    $ ./java <arguments>
    bash: syntax error near unexpected token `newline'
    Then(without < >):
    user@owner ~/Java/jdk1.5.0_05
    $ ./java arguments
    bash: ./java: No such file or directory
    user@owner ~
    $ ./java javac
    Exception in thread "main" java.lang.NoClassDefFoundError: javac
    user@owner ~
    $ ./java java
    Exception in thread "main" java.lang.NoClassDefFoundError: java
    Then :
    user@owner ~/Java/jdk1.5.0_05
    $ echo "PATH=$PATH:~/jdk1.5.0_05/bin" >> $HOME/.bashrc
    It accepted it.
    Then:
    user@owner ~/Java/jdk1.5.0_05
    $ javac HelloWorldApp.java
    bash: javac: command not found
    user@owner ~/Java/jdk1.5.0_05
    $ java HelloWorldApp
    Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
    Unfortunately the same result.
    Could you please tell me what else I have to do in order to compile it and run it?
    Thanks a lot!

  • Run simple java program error

    Hi:
    I followed the step by step at "Your First Cup of Java (for Microsoft Windows)" at
    http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html#
    all the steps work, esecpt for the run program part, I get Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp. but the HelloWorldApp clases is there. and I set my path and classes path at xp enviroment
    classes %CATALINA_HOME%\common\lib\servlet.jar;c:\jdom-b8\build\jdom.jar;c:\jdom-b8\lib\xerces.jar; Library.java;c:\hsqldb\lib\hsqldb.jar
    %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM;c:\jdk1.4.0_02\bin; %path%
    hope you can help !
    Thank you

    The problem with running the HelloWorldApp is because you have set the classpath.
    It looks like Tomcat and others are installed on your system. Trying to run before you can walk, eh!
    This is your system CLASSPATH and points to directories that contain classes and/or *.jar files that contain classes:
    .;%CATALINA_HOME%\common\lib\servlet.jar;c:\jdom-b8\build\jdom.jar;c:\jdom-b8\lib\xerces.jar;c:\hsqldb\lib\hsqldb.jar
    I don't know why Libary.java is there in your original post because it is a source file and not a class yet; and you don't point directly at a class, only the folder or JAR it is in.
    This is your system PATH and points to directories that contain programs:
    %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM;c:\jdk1.4.0_02\bin;
    With XP the environment is split into two parts:
    1/ the system environment variables and will prepend to:
    2/ your user environment variables may have the same name and will append to variables in 1/. So there is no need for the %path% bit.
    Make sure that CATALINA_HOME is set to the base folder of the CATALINA(TOMCAT) installation, if you are planning to use it.
    You shouldn't need to set PATH or CLASSPATH for your user ID unless you only want that user id to have access.
    My advice (if it is your machine) is to uninstall Apache/Tomcat and anything else (such as JDOM) that isn't basic Java until you have learned the language. Then delete the CLASSPATH variable and remove the \system32\WBEM; part of the the PATH variable.
    Regards,
    Hugh.

  • How to compile and run PRO*C programs in Linux

    Hi all,
    This is my first post in this forum.
    I have Oracle 9i installed in linux platform .
    How can i compile and run Pro*C programs in linux.(i mean any commands or procedure to run these programs)
    please help me in this regard.
    Thanks in advance,
    Trinath Somanchi,
    Hyderabad .

    (1) How to compile the Pro*c program U got to have a makefile to compile a Pro*c program. It helps u in compiling and creating an excutable. Once U have created a makefile , just call "make" and it will do the compilation and create the executable as well.
    For a sample makefile visit
    http://asktom.oracle.com/~tkyte/proc_makefile/
    (2) How to run the Pro*c program ? and Once U have created an executable, U shall call that directly as any other linux command. Make sure U have the permissions to run the executable. If not give the permissions using chmod 777 executable
    (3)How to get the output of the program ?Question 2 and 3 are the same. I mean running and getting a output are the same

  • A simple Java program to be compiled with ojc and executed with java.exe

    Hi ,
    This thread is relevant to Oracle Java Compiler (file ojc) and jave.exe file.
    I have written a simple java program which consists of two simple simple classes and using the JDev's 10.1.3.2 ojc and java files , i'm trying to execute it after the successful compilation....
    The problem is that trying to run it... the error :
    Exception in thread "main" java.lang.NoClassDefFoundError: EmployeeTest
    appears.
    How can i solve this problem...????
    The program is as follows:
    import java.util.*;
    import corejava.*;
    public class EmployeeTest
    {  public static void main(String[] args)
       {  Employee[] staff = new Employee[3];
          staff[0] = new Employee("Harry Hacker", 35000,
             new Day(1989,10,1));
          staff[1] = new Employee("Carl Cracker", 75000,
             new Day(1987,12,15));
          staff[2] = new Employee("Tony Tester", 38000,
             new Day(1990,3,15));
          int i;
          for (i = 0; i < 3; i++) staff.raiseSalary(5);
    for (i = 0; i < 3; i++) staff[i].print();
    class Employee
    {  public Employee(String n, double s, Day d)
    {  name = n;
    salary = s;
    hireDay = d;
    public void print()
    {  System.out.println(name + "...." + salary + "...."
    + hireYear());
    public void raiseSalary(double byPercent)
    {  salary *= 1 + byPercent / 100;
    public int hireYear()
    {  return hireDay.getYear();
    private String name;
    private double salary;
    private Day hireDay;
    For compilation... i use :
    D:\ORACLE_UNZIPPED\JDeveloper_10.1.3.2\jdev\bin\ojc -classpath D:\E-Book\Java\Sun_Java_Book_I\Corejava EmployeeTest.java
    For execution , i issue the command:
    D:\ORACLE_UNZIPPED\JDeveloper_10.1.3.2\jdk\bin\java EmployeeTest
    NOTE:I tried to use the jdk of Oracle database v.2 but the error :
    Unable to initialize JVM appeared....
    Thanks , a lot
    Simon

    Hi,
    Thanks god....
    I found a solution without using Jdev.....
    C:\oracle_files\Java\Examples>SET CLASSPATH=.;D:\E-Book\Java\Sun_Java_Book_I\Corejava
    C:\oracle_files\Java\Examples>D:\ORACLE_UNZIPPED\JDeveloper_10.1.3.2\jdk\bin\javac EmployeeTest.java
    C:\oracle_files\Java\Examples>D:\ORACLE_UNZIPPED\JDeveloper_10.1.3.2\jdk\bin\java EmployeeTest
    What does Ant has to do with this?Sorry, under the Ant tree a classpath label is found....I'm very new to Java and JDev...
    You need to include the jar file that has the Day method in it inside project properties->libraries.I have not .jar file.. just some .java files under the corejava directory.... By the way , I have inserted the corejava directory to the project pressing the button Add Jar/Directory.... , but the problem insists..
    Thanks , a lot
    Simon

  • I start running a java program and when i switch users the sound doesnt work

    When I start running a java program or leave a game running and i switch users the sound doesnt work. I have been searching around the web and nobody seems to have an answer. This just recently started to happen. Please if anyone has any ideas that would be much appreciated and the problem is my computer its almost brand new. And my computer is completely up to date.

    Sony Mobile team has a separate community which can be found here.
    If my post answers your question, please click on "Accept as Solution"

  • How to compile and run a .java file from another java program

    hello,
    can any one tell me how to compile and run a *.java* file from another java program which is not in same directory?

    Well a smarter way of implementing this is by using a solution provided by Java Itself.
    If you are using J2SE 6.0+ there is an in built solution provided along with JDK itself and inorder to go ahead with solution the below are set of API which you;d be using it for compiling Java Programs (Files)
    http://java.sun.com/javase/6/docs/api/javax/tools/package-summary.html
    How do i do that ??
    Check out the below articles which would help you of how to do that
    http://www.ibm.com/developerworks/java/library/j-jcomp/index.html
    http://www.javabeat.net/javabeat/java6/articles/java_6_0_compiler_api_1.php
    http://books.google.com/books?id=WVbpv8SQpkEC&pg=PA155&lpg=PA155&dq=%22javax+tools%22+compiling+java+file&source=web&ots=XOt0siYe-f&sig=HH27ovuwvJgklIf8omTykUmy-eM
    Now once we are done with compilation.In order to run a Specific class all you ought to do is create an object and its specific methods of a specified class included in the CLASSPATH which you can manage it easily by usage little bit reflections.
    Hope that might help :)
    REGARDS,
    RaHuL

  • How can i run my java program with out java language

    Hai to every one ..Iam new to java language ...am using windows xp operating system , i did not installed java language in my system .. how can i run a java program with out installing java language... Which files is requied to run java program..?
    any one can help me??

    Hai to every one ..Iam new to java language ...am
    using windows xp operating system , i did not
    installed java language in my system .. how can i run
    a java program with out installing java language...
    you ... can ... not ... do ... this
    Which files is requied to run java program..?
    any one can help me??a JVM. Download it from sun's website.
    [url http://java.sun.com/javase/downloads/index.jsp]Download JavaSE here

  • How can i run my java program in background process?

    hi all,
    i am working on desktop monitoring so when i start my program on client machine that is visible to all but i want this program client not visible to all instead of this can be run in background process . so, nobody can see that.
    so, how i can do this ?
    pls pls help me
    thanks in advanced to helper
    regards
    maulik & ritesh

    this will run the java program in the background.It'll just use the Windows Java Console instead of the command-line console. It has nothing to do with running as a background process.
    Edit: though this might be exactly what the OP wants: not "background process" but "no DOS console".

Maybe you are looking for