java的第一个程序
Java的第一个程序
1.新建文件
public class Hello {
public static void main(String[] args) {
System.out.println("hello world!");
}
}
2.打开cmd

3.执行javac Hello.java

javas命令:将Java源代码转换成jvm能识别的Java字节码

4.在执行Java Hello,会发现控制台会输出hello world!

1 自动关机与接触关机
- 自动关机
import java.io.IOException;
public class Demo1 {
/**
* 文档注释
* 这是程序的入口
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// 单行注释
/*
* 多行注释
*/
//"println":输出并换行
System.out.println("hello world!");
//自动关机
//得到当前java运行时的环境,exec("DOC命令") 3600s后自动关机
Runtime.getRuntime().exec("shutdown -s -t 3600s");
}
}
2.解除自动关机
import java.io.IOException;
public class Demo2 {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Runtime.getRuntime().exec("shutdown -a");
}
}
2 代码语句分类
2.1 结构定义语句
public class Hello {
public static void main(String[] args) {
}
}
2.2 功能执行语句
//语句必须以英文分号结束
System.out.println("hello world!");

浙公网安备 33010602011771号