Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 335471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:09:07+00:00 2026-05-12T10:09:07+00:00

The entry point into a program in java is typically something like this //

  • 0

The entry point into a program in java is typically something like this


    // MyMain.java
    public class MyMain{  
      //whatever 
        public static void main(String args[]){ 
        System.out.println("balderdash");
        }
    }

However, since there is only the one SOP in main, the above class may be like this instead


    // MyMain.java
    public class MyMain{
        //whatever
        static {    
        System.out.println("balderdash");
        }
    }

One obvious advantage to using main(…) is that arguments may be passed in to the program.
Another ( I’m guessing here ) may have to do with the garbage collecter treating objects created within a static block differently.

What other benefits come from using the language-defined entry-point – public static void main( String args[] ) instead of using a static initializer.

p.s. The above snippets are for illustration only, and may not be compilable

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:09:07+00:00Added an answer on May 12, 2026 at 10:09 am
    • You can test it or call it from other applications.
    • It’s what other people will expect.
    • If you execute your whole application in the context of a static initializer, I suspect you’ll effectively be holding a lock on that type for the whole time. If any other thread tries to call a static method in the same class, it will block. That’s the sort of problem you get when you try to use a concept in an unexpected way – it’s just conceptually “wrong”. Initializing the class simply isn’t the same as running an application.

    EDIT: Here’s an example of that problem:

    class SampleTask implements Runnable
    {
        public void run()
        {
            System.out.println("Calling someStaticMethod");
            Test.someStaticMethod();
            System.out.println("someStaticMethod returned");
        }
    }
    
    public class Test
    {
        static
        {
            System.out.println("Starting new thread...");
            new Thread(new SampleTask()).start();
            System.out.println("Thread started. Sleeping");
            try
            {
                Thread.sleep(5000);
            }
            catch (InterruptedException e)
            {
                System.out.println("Interrupted!");
            }
            System.out.println("Finished sleeping");          
        }
    
        public static void someStaticMethod()
        {
            System.out.println("In someStaticMethod");
        }
    
        public static void main(String[] args)
        {
            System.out.println("In main. Sleeping again.");
            try
            {
                Thread.sleep(5000);
            }
            catch (InterruptedException e)
            {
                System.out.println("Interrupted!");
            }
        }
    }
    

    Output:

    Starting new thread...
    Thread started. Sleeping
    Calling someStaticMethod
    Finished sleeping
    In someStaticMethod
    someStaticMethod returned
    In main. Sleeping again.
    

    Note how the call to someStaticMethod from the new thread has to wait until the static initializer has finished before it gets to run.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 189k
  • Answers 189k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer When I've got uncommitted changes from one task in my… May 12, 2026 at 5:42 pm
  • Editorial Team
    Editorial Team added an answer Reference: MySQL Reference The syntax is: IF (friend.block = 1)… May 12, 2026 at 5:42 pm
  • Editorial Team
    Editorial Team added an answer You could refactor some parts of the code by creating… May 12, 2026 at 5:42 pm

Related Questions

I'm writing a tiny program that takes user input using Getops, and based on
I am writing a piece of code designed to do some data compression on
I am working on writing a wrapper DLL to interface a communication DLL for
I would be grateful for any suggestions on how to add license key enforcement

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.