且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

《Java编码指南:编写安全可靠程序的75条建议(英文版)》—— 2.5 保存编写好的程序

更新时间:2022-10-12 22:51:29

本节书摘来异步社区《Java编码指南:编写安全可靠程序的75条建议(英文版)》一书中的第2章,第2.5节,作者:【美】Fred Long(弗雷德•朗),Dhruv Mohindra(德鲁•莫欣达), Robert C. Seacord(罗伯特 C.西科德),Dean F.Sutherland(迪恩 F.萨瑟兰),David Svoboda(大卫•斯沃博达),更多章节内容可以访问云栖社区“异步社区”公众号查看。

2.5 保存编写好的程序

程序现在应如程序清单2.2所示,当然,可能第5行和第6行使用的间距略有不同。进行必要的改正,然后存储该文件(通过选择File->Save来执行)。

程序清单2.2 Saluton程序的完整版本

1: package com.java24hours;
2:
3: class Saluton {
4:   public static void main(String[] arguments) {
5:     String greeting = "Saluton mondo!";
6:     System.out.println(greeting);
7:   }
8: }```
计算机运行该程序时,将运行main语句块中的第5行和第6行。用自然语言而不是Java来编写该程序时,将如程序清单2.3所示。

程序清单2.3 Saluton程序的逐行分解

1: Put this program in the com.java24hours package.
2:
3: The Saluton program begins here:
4:   The main part of the program begins here:
5:      Store the text "Saluton mondo!" in a String variable named
       greeting
6:      Display the contents of the variable greeting
7:   The main part of the program ends here.
8: The Saluton program ends here.`
程序清单2.4所示为使用克林贡语言编写的程序,该语言由电影《星际迷航》中的外星种族所使用。

程序清单2.4 使用克林贡语言编写的Saluton程序

1: This program belongs to the house of com.java2hours!
2:
3: Begin the Saluton program here if you know what's good for you!
4:   The main part of the program begins here with honor!
5:      Store the gibberish "Saluton mondo!" in a String variable
        called greeting!
6:      Display this gibberish from a tongue inferior to Klingon!
7:   End the main part of the program here to avoid my wrath!
8: End the Saluton program now and be grateful you were spared!