Exit in java

Hey
I was hoping someone could help me out. i need to write some code so that i give someone the option to either exit the program or rerun the program.
I am only new to java and am having difficulty setting this up.
thanks.

Skydev2u wrote:
In Java there is a built in method that when called will end the program. Its System.exit(n); where n is a int. It is generally preferred not to use this method unless the program needs to end with an error-code.
while (something == true) {Just a slight nitpick, but if I were coding this statement, it would be:
while (something) {the == true is redundant and somewhat ugly.

Similar Messages

  • CRM - Pricing User Exit in Java - BADI CRM_COND_COM_BADI

    Hi All
    I have to convert some user-exit from Abap to Java in order to work in CRM Pricing Scenario (I use VMC technology based on Web AS 7.00).
    In the manual attached to note 809820 (New userexit concept for pricing)
    I find this chapter but I don't understand how to work with BADI <b>CRM_COND_COM_BADI.</b>
    <b>My objective is to create Java user-exit using Custom Tables and Fileds.</b>
    <b>Passing additional information to pricing</b>
    To summarize, if the information used in a requirement is not depending on the current calculation result, then the information can be passed to the pricing engine. This is the best way to avoid e.g. DB or JCo calls from the user exits.
    Nearly all application scenarios using the pricing engine provide a way of filling additional attributes.
    1. Create a field catalogue entry for the additional attribute
    2. Program the filling of that attribute value
    The application calling the pricing engine and the way it is allowing customer code to fill or influence attributes is not part of this document. Here is only a short list of documentation to start with (also various notes exist):
    Application Description
    CRM Online Order Processing
    Implement BADI CRM_COND_COM_BADI. Note 850077
    Mobile Solutions Implement VBA user exit methods on SPCDOCHANDLER or SPCITEMHANDLER.Note 677314 and Note 934216
    Best regards
    Davide Ivanov
    [email protected]

    Hi davide,
    The BADI CRM_COND_COM_BADI is used for filling the pricing communication structure.
    If you have added any field at header level of the field catelog that will available in the changing parameter of the method HEADER_COMMUNICATION_STRUCTURE.
    If you have added any field at item level of the field catelog that will available in the changing parameter of the method ITEM_COMMUNICATION_STRUCTURE.
    Additional fields added at catelog can be filled with the values using this BADI.
    Thanks & Regards,
    Raghuram. K.R.

  • Denying system.exit in java code

    My objective is to nullifying the system.exit programmed. By goggling i learn t that this can be done by adding permission in policy file. But as far my google search i dont understand how to deny a permission. Most of them says about granting a permission. Can anyone clarify how to deny a permission.
    Steps i tried.
    Sample program: which does nothing other than calling system.exit(0) as the first line in main method.
    added the following line to java.policy file in my JAVA_HOME/jre/lib/security
    grant {
              permission java.lang.RuntimePermission "exitVM";
    Also tried adding only
    permission java.lang.RuntimePermission "exitVM";
    to the already available grant block.
    Also commented out
    //grant codeBase "file:${java.home}/lib/ext/*" {
    //     permission java.security.AllPermission;
    After that i understood that the default java policy file is java.home\lib\security\java.policy. So made all the change above mentioned there too.
    But i could not achieve it. Can any one help me on this.
    Win 2000/ Java1.4.2_12/no command line arguments while running the program.

    Welcome to the Forums.
    Please go through the FAQ of the Forum.
    You has posted your query in the wrong Forum, this one is dedicated to Oracle Forms.
    Please try {forum:id=1050}.
    Regards,

  • System Exit from JAVA Application

    I need to call Oracle Reports from a JAVA application.
    Does anyone have experience in this area?
    One thing that comes to mind is to make a system exit and call the reports from the command line. Is this possible to be done? How?
    Thank you for any help or suggestions.
    Tina.

    the best way to access the oracle database is via jdbc (see http://java.sun.com/products/jdbc/ ). if, however, you specifically need to run some oracle reporting s/w then you could run it as a separate process from your java application using Runtime.exec() (see http://java.sun.com/j2se/1.3/docs/api/java/lang/Runtime.html#exec(java.lang.String) ) which returns a Process object. you can then read its output with the Process object's getInputStream() method (this gives you an InputStream which is the data piped from the standard output stream of the process).
    hth,
    jonesy (sun developer technical support)

  • How do I exit a java program based on condition can i use system.exit

    I have java program that is called by another program that I dont have control on. My program returns a bigdecimal... but if the ordernumber is empty in my program i dont wnat to do anything.. does system.exit work in that condition... i put it int he else if ordernumber is empty condition.. but i dont think that is the right approach..

    When software module is expected to bring some result, it should bring the result, positive or negative. I think you should check what your counterpart software expects as positive or negative result. And then implement your software this way. You can use System.exit, but this call is employed usually to indicate status with the software after it's completion and not to return any resulting value.
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#exit(int)

  • Windows crashes upon Java exit.

    Firstly, I apologise that I know very little about Java and if I've omitted any important information here I may need precise instructions on how to find it out.
    According to the Add/Remove Programs menu, I have 'JS2E Runtime Environment 5.0 Update 6', version '1.5.0.60' installed.
    My problem is that, in any of the following situations, Windows crashes and I either get a BSOD reporting a 'stop error', or my computer reboots itself:
    1) I exit the Java Control Panel, attempt to clear temporary files using the Java Control Panel, or exit certain settings windows/message boxes from the Java control panel (Always occurs)
    2) I exit Limewire (which I assume has some embedded Java applet) (Always occurs)
    3) I exit a Java executable (.jar file) (Always occurs)
    4) I exit Internet Explorer or Firefox (sometimes occurs. I think it's safe to assume this is when I've visited a site with a Java applet, but I haven't tested this)
    5) I end the javaw.exe process from Windows Task Manager (always occurs)
    6) I attempt to uninstall Runtime Environment 5.0 Update 6 from the Add/Remove Programs menu (always occurs. The crash happens a good while into the uninstallation, however)
    Is this a known issue? What is the cause/possible cause? How can it be resolved, given that I can't uninstall Java?

    This is a long shot, but anti-aliasing and/or video driver problems seem to cause most of the crashes. So try the following and respond back whether it worked or not.
    Make sure you have anti-aliasing set to Application-Controlled: http://www.java.com/en/download/help/5000041100.xml
    Make sure you've updated to the latest video drivers.
    Make sure Directx is updated to the latest version.
    If that still doesn't work read http://forum.java.sun.com/thread.jspa?threadID=661574 and then try adding to your environment JAVAOPTIONS variable -Dsun.java2d.d3d=false. If that doesn't work try -Dsun.java2d.noddraw=true
    If the problem was AA, then and you still want to force all 3d applications to use AA and you don't want to keep changing your graphics card display options, you can disable java's use of the Direct3D by setting an environment variable JAVAOPTIONS to -Dsun.java2d.d3d=false. This will allow you to keep your AA settings. Disabling Direct3D is the proposed update to 1.5 (Update 8) to fix this bug. See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6311320

  • Proper way to exit with a j2ee java app running in the NW70 j2ee engine

    Hello,
    I am working on migrating an app and it's ear from j2ee 6.20 to 7.0. It deploys okay, but when invoked, the j2ee server restarts. Looking at the part that fails, its trying to create a jco connection, which fails and then it catches the failure and does a stack dump and a System.exit(1). It shuts down and restarts at that point. Is System.exit(1) the proper way to exit a java app that is running within the j2ee engine? If it is, is it possible I am picking up the wrong System.exit and need to use an SAP specific one? I inherited the code, but not the IDE it was written with.
    Thanks,
    Paul D. Chamberlain

    Hi,
    Answered my own question. System.exit(1) should not be used. Return works.
    Paul D. Chamberlain

  • Java If/Then/Else Statement

    Hello,
    Just wondering if it is possible to call one java file from within another.
    I'm thining wiht an if.then/else statement similar to
    If x==true
    then run file1.java
    else run file2.java
    any examples of this, or if it is even possible would be appreciated.

    This is something like what I would do.
    public class FileRunner {
        public static void main(String [] args) {
            if ( args[0].equals("file1") {
                File1 file1 = new File1();
                file1.init() //method you define in File1 that runs everything that would've been in the File1's main method
            } else if (args[0].equals("file2") {
                File2 file2 = new File2();
                file2.init() //method you define in file2 that runs everything that would've been in the File2's main method
            } else {
                System.err.println("Invalid argument");
                System.exit(1);
    java.exe FileRunner.class file1
    java.exe FileRunner.class file2The other method is to start a new jvm from within java, but that gives you less control than this imo.

  • How to call a .bat file from java code?

    How to call a .bat file from java code? and how can i pass parameters to that .bat file?
    Thanks in advance

    thanks for ur reply
    but still i am getting the same error.
    I am trying to run a .bat file of together tool, my code looks like below
    import java.lang.Runtime;
    import java.lang.Process;
    import java.io.File;
    class SysCall{
         public static void main(String args[]){
              String cmd="D://Borland//Together6.2//bin//Together.bat -script:com.togethersoft.modules.qa.QA -metrics out:D://MySamples//Metrics// -fmt:html D://Borland//Together6.2//samples//java//CashSales//CashSales.tpr";
              //String path="D://Borland//Together6.2//bin//Together.bat ";
              Runtime r= Runtime.getRuntime(); //Declare the system call
              try{
                   System.out.println("Before batch is called");
                   Process p=r.exec(cmd);
                   System.out.println(" Exit value =" + p.exitValue());
                   System.out.println("After batch is called");
              /*can produce errors which must be caught*/
              catch(Exception e) {
                   e.printStackTrace();
                   System.out.println (e.toString());
    I am getting the below exception
    Before batch is called
    java.lang.IllegalThreadStateException: process has not exited
    at java.lang.Win32Process.exitValue(Native Method)
    at SysCall.main(SysCall.java:17)
    java.lang.IllegalThreadStateException: process has not exited

  • How to sign a .jar file in java 6?

    I know how to do it in java 5. One I have generated myKeystore I do this:
    keytool -selfcert -alias mySelf -keystore myKeyStore
    but, selfcert parameter doesn't exit in java 6, What i have to do?.
    Thanks, everybody.

    According to http://java.sun.com/javase/6/docs/technotes/tools/windows/keytool.html the -selfcert option does still exist, it's just no longer documented.

  • How to catch error codes returned from java

    Hi all,
    Is there anyway to capture the exit code that is returned by System.exit() from java. I know a batch file's ERRORLEVEL can do this. However, I want to use c/cpp (JNI) to get this functionality. Please help ..
    Thanks in advance,
    Soujanya.R

    how could you expect me to use JAVA command without compiling it with Javac??
    I complied the java code using javac and then called(executed ) it using the Java..
    I am using JNI_Create/JavaVM() to create a JVM from CPP file. that works fine. Now, my issue is that I want to capture a couple of exit codes that are returned from the System.exit() of the java code.
    now, guys.. is there any way to capture that exit codes returning by Ssytem.exit() in or using JNI ??
    if yes, please help me with the code snippets.
    Thanks,
    Soujanya.R

  • ABAP code in to JAVA for overwritting condition value for IPC pricing

    Dear experts i am an IPC JAVA developer and i am trying to translate an ABAP Routine in to JAVA code for overwriting condition value in the pricing user exit of IPC
    Here is the ABAPcode segment i am trying to transulate
      DATA: l_kdkg1  LIKE komk-kdkg1,
            l_work TYPE f,
            l_umren LIKE marm-umren,
            l_umrez LIKE marm-umrez.
      SELECT SINGLE peinh FROM mbew INTO mbew-peinh         
      WHERE matnr = komp-matnr
      AND bwkey = komp-werks.
      I need some  help in the following things
      1. I don't know how to transulate the following Line of ABAP code into JAVA
         " AND bwkey = komp-werks."
    Bwkey stands for plant details. I don't know how to get plant details from  Pricing Item.
      2. Someone please tell me weather the following JAVA transulation is correct
      Vector x = prItem.getUserExitConditions();
      db database = pricingEngine.getDatabase();
         // set table name
      String tableStart = "mbew";                                             
         // set query parameters
      sys_query_pair[] queryPair = null;
      //matnr = komp-matnr . Getting the material Number
      String materialNo= prItem.getProduct().toString();
      //bwkey = komp-werks.Getting plant.
      // TODO: werks stands for plant. Not sure how to get it from prItem
       String plant = "";
       queryPair = new sys_query_pair[2];                    
       queryPair[0] = new sys_query_pair("matnr", materialNo);
       queryPair[1] = new sys_query_pair("bwkey", plant);
      // set query columns
       String ZZFIELDStart = "peinh";
       String ZZFIELD_VALUEStart;                   
       String[] projectionStart;
       projectionStart = new String[];
       BigDecimal pricingUnit = null;
       try{     
          // execute query
          res resultSetStart = database.db_read_table(tableStart, queryPair,projectionStart) ;
          if (!res.db_empty_results_p(resultSetStart))
         ZZFIELD_VALUEStart = resultSetStart.db_get_row_element_string(0);
         pricingUnit = new BigDecimal(ZZFIELD_VALUEStart);
         resultSetStart.db_finish();
       else
         System.out.println("Coudn't find a value of field peinh in table mbew!");
       catch (exc_database_error e)
         e.printStackTrace();

    Please login to the server where IPC is installed. In the IPC folder u find libs folder  or search for docs in IPC folder. There it is dealt how ABAP routines are mapped to  user exits in java coding
    Thanks
    Surya

  • How to assure tht javaw.exe exits from taskbar on application exit

    Hi all,
    My java application acquires a license when it runs.
    The problem arises when the application terminates abnormally,sometimes its javaw.exe doesnt stop.This doesnt lead to the release of license by tht application.
    How can i assure tht the javaw.exe file has stopped?
    Thanks & Regards
    Mansi

    MansiSachar wrote:
    Hi all,
    My java application acquires a license when it runs.
    The problem arises when the application terminates abnormally,sometimes its javaw.exe doesnt stop.This doesnt lead to the release of license by tht application.At worst that is nonsensical at best you left out information.
    If the application terminated, regardless of how, then it cannot still be running.
    A thread in java, such as the main thread, might exit, fall out of main(), via several methods. That however doesn't mean that the application has terminated. The java app will only terminate when all non-daemon threads have exited.
    "Abnormal" is less than informative. If an OS system exception occurs then the app will be terminated (see above) by the OS. Nothing in java can prevent that.
    If a java exception occurs and the main thread is exited then the app might or might not be terminated (see above.)
    Best I can suppose is that your main() is exiting but there are still non-daemon threads running. So you must find them and stop them. A common source of that problem is incorrectly exiting a java GUI. Because the java GUI creates a thread which must be stopped. That might or might not be relevant to what you are doing. There are other sources of non-terminated threads including of course the ones that you explicitly created but which might also exist via other third party libraries that you might be using. The same applies for those however, you must terminate them for the application to exit.

  • Java static variables in Stored Java

    I'm wondering if someone in Oracle could relate their thinking with regards to static variables in stored java and why were these implemented as they were. The aspect I'm referring to specifically is how these are basically working as PLSQL package variables, i.e. with state maintained for the life of the session.
    Outside the database, in the "normal" Java world, statics will only live as long as the program is running. But in the Oracle DB world, the static continues to live as long as the session. With this in mind, doesn't this difference compromise the idea of just inserting working Java code into the Database? i.e. static variables now have to be initialized every time a method is called, and cannot be assumed to have default values. Does that not seem like a rather large departure from what a non-DB java programmer would be doing?
    Thanks in advance for your thoughts on this.
    Joe Tseng

    It should generally be the case that all calls in a session see the same static variable values. Some actions will terminate the java session (and lose the static variable state) without ending the RDBMS session, such as calling System.exit from java, but normally this can't happen within a single RDBMS call. Perhaps if you give more details on how you are making the call from java to PLSQL one could say more. In particular, if the call happens to be via the JDBC thin driver then the session running in the JDBC connection will be distinct from the calling session.

  • Simple Question: Why does this code not exit properly?

    This code is pretty simple. All I want to do is load and play a sound file in an application, but this code to load the sound file does not exit properly. I know that some resources must be allocated which I need to deallocate in order to shut down the process, but I don't know what to call to do a proper shut-down. Any help would be appreciated.
    -adam
    import java.applet.Applet;
    import java.applet.AudioClip;
    import java.net.MalformedURLException;
    import java.net.URL;
    public class PlaySoundTest extends java.applet.Applet
    public static void main( java.lang.String[ ] aryArgs )
    java.net.URL urlSound = null;
    try
    urlSound = new java.net.URL( "file:/" + aryArgs[ 0 ] );
    catch( java.net.MalformedURLException murle )
    murle.printStackTrace( );
    System.exit( 1 );
    java.applet.AudioClip acSound = java.applet.Applet.newAudioClip( urlSound );

    HI , If u'r still looking for the solution, this code is working on my system -
    import java.applet.Applet;
    import java.applet.AudioClip;
    import java.net.MalformedURLException;
    import java.net.URL;
    public class PlaySoundTest extends java.applet.Applet
    public static void main( java.lang.String[ ] aryArgs ){
    java.net.URL urlSound = null;
    try{  //rahul
    try
    urlSound = new java.net.URL( "file:" + aryArgs[ 0 ] );
    catch( java.net.MalformedURLException murle )
    murle.printStackTrace( );
    System.exit( 1 );
    urlSound = new java.net.URL( "file:" + aryArgs[ 0 ] );
    java.applet.AudioClip acSound = java.applet.Applet.newAudioClip( urlSound );
    if(acSound != null){
    acSound.play();
    catch( Exception murle )
    {        //rahul
    murle.printStackTrace( );
    System.exit( 1 );
    }//main
    The only change I made was in the URL part - file: instead of file:/ .
    The other was of course to play the soundclip ...... :- ) I got really confused the first time I played it .

Maybe you are looking for