Writing main class (All in one method or split into several?)

Hello,
How is the common practice to write a main method?
I use to write one method if nothing repeats it self then I make a private method for it.
Like this
public static void main(String[] args) {
foo();
foo();
private void foo(){
}But I have read a lot of main methods where there is private methods which is only executed ones.
And the main method calls a new private method like this
public static void main(String[] args) {
foo(args);
private void foo(String[] args){
foo2();
foo3();
foo4()
private void foo2(){
private void foo3(){
private void foo4(){
}

I think its better to do the second example
but it does not really make a difference
Example 1 you have to say xyzClass.foo();
Example 2 you call the methods directly
public class XYZ{
  public XYZ(){
  public void method1(String s){ 
  public void method2(){ 
  public void method3(String s){ 
  public void method4(String s){
  public void method5(String s){ 
  public method(String[] args){
    method1(args[0]);
    method2(args[1]);
    method3(args[2]);
    method4(args[3]);
    method5(args[4]);
  }main methods
public static void main(String[] args){
  XYZ xyz = new XYZ();
  xyz.method1(args[0]);
  xyz.method2(args[1]);
  xyz.method3(args[2]);
  xyz.method4(args[3]);
  xyz.method5(args[4]);
//vs.
public static void main(String[] args){
  XYZ xyz = new XYZ();
  xyz.method(args);
}Edited by: gtRpr on 2008/07/22 01:42

Similar Messages

  • Where is the IP number for a HP deskjet 3520 e-all-in-one, needed to install into windows 7?

    Where is the IP number for a HP deskjet 3520 e-all-in-one, needed to install into windows 7?

    Hi - You can print a test page to get the IP address for your printer.  Follow these instructions:
    On the printer control panel, press the Wireless button ( ), and then press the button ( ) next to Settings .
    Press the Down Arrow ( ) to select Print Report , and then press OK .
    Press the Down Arrow ( ) to select Test Report , and then press OK .
    The printer prints the test page.
    Hope that helps.
    Say Thanks by clicking the Kudos thumbs up. Please mark the post that solves your problem as an Accepted Solution so other forum users can utilize the solution.
    I am an HP employee.

  • How can I divide one big long track into several smaller ones?

    I have many mp3"s I imported or downloaded in my Library of lectures, sermons and speeches.
    How can I divide one big long track into several smaller ones?
    Any input would be great.

    lakergrl wrote:
    How do I split one very long track into several tracks (audio journal split into each day)
    http://www.bulletsandbones.com/GB/GBFAQ.html#exportsections
    (Let the page FULLY load. The link to your answer is at the top of your screen)

  • Creating a class with only one method in it

    Do you think it is worth creating a class if you only have one method in it?
    Or do you think i should just put it in the class that contains the main method?
    Just wondering.
    Thank you.

    lol, what does it depend on.
    The class i am talking about, is to register new
    customers, A class is typically a noun in your problem description - so the class could be Customer, or maybe Registry. But "register new customers" is an action, so this should be a method, and it should belong to whatever class in your system you think should have the responsibility to register new custromers.
    a pretty major part of the application.
    But is it really required to have it's own class?
    If it still depends, what does it depend on?

  • Source one message to split into 2 messages

    Hi Gurus.
    I have one incoming IDOC record. There are 3 segments in the IDOC. Output type is simple - just 5 or 6 fields. But each field of the output type can be derived either from segment 1, or 2, or 3. Means if all 3 segments have data, there will be 3 rows in the output message type. It's an IDOC to file scenario.
    To elaborate:
    Seg 1 -> Field : pernr, appt_type, change reason -> this can map one to one directly to Output type 3 fields, and will be 1 row in the output file.
    Seg 2 -> same fields, but the mapping has some rules. Based on those rules, output type's 3 fields will get their values and this will be 2nd row in the output file.
    Same for segment 3.
    So in summary, it means, 1 IDOC record can result in 3 records in the output file.
    How can I go ahead to achieving this?
    Thanks in adv.

    >
    Aishi A wrote:
    > Hi Gurus.
    >  I have one incoming IDOC record. There are 3 segments in the IDOC. Output type is simple - just 5 or 6 fields. But each field of the output type can be derived either from segment 1, or 2, or 3. Means if all 3 segments have data, there will be 3 rows in the output message type. It's an IDOC to file scenario.
    > To elaborate:
    > Seg 1 -> Field : pernr, appt_type, change reason -> this can map one to one directly to Output type 3 fields, and will be 1 row in the output file.
    > Seg 2 -> same fields, but the mapping has some rules. Based on those rules, output type's 3 fields will get their values and this will be 2nd row in the output file.
    > Same for segment 3.
    > So in summary, it means, 1 IDOC record can result in 3 records in the output file.
    > How can I go ahead to achieving this?
    >
    > Thanks in adv.
    Hi Aishi,
    You can use CONTEXT option, to refer Segment2&3 to context node of Segment1
    c you

  • When i connect my mac book pro to an external display using a VGA cable and adaptor, the external display splits into several different columns of the same screen overlapping one another. Does anybody have any ideas as to why this happens?

    I have used different VGA to mini port adaptors, different VGA cables and connected them to different external monitors and prjectors but the same thing happens. I am starting to think there may be a problem with the macbook itself however, when i have used a HDMI lead and adaptor to external monitors the external display is fine.

    Hi there LDIMERY,
    You may find the troubleshooting steps in the article below helpful.
    Apple computers: Troubleshooting issues with video on internal or external displays
    http://support.apple.com/kb/ht1573
    -Griff W. 

  • How can i execute Spaces API in java main class?

    Hi
    I am able to execute Spaces API through portal application. However if i try to execute it in java main class, its throwing an exception
    "SEVERE: java.io.FileNotFoundException: .\config\jps-config.xml (The system cannot find the path specified)"
    oracle.wsm.common.sdk.WSMException: WSM-00145 : Keystore location or path can not be null or empty; it must be configured through JPS configuration or policy configuration override.
    How can i set this path, so that i can execute Spaces API from java main class.
    Need this main class to configure in cron job, to schedule a task.
    Regards
    Raj

    Hi Daniel
    Currently i have implemented create functionality in my portal application using Spaces API, which is working fine. Now the requirement is, i need to implement a "Cron Job" to schedule a task, which will execute to create space(for example once in a week). Cron job will execute only the main method. So I have created java main class, in which I have used Spaces API to perform create space operation. Then it was giving exception.
    Later I understood the reason, as I am executing the Space API with a simple JSE client, its failing since a simple java program has no idea of default-keystore.jks, jps-config.xml, Security Policy. Hence i have included those details in main class. Now I am getting new error,
    SEVERE: WSM-06303 The method "registerListener" was not called with required permission "oracle.wsm.policyaccess"
    For your reference i have attached the code below, please help. How can i use Spaces API in java main method(i mean public static void main(String[] args) by giving all required information.
        public static void main(String[] args) throws InstantiationException,
                                                      GroupSpaceWSException,
                                                      SpacesException {
            Class2 class2 = new Class2();
            GroupSpaceWSContext context = new GroupSpaceWSContext();
            FactoryFinder.init(null);
            context.setEndPoint("http://10.161.226.30/webcenter/SpacesWebService");
            context.setSamlIssuerName("www.oracle.com");
            context.setRecipientKeyAlias("orakey");
            Properties systemProps = System.getProperties();
            systemProps.put("java.security.policy","oracle/wss11_saml_or_username_token_with_message_protection_client_policy");
            systemProps.put("javax.net.ssl.trustStore","C:\\Oracle\\Middleware11.1.7\\wlserver_10.3\\server\\lib\\cacerts.jks");
    systemProps.put("oracle.security.jps.config","C:\\Oracle\\Middleware11.1.7\\user_projects\\domains\\workspace\\system11.1.1.7.40.64.93\\DefaultDomain\\config\\fmwconfig\\jps-config.xml");
            systemProps.put("javax.net.ssl.keyStore",C:\\Oracle\\Middleware11.1.7\\user_projects\\domains\\workspace\\system11.1.1.7.40.64.93\\DefaultDomain\\config\\fmwconfig\\consumer.jks");
            systemProps.put("javax.net.ssl.keyStorePassword", "Test12");
            System.setProperties(systemProps);
            GroupSpaceWSClient groupSpaceWSClient;
            try {
                groupSpaceWSClient = new GroupSpaceWSClient(context);
                System.out.println("URL: " +
                                   groupSpaceWSClient.getWebCenterSpacesURL());
                //delete the Space
                List<String> groupSpaces = groupSpaceWSClient.getGroupSpaces(null);
                System.out.println("GroupSpaces:: " + groupSpaces.size());
            } catch (Exception e) {
    Regards
    Raj

  • Determine a string from main class in an outside class

    Hello there,
    This might be stupid question but I cant think, I am so very tired. Okay here is the question, is there any way we could see or the get the value of a string(just a string which is set in main class'A', its already set, we cannot make it static r anything like that)in a method outside that main class, probably in a method 'x' in class'C'.
    Thanks
    potti

    Yes, you can, in many ways, or else Java would be moot. Excluding the static way of doing it, which by the way is evil, your class C can make an instance of class A and then access it either as a public field or as the value returned by a public method. You can also use inheritance, but it's pointless in this case, inheritance is meant to abstract, extend functionality, and prevent having to rewrite code. It's not meant for accessing fields. And by the way, inheritance, too, is evil.
    This is one way to do it.
    class A {
         public String s = "great balls of fire";
    public class C {
         public static void main(String[] args) {
              A myInstance = new A();
              String s = myInstance.s;
              System.out.println(s);
    }This is the preferred way to do it, as it encapsulates the String. The idea of encapsulation is to access fields by a method instead of directly since interfaces are less likely to change than an object's data and in the case that the object's data does change and the interface does not, the changes will remain local.
    class A {
         private String s = "great balls of fire";
         public String getS() { return s; }
    public class C {
         public static void main(String[] args) {
              A a = new A();
              String s = a.getS();
              System.out.println(s);
    }

  • How can ı run my JavaMail main class in dos mode ?

    I develop a program about current account. There are two classes. One class is main class. I can run main class in Sun One Studio but &#305; can not run in DOS mode. If &#305; wrote "java Carihesap " on command line appear exception in thread main javax/mail/messaging exception.
    Please help me about this problem

    &#305; didnt include any jars within my project. My project occur only two classes. First one main class other one table model class .

  • Photosmart 7525 All in One - Unable to Scan to Computer

    Unable to "Enable Scan to Computer"
    I've downloaded the most recent downloads and drivers.
    Running Yosemite 10.10.1 on Mac
    WiFi connection confirmed
    HP Utility - Photosmart 7520 series > Scan to Computer > "Scan to Computer Cannot Be Enabled"

    Hi @sarahxtemp,
    Looks like we may need to try a different uninstall approach and see if this gives us the Scan to Computer option.
    Move the files and/or folders to the trash, drag and drop
    Macintosh HD/Applications//Hewlett-Packard folder
    Macintosh HD/Library/Application Support/ - delete all files and folders regarding HP/Hewlett Packard
    In Macintosh HD/Library/Caches - delete all files and folders regarding HP/Hewlett Packard
    Macintosh HD/Library/Documentation/Help/ - delete all files and folders regarding HP/Hewlett Packard
    Macintosh HD/Library/Frameworks/HPServicesInterface.framework
    Macintosh HD/Library/Frameworks/HPSmartX.framework
    Macintosh HD/Library/Image Capture/TWAIN Data Sources/HP Scan Pro
    In Macintosh HD/Library/Image Capture/Scripts - delete all files and folders regarding HP/Hewlett Packard
    In Macintosh HD/Library/Preferences - delete all files and folders regarding HP/Hewlett Packard
    Move Macintosh HD/Library/Preferences/loginwindow.plist to the desktop. NOTE: Not removing the file loginwindow.plist during the manual uninstall could cause the uninstall to be unsuccessful.
    In Macintosh HD/Library/Printer/hp - delete folder
    In Macintosh HD/Library/StartupItems, drag the following folders to the trash, HP IO and HP Trap Monitor
    In Macintosh HD/Users/USERNAME (this should have a symbol of a house next to it)/Library/Preferences, drag the following folders to the trash: *Any files beginning with com.apple.print, *Any files beginning with com.hp, *Any files beginning with Hewlett-Packard, *Any files beginning with HP or hp
    In MacintoshHD/Users/USERNAME/Library/Printers, drag any All-in-One printers listed here into the trash.
    Drag the HP icons from the Dock and drop it on an empty space on the desktop. The icon will disappear.
    Close all open windows.
    Restart.
    Empty the Trash.
     Follow these steps to remove the print driver and other software from a computer.
    From the computer desktop, double-click the Macintosh HD  icon.
    Double-click the Library folder.
    Double-click the Printers folder.
    Right-click the HP folder, and then select Move to Trash.
    When prompted, type the Administrator name and Password for the computer, and then clickOK. Wait for authentication to complete.
    Double-click the PPDs  folder.
    Double-click the Contents  folder.
    Double-click the Resources  folder.
    Locate your printer in the printer list, and then right-click on your printer and select Move to Trash.
    When prompted, type the Administrator name and Password for the computer, and then click OK. Wait for authentication to complete.
    Click the Trash icon on the taskbar, click the Empty  button, and then click OK to empty the trash.
    NOTEBy clicking OK, all items in your trash will be permanently deleted from your computer. To delete one item in the trash, click that item to highlight it, and then click OK.
    On the upper-left corner of the computer desktop, click the Apple menu icon, and then click System Preferences on the drop-down menu.
    Double-click Print & Scan.
    In the Printers list, click your HP printer, and then click the Minus button to delete it.
    Restart the computer again.
    After logging in, Repair Disk Permissions
    On the Dock, click  Applications, and then click Utilities.
    Double-click Disk Utility.
    Highlight your hard drive/partition on the left (by default this is "Macintosh HD").
    Click the Repair Disk Permissions button at the bottom of the window.
    Once the repair is complete, restart the computer .
    Restart the computer.
    Install the software; HP Photosmart 7520 e-All-in-One Printer Full Feature Software and Drivers, once the software is successfully installed we can then delete the loginwindow.plist from the desktop.
    Download and install the HP Printer Drivers for OS X.
    **Source
    Please let me know if this resolves the issue.
    HevnLgh
    I work on behalf of HP
    Please click “Accept as Solution” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" to the left of the reply button to say “Thanks” for helping!

  • Hi all, i need to create a one method in assistance class for updating the custom table.

    Req as follows : 
    1. i need to create one method in a assistance calss  for updating custom table .
    2. now i  have to pass the multiple entries to that table then inside the method based need to update the Ztable. based on this entries
    3. My internal table is having 2 fields ( Customernumber (key field) , Shiftloc ).(Multiple entries ex : 500)
       based on customernumber need to update the new shiftloc in my custom table.
    Can any one give some inputs please. i have doubt can we pass mupltiple entries (internal) as a importing parameter to the method?
    Cheers,
    Venu

    Hi rama,
    thank you for your promt reply.
    i have one more query. Here i need to update the only Shipt to adress for particular customer number.
    i have written the code as below. Please clarify this code will work for my requirement.
       method UPDATE_SHIPTO.
      data : Lt_contract type ty_update_shipto_t.
      data : ls_contract like line of  Lt_contract .
      REFRESH : Lt_contract.
      lt_contract[] = LT_DATA[].
      loop at lt_contract into ls_contract.
    *    update  Zcustom  SET ship_to_adress  = ls_contract-new_bp
                                 WHERE  cust_no = ls_contract-custnum
        CLEAR : ls_contract.
      ENDLOOP.
    COMMIT WORK.
    endmethod.

  • Running one main class from another

    Hey, i developed two main class. Each class produce it's one JFrame. One Frame suppose to at one point run the other frame when a start button is press. How should I go about doing it?

    You can just call the other class's main method.
    However, that's kind of messy. If you have any functionality in your main method other than just bootstrapping your program, it's probably better to refactor it out into a different method. Then your other class can invoke that new method.

  • Using main class's methods from a different class in the same file

    Hi guys. Migrating from C++, hit a few snags. Hope someone can furnish a quick word of advice here.
    1. The filename is test.java, so test is the main class. This code and the topic title speak for themselves:
    class SomeClass
         public void SomeMethod()
              System.out.println(test.SomeOperation());
    public class test
         public static void main(String args[])
              SomeClass someObject = new SomeClass();
              someObject.SomeMethod();
         public static String SomeOperation()
              return "SomeThing";
    }The code works fine. What I want to know is, is there some way to use test.SomeOperation() from SomeClass without the test.?
    2. No sense opening a second topic for this, so second question: Similarly, is there a good way to refer to System.out.println without the System.out.? Like the using keyword in C++.
    Thanks.

    pfiinit wrote:
    The code works fine. What I want to know is, is there some way to use test.SomeOperation() from SomeClass without the test.?Yes you can by using a static import, but I don't recommend it. SomeOperation is a static method of the test class, and it's best to call it that way so you know exactly what your code is doing here.
    2. No sense opening a second topic for this, so second question: Similarly, is there a good way to refer to System.out.println without the System.out.? Like the using keyword in C++.Again, you could use static imports, but again, I don't recommend it. Myself, I use Eclipse and set up its template so that when I type sop it automatically spits out System.out.println(). Most decent IDE's have this capability.
    Also, you may wish to look up Java naming conventions, since if you abide by them, it will make it easier for others to understand your code.
    Much luck and welcome to this forum!

  • Hi! At connection to iTunes the section "other" constantly increases. What's the matter? How to avoid it? On phone music isn't necessary, video too isn't present. But another grows. How to correct it? I know only one method, it to dump all settings and a

    Hi! At connection to iTunes the section "other" constantly increases. What's the matter? How to avoid it? On phone music isn't necessary, video too isn't present. But another grows. How to correct it? I know only one method, it to dump all settings and a content.

    http://discussions.apple.com/docs/DOC-5142

  • One method used in two classes

    Hi
    I have one method in class A and I need to use it (only this method) in class B. what should I do? Should I create subclass within class A with this method, and then use it in class B or create completely different class C with only this method?
    Thanks
    waso

    It's a good idea to use Java conventions about cAsE: especially since boolean and Boolean are different beasts.
    So:
    public class MyExample {
        public boolean example() {
            System.out.println("My example");
            return true;
    }You use it in some other class B like this:
    class B {
        void someMethod() {
            MyExample eg = new MyExample();
            boolean result = eg.example();
            System.out.println("example() returned " + result + " (as expected!)");
    }There's no subclassing ("in" A or elsewhere).
    This is a bit of a contrived example, because example() always returns the same thing. eg is initialised as an instance of MyExample but that class has no state so the method is effectively static. If MyExample had state and the method call did something genuine involving this state, then things would get interesting - and it is precisely then that subclassing, extracting someMethod() into some other class, or inlining it where it was used would make no sense.
    Edited by: pbrockway2 on Jul 12, 2008 9:26 PM

Maybe you are looking for

  • Is Verizon going to offer the 32GB and/or 64GB models of the Galaxy S 4?

    I have been waiting for months for information about this phone.  It has come out incrementally in very small bites and, slowest and most grudgingly of all, from Verizon.  Now, finally, Verizon has offered pre-order of the 16GB model.  I don't want t

  • Handwriting input on X60T after Win 8.1 upgrade

    Hi Folks Has anyone else had trouble getting their apps to insert handwritten text from the Tablet Input Panel?  If I use onscreen keyboards, no problem.  Only has a problem with parsed handwritting; and then only on some apps like the notes editor i

  • Portal Activity Report - Aggregator System Load

    Hey Everyone, What is everyone's impression of the Portal Activity Report? Is it helpful? Do we really have anyother options to get valid reports on usuage? Also, what type of load does the Aggregator really put on its server? Thanks

  • How do I cancel and cleanup after starting Xcode download?

    I started to install xcode 5 and the download progress bar opened in launchpad.  Whe I saw the 2.3GB size I paused the download. The apple store will let me "hide" the "purchase" (free) but how do I clean up and remove the progress from lauchpad?

  • K7T Turbo2 ver5.0 won\'t reboot

    I just recently bought a K7T Turbo2 (MS-6330) motherboard and I'm having a problem with it rebooting.  I can't get the board to do a warm reboot.  It works fine if I turn off the power and then turn it back on but even changing the BIOS settings won'