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

    Default alternative to static initialization blocks

    Hi,

    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!
    Thanks,

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

Similar Threads

  1. alternative for ajax
    By site4u in forum New To Java
    Replies: 6
    Last Post: 04-28-2011, 02:15 PM
  2. Any Alternative to Swing?
    By Niveditha in forum AWT / Swing
    Replies: 13
    Last Post: 06-27-2008, 10:39 AM
  3. Replies: 0
    Last Post: 04-17-2008, 12:07 AM
  4. Blocks Language 0.1
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 09-23-2007, 12:21 AM
  5. Task Blocks 0.5
    By johnt in forum Java Software
    Replies: 0
    Last Post: 08-08-2007, 09: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
  •