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.

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.

  • 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?

  • 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!

  • 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.

  • 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

  • Run a java program by double-click on desktop file

    hi guys,
    i need ur help!!!!!!! i'm tryin to code a program, where i double click on any file type and my coded java program should start running. my coded program should check for th particular in network,if the particular application is not in harddisk......
    (eg
    double-click on s.pdf file coded java program should start running and search should check for acrobat reader
    in network)
    pls send a sample code asap!!!!!

    Did you started any coding on this or just looking for
    a complete solution from the memebers of JDC??i think you've got it...
    could you please stop posting this message
    http://forums.java.sun.com/thread.jsp?thread=207687&forum=4&message=705223
    http://forums.java.sun.com/thread.jsp?thread=207185&forum=4&message=702579
    http://forums.java.sun.com/thread.jsp?thread=207950&forum=4&message=706537
    plus this one
    and all the old posts about opening files including this one...
    http://forums.java.sun.com/thread.jsp?thread=206532&forum=4&message=699027
    maybe you should try and actually write some code on your own...

  • Error while running a Java Program

    Can anyone help me,
    I am getting the following error while running a Java program, Below is the exception thrown, please help.
    java.nio.BufferOverflowException
    at java.nio.Buffer.nextPutIndex(Buffer.java:425)
    at java.nio.DirectByteBuffer.putChar(DirectByteBuffer.java:463)
    at org.jetel.data.StringDataField.serialize(StringDataField.java:295)
    at org.jetel.data.DataRecord.serialize(DataRecord.java:283)
    at org.jetel.graph.DirectEdge.writeRecord(DirectEdge.java:216)
    at org.jetel.graph.Edge.writeRecord(Edge.java:288)
    at com.tcs.re.component.RESummer1.run(RESummer1.java:505)
    java.nio.BufferOverflowException
    at java.nio.Buffer.nextPutIndex(Buffer.java:425)
    at java.nio.DirectByteBuffer.putChar(DirectByteBuffer.java:463)
    at org.jetel.data.StringDataField.serialize(StringDataField.java:295)
    at org.jetel.data.DataRecord.serialize(DataRecord.java:283)
    at org.jetel.graph.DirectEdge.writeRecord(DirectEdge.java:216)
    at org.jetel.graph.Edge.writeRecord(Edge.java:288)
    at com.tcs.re.component.RECollectCont.run(RECollectCont.java:304)

    Ok, let's see. Write the following class:
    public class Grunt {
      public static void main(String[] args) {
        System.out.println("Hello Mars");
    }Save it as "C:\Grunt.java", compile by typing:
    javac c:\Grunt.javaRun by typing:
    java -classpath "C:\" GruntDoes it say "Hello Mars"? If yes, go back to your program and compare for differences (maybe you used the "package" statement?).
    Regards

  • Running a java program a set number of times

    This is a general question. Is it possible to make a java program run only 5 times for the sake of arguement.
    Basically I want to write a program that will give the user some flexibility when it will actually run another Java program, but I only want them to be able to say "not now' for a set number of times. When the last time comes the other program will launch. I was initially thinking of the Do Whilw loop, but this needs to work when the program is restarted.
    Program starts, it has 5 times it will run before it does something else(doesn't really matter now I think). User takes option "Not Now" and the program ends, but warns the user this will run 4 more times before you will need to do something.
    This process will repeat until the user takes the option "Ok install now" or the time limit expires and the install occurs anyway. Can someone point me in the right direction.

    ok I see so it's like one those programs that you download for free on the internet and they give you a set amount times to use it before you have to pay for it. but in this case when the number of times you use it equals 5 (or when the user clicks ok) a different java app will open automatically.
    My first thought would be to Write a Serialized object to disk using objectOutputStream that stores the number of times the application has been opened. and each time the program runs it checks for the serialized object and then you can do something like what I posted before. of course if were worried about security the user could always look for the object and erase it, if so then I guess we would have to come up with another plan of attack
    Hope this helps

  • Running a java program from an icon

    I want to run my program from an icon on my desktop. I have a .bat file that I've built a shortcut to and it works.MY GUI program does display and run when I click on the icon. The problem is that the DOS window also shows up behind my GUI.
    Is there anyway to prevent the DOS window from showing? Or is there another way to run a Java program without resorting to a DOS command line or running it through FORTE or another IDD?

    Chris's solution worked well, with one small problem. Once my GUI starts, it takes up the whole screen. Normally when I run it, it appears as a small window.
    not a big problem, I can reduce it easily after it starts. But does anyone know a way to make it come up in the reduced size it norally comes up in when I run it from my IDE?

  • Running a java program via a batch file

    I am unable to run a java program from a batch file that I created.
    spiderpackage.EntryPoint is a class file which I am trying to run with a -v option to output something.What should I do to get the output?
    echo ^<html^>^<body^>
    echo hello^<br^>
    call java spiderpackage.EntryPoint -v
    echo ^</body^>^</html^>

    This has nothing to do with java programming. Have a look at the windows help for the call command.
    The echo <html> stuff doesn't make sense. What's it for?
    The command in you batch file should be:
    java -cp . spiderpackage.EntryPoint -v
    assuming that java is in the system path, and the EntryPoint.class is in a directory called spiderpackage which is a subdirectory of your current working directory

  • Running a Java program at startup in Linux

    Hello
    How do I run a Java program at startup in Linux? I know in Windows I can put a .bat file in C:\Windows\Start Menu\Programs\StartUp\ directory, but in Linux I have no idea how it is done.
    Thank you,
    Mihai

    This is really a Linux question, not Java.
    And then it depends on the version of Linux you are using.
    Maybe this will help, otherwise you should try on a forum for your version of Linux.

  • Running a java program over network

    Hi,
    How a java program on a machine can be run without having JRE on the same machine, rather interpreting bytecode over network having JRE on another machine?

    Rahul.Kumar wrote:
    well, so my java program is running on x. Initialy X had JRE and on invoking java program from command prompt, it had looked for JRE at path, set in environmental settings. Now I moved JRE to another machine Y and connected these two machines (X and Y). You have two machines X and Y.
    "Connected" or not has nothing to do with this discussion.
    In X path is set to the JRE on Y. The path on X has absolutely nothing to do with anything on Y.
    Now execute java program on X, theoretically it should work or what is wrong with this?This makes no sense. Presuming you meant Y in the above then the following must be true.
    1. You must have a JRE on Y.
    2. You must have a java application on Y (or one accessible via the file system on Y.)
    3. You must be on Y and start the JRE passing the java application that is on Y to it.
    Notice in the above there is no mention of X. There can be no mention of X.

  • Exception while Running a Java Program for UME.

    Hi Experts,
                           I am trying to run a java program to acess UME. Its a sample to create user but all of my samples are throwing this exception in NWDS  (Console).Can anyone tell me why is it throwing this exception .
    com.sap.security.api.UMRuntimeException: UME factory 'com.sap.security.api.IUserFactory' cannot be accessed because UME initialization has not started yet.
    Please check
            UMFactory.isInitialized() before using UME functionality.
        at com.sap.security.api.UMFactory.checkInitialized(UMFactory.java:1019)
        at com.sap.security.api.UMFactory.getUserFactory(UMFactory.java:801)
        at Search.main(Search.java:25)
    Exception in thread "main"
    Thanks in advance
    Somil

    Hi,
    Earlier i faced the same exception when i tried to call the UME form Standalone java application,To resolve this i used stateless session bean approach. i follow the Below Mentioned Steps,
    1:-- create an J2EE -- EJB module project.
    2:-- Create stateless session bean and define the require methods ,implement Local and remote interface methods  in your bean class.
    3:-- refer the UME apis in EJB Projects build path.
    4:-- Call UME in Bean class methods.Build the EJB project and Archive.
    5:--Now create an Enterprise application Project ,Include the EJB module project to your EA Project by right clicking on EA project.Build EA project and EAR file
    6:--Deploy the EAR file on your server.
    7:--Now from your standalone java application include these two projects in Project tab of your Application.
    8:--Lookup the stateless session bean in your java class by its default JNDI name ,Obtain remote or local Home interface,And execute the BEAN Method which deals with UME.
    You can also refer this tutorial in some parts of it UME apis(like IUser,UMFactory) are used in Servelets and EJB ,You can download this tutorial source from SDN for your reference.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/297f35cf-0201-0010-00b2-fe2f3e23d360
    Siddharth

Maybe you are looking for

  • Mail not opening, "Home directory is full" ???

    I am unable to open my mail application. I'm getting the following error message: "Mail cannot update your mailboxes because your home directory is full. You must free up space in your home folder before using Mail. Delete unneeded documents or move

  • HP Mini 110 MI Skype microphone problems

    I have a new mini running Ubuntu.I can't get the microphone to work with the installed version of Skype. I found  earlier posts that indicated a OP system problem, but that was in 2008. Any updates?

  • Installing X fi Extreme Music On To Windows 7 64 Bit?

    I wan't to install my old extreme music card,but now that I have windows 7 64 Bit do I start from the original disk(XP) I think or just use the updatted drivers for windows 7?I wan't most of the original software.... Thanks

  • Iphone not turning off

    this is my second iPhone 4s I have had the same problem with. I try to switch it off, it goes into closedown (spinning wheel), then the black screen then it restarts unprompted. As my first phone was under 12 month warranty Vodafone replaced it free

  • AICS3 Import of FHMXa Files

    Does AICS3 do a better job of importing FHMXa files? Specifically gradients and transparent lens fills.