[ Java 笑话]public static void main(String[] args){} - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
yazinnnn
V2EX    Java

[ Java 笑话]public static void main(String[] args){}

  •  
  •   yazinnnn Oct 8, 2022 4968 views
    This topic created in 1299 days ago, the information mentioned may be changed or developed.

    https://www.bilibili.com/video/BV1e24y197Qv/

    The classic “Hello World” program looks like this in Java:

    public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } } It may only be five lines, but those lines are packed with concepts that are challenging to absorb without already having some programming experience and familiarity with object orientation. Let’s break down the concepts a student confronts when writing their first Java program:

    public (on the class). The public accessibility level is relevant only when there is going to be cross-package access; in a simple “Hello World” program, there is only one class, which lives in the unnamed package. They haven’t even written a one-line program yet; the notion of access controlkeeping parts of a program from accessing other parts of itis still way in their future.

    class. Our student hasn’t set out to write a class, or model a complex system with objects; they want to write a program. In Java, a program is just a main method in some class, but at this point our student still has no idea what a class is or why they want one.

    Methods. Methods are of course a key concept in Java, but the mechanics of methodsparameters, return types, and invocationare still unfamiliar, and the main method is invoked magically from the java launcher rather than from explicit code.

    public (again). Like the class, the main method has to be public, but again this is only relevant when programs are large enough to require packages to organize them.

    static. The main method has to be static, and at this point, students have no context for understanding what a static method is or why they want one. Worse, the early exposure to static methods will turn out to be a bad habit that must be later unlearned. Worse still, the fact that the main method is static creates a seam between main and other methods; either they must become static too, or the main method must trampoline to some sort of “instance main” (more ceremony!) And if we get this wrong, we get the dreaded and mystifying "cannot be referenced from a static context" error.

    main. The name main has special meaning in a Java program, indicating the starting point of a program, but this specialness hides behind being an ordinary method name. This may contribute to the sense of “so many magic incantations.”

    String[]. The parameter to main is an array of strings, which are the arguments that the java launcher collected from the command line. But our first programlikely our first dozenwill not use command-line parameters. Requiring the String[] parameter is, at this point, a mistake waiting to happen, and it will be a long time until this parameter makes sense. Worse, educators may be tempted to explain arrays at this point, which further increases the time-to-first-program.

    System.out.println. If you look closely at this incantation, each element in the chain is a different thingSystem is a class (what’s a class again?), out is a static field (what’s a field?), and println is an instance method. The only part the student cares about right now is println; the rest of it is an incantation that they do not yet understand in order to get at the behavior they want.

    简化后的 hello world

    void main() { println("Hello World"); } 

    诶哟谢天谢地,恭喜今后的 java 初学者,终于能学一个正常的 hello world 了

    23 replies    2022-10-08 13:59:05 +08:00
    kujio
        1
    kujio  
       Oct 8, 2022   3
    对初学者来说 void main() {} 和 pubic static void main(String[] args){}只是字数不一样, 这些概念都是在深入学习之后才明白的,而深入学习之后 void main(){} 反而比 public static void main(String[] args) 更难理解。
    ZField
        2
    ZField  
       Oct 8, 2022
    初学者没必要一上来就搞简写= =
    yolee599
        3
    yolee599  
       Oct 8, 2022 via Android
    C99 之后,void main() {} 是不规范写法,应该返回 int 的
    yolee599
        4
    yolee599  
       Oct 8, 2022 via Android
    既然是仿 c-style 要仿得像一点嘛
    chendy
        5
    chendy  
       Oct 8, 2022   2
    一众脚本语言:main 是啥?
    selca
        6
    selca  
       Oct 8, 2022   1
    字数不同而已,打几个字都不愿意,建议学 python ,那个字少
    zhuweiyou
        7
    zhuweiyou  
       Oct 8, 2022
    不见得是简写,反正有 IDE 都是打几个字母全出来的.
    monkeyWie
        8
    monkeyWie  
       Oct 8, 2022
    建议直接学 js ,main 方法都不需要
    wdwwtzy
        9
    wdwwtzy  
       Oct 8, 2022
    建议直接学 C# ,main 方法都不需要
    Kamiyu0087
        10
    Kamiyu0087  
       Oct 8, 2022
    你用 jshell 一行就够了
    一样是 Java
    LGA1150
        11
    LGA1150  
       Oct 8, 2022 via Android
    psvm
    sout
    Leviathann
        12
    Leviathann  
       Oct 8, 2022
    @LGA1150 main + tab 就可以
    WOLFRAZOR
        13
    WOLFRAZOR  
       Oct 8, 2022
    初学开始用简写并不好,容易无法理解。
    dbpe
        14
    dbpe  
       Oct 8, 2022
    建议学 Node..前后端一把梭
    Pastsong
        15
    Pastsong  
       Oct 8, 2022
    喜欢打字多的建议去写 ASSEMBLY ,那个字多
    Slurp
        16
    Slurp  
       Oct 8, 2022
    @yolee599 #3 #4 你 C 关我 Java 屁事?

    @chendy @zhuweiyou Python:

    if __name__ == "__main__":
    wakarimasen
        17
    wakarimasen  
       Oct 8, 2022 via Android
    建议 Javascript 解释器都不用装,打开浏览器直接写
    dreamlike
        18
    dreamlike  
       Oct 8, 2022 via Android
    jshell+system.out.println 不比这个简单?
    flyingghost
        19
    flyingghost  
       Oct 8, 2022
    不想学概念建议口述,电脑都不要。
    jorneyr
        20
    jorneyr  
       Oct 8, 2022
    如果你的世界就只有一个 Hello World ,那么你赢了。
    leonshaw
        21
    leonshaw  
       Oct 8, 2022
    没有得到笑点
    shiny
        22
    shiny  
    PRO
       Oct 8, 2022 via iPhone
    全域静态管理
    dcsuibian
        23
    dcsuibian  
       Oct 8, 2022
    echo 'Hello World'
    Write-Output 'Hello World'

    不知道什么叫做“正常”的 Hello World
    About     Help     Advertise     Blog     API     FAQ     Solana     3270 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 91ms UTC 12:17 PVG 20:17 LAX 05:17 JFK 08:17
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86