Java基础语法
上一篇 /
下一篇 2017-11-08 16:48:44
/ 个人分类:JavaSE
Java关键字true、false、null是字面量,不是关键字特殊关键字(保留字):goto,const在现版本没有使用,新版中可能会使用abstract | default | if | private | thsi |
boolean | do | implements | protected | throw |
break | double | import | public | throws |
byte | else | instanceof | return | transient |
case | extends | int | short | try |
catch | final | interface | static | void |
char | finally | long | strictfp | volatile |
class | float | native | super | while |
const | for | new | switch |
|
continue | goto | package | synchronized | |
1.一个完整的Hello world 程序第一步:编写java文件
- package cn.et.cast;
- public class HelloWorld{
- public static void main(String[] args) {
- System.out.println("Hello World"):
- }
- }
(1).文件名必须和public修饰的类名一致,以.java作为文件后缀,如果定义的类不是public的,则文件名与类名可以不同(2).一个.java文件中可以有多个class,但是只能有一个public修饰类
(3).Java 源文件编译后,一个类对应生成一个.class文件
(4).一个JavaSE应用程序应该包含一个main()方法,而且方法签名是国定的,它是应用程序入口
第二部:编译java文件,生成class(与平台无关的字节码)文件
javac -d . HelloWorld.java
(1).“-d”:让该类生成的时候按照包结构去生成
(2).“.”:指的是在当前路径下生成
第三步:将字节码文件交给jvm(Java虚拟机)去解析执行
java cn.et.cast.HelloWorld
2.if-else if-else语句
- public class IfStarmentDemo{
- public static void main(String[] args) {
- if(10>20) {
- System.out.println("-_-");
- } else if(10<20){
- System.out.println("*_*");
- } else {
- System.out.println("^_^");
- }
- }
- }
3.switch-case语句- public class SwitchStarmentDemo{
- public static void main(String[] args) {
- int n=1;
- switch(n){
- case 1:'男';
- break;
- case 2:'女';
- break;
- default:'妖';
- }
- }
- }
4.while循环- public class WhileStarmentDemo{
- public static void main(String[] args) {
- int n=1;
- while(n<=10) {
- System.out.println(n++);
- }
- }
- }
public class WhileStarmentDemo{
public static void main(String[] args) {
int n=1;
while(n<=10) {
System.out.println(n++);
}
}
}
5.for循环
- public class ForStarmentDemo{
- public static void main(String[] args) {
- for(int n=1;n<=10;n++) {
- &
收藏
举报
TAG:
标题搜索
日历
|
日 |
一 |
二 |
三 |
四 |
五 |
六 |
| 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | | | | |
数据统计
- 访问量: 3620
- 日志数: 5
- 建立时间: 2017-11-06
- 更新时间: 2017-11-18