Results 1 to 2 of 2
  1. #1
    paola is offline Member
    Join Date
    Dec 2008
    Rep Power

    Default alternative to static initialization blocks


    I've been asked to modify some code written by someone else. The code currently has a static initialization block that invokes a program and also uses addShutdownHook to exit cleanly. To invoke and close the program you have to pass a file name as an argument. The static block was working perfect here because the user was passing the file name on the command line when he ran the class using the -D option and the name of the variable. They don't want to do that anymore. I won't have the file name until the user invokes a begin(String file) method. So the static initialization is not a good idea anymore. btw, this class doesn't have a main method. Since I'm new to java, I'm not sure which would be the best approach. I read somewhere that a private static method is an alternative to static initialization blocks. Can I create a private static method and move the lines that start and exit the program there and then call it from inside the begin method? :confused:

    I will appreciate any help!

  2. #2
    racerxadam is offline Member
    Join Date
    Jul 2008
    Rep Power

Similar Threads

  1. alternative for ajax
    By site4u in forum New To Java
    Replies: 6
    Last Post: 04-28-2011, 01:15 PM
  2. Any Alternative to Swing?
    By Niveditha in forum AWT / Swing
    Replies: 13
    Last Post: 06-27-2008, 09:39 AM
  3. Replies: 0
    Last Post: 04-16-2008, 11:07 PM
  4. Blocks Language 0.1
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 09-22-2007, 11:21 PM
  5. Task Blocks 0.5
    By johnt in forum Java Software
    Replies: 0
    Last Post: 08-08-2007, 08:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts