Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #39148

Re: Surprise!

From Martin Gregorie <martin@mydomain.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Surprise!
Date 2019-09-19 20:47 +0000
Organization A noiseless patient Spider
Message-ID <qm0pgn$h50$1@dont-email.me> (permalink)
References <Main.java-20190919202538@ram.dialup.fu-berlin.de>

Show all headers | View raw


On Thu, 19 Sep 2019 19:28:50 +0000, Stefan Ram wrote:

> Write this:
> 
> public final class A { public static void main( final java.lang.String[]
> args )
>   { B.hello(); }}
> 
> public final class B { public static void hello()
>   { java.lang.System.out.println( "Hello!" ); }}
> 
>   and save it as "Main.java". Then call:
> 
> java Main.java
> 
>   with a recent JDK. What you have there is a file named "Main.java"
>   that does /not/ contain a class "Main", and it has /two/ public
>   classes. Yet, the above command will happily print,
> 
> Hello!
> 
>
Not with the latest Open JDK 1.8 it doesn't: this just complains the A 
should be on A.java and B should be in B.java

Maybe later Java versions removed the "ClassName == ClassName.java" and 
"public static void main(String[])" requirements to make scripting easier?


-- 
Martin    | martin at
Gregorie  | gregorie dot org

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: Surprise! Martin Gregorie <martin@mydomain.invalid> - 2019-09-19 20:47 +0000
  Re: Surprise! Eric Douglas <e.d.programmer@gmail.com> - 2019-09-19 14:01 -0700
    Re: Surprise! Martin Gregorie <martin@mydomain.invalid> - 2019-09-19 23:18 +0000
      Re: Surprise! Knute Johnson <groups@585ranch.com> - 2019-09-19 20:03 -0500
      Re: Surprise! Eric Douglas <e.d.programmer@gmail.com> - 2019-09-20 08:03 -0700
        Re: Surprise! Arne Vajhøj <arne@vajhoej.dk> - 2019-09-20 19:01 -0400

csiph-web