关于java:cs61b-class1run-a-java-program

71次阅读

共计 1611 个字符,预计需要花费 5 分钟才能阅读完成。

应用命令行运行 java 程序,首先进入到你创立的.java 文件夹,而后关上 cmd,顺次输出
1.javac filename.java(你所命名的 java 文件的名字,不要遗记后缀.java)
之后应该会生成一个 filename.class 文件。
2.java filename(这次不须要加.java)

视频外面应该是说 javac 是 complier,java 是 interpreter

之后就能够看到程序输入了.
视频中呈现了一些命令
ls 浏览以后文件夹里的文件
rm filename.class 删除 filename.class 文件
cat filename.java 命令用于连贯文件并打印到规范输出设备上
这些是 Linux 的命令 ….
而后是一些 Java 的语法个性:
Key Syntax Features. Our first programs reveal several important syntax features of Java:

All code lives inside a class.
The code that is executed is inside a function, a.k.a. method, called main.
Curly braces are used to denote the beginning and end of a section of code, e.g. a class or method declaration.
Statements end with semi-colons.
Variables have declared types, also called their“static type”.
Variables must be declared before use.
Functions must have a return type. If a function does not return anything, we use void,
The compiler ensures type consistency. If types are inconsistent, the program will not compile.
Static Typing. Static typing is (in my opinion) one of the best features of Java. It gives us a number of important advantages over languages without static typing:

Types are checked before the program is even run, allowing developers to catch type errors with ease.
If you write a program and distribute the compiled version, it is (mostly) guaranteed to be free of any type errors. This makes your code more reliable.
Every variable, parameter, and function has a declared type, making it easier for a programmer to understand and reason about code.
There are downside of static typing, to be discussed later.

Coding Style. Coding style is very important in 61B and the real world. Code should be appropriately commented as described in the textbook and lectures.

Command line compilation and execution. javac is used to compile programs. java is used to execute programs. We must always compile before execution.

正文完
 0