Friday, November 2, 2012

Java program without main method

Writing java program without main method


package com.jsl.sta.core;
public class StaticDemo {
static{
System.out.println("Block-1");
System.exit(0);
}
}

The above code will execute upto java 1.6 but it won't be executed in java 1.7 and gives error message


Error: Main method not found in class com.jsl.sta.core.StaticDemo, please define the main method as:

public static void main(String[] args)


In Java 7 without main method java program can't be executed.


Note:

If ask some one you can say still 1.6 its fine, Printing some message using static block without main method, But In Java 7 its required main method in order to execute java program.

No comments:

Post a Comment

Spring Boot 3 : JWT with SecurityFilterChain, AuthorizeHttpRequests, RequestMatchers

pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"...