java:基础内容
文档:
https://docs.oracle.com/en/java/javase/16/index.html
java程序:
Test.java —编译—> Test.class——> 用JVM运行类文件
ps: 所有java程序都将编译为类(class)文件 。java程序可以由协同工作的多个类文件组成。
JVM,即java虚拟器是运行所有java代码的解释器。运行java程序时,JVM将查找main()代码块,并开始处理该代码块中的java语句。
应用程序:
在本地计算机上运行的java程序被称为应用程序。
在下面代码所示的应用程序中,应用程序位于HelloWorld包中。
一段代码:
package HelloWorld; //put this program in the HelloWorld package public class Test { //the Test program begins here public static void main(String[] args) { //the main part of the program begins here // TODO Auto-generated method stub System.out.println("HelloWorld"); } } //the Test program ends here
java数据类型:

引用java类库
import java.util.*;
实例化对象
Random generator = new Random();
创建数组
int[] array = new int[10]; int[] array2= {1,2,3,4,5,6}; int[][] array3=new int[5][5]; //得到数组元素个数/数组上界 array.length
对象
public class Modem { int speed; public void displaySpeed() { System.out.println("Speed: "+speed); } } Modem md = new Modem(); md.speed=1000; md.displaySpeed();
//继承
public class ErrorCorrectionModem extends Modem {
}
类型转换
//简单变量类型转换 float source=7.06F; int destination=(int)source; //对象类型转换 public void paintComponent(Graphics comp){ Graphics2D comp2D=(Graphics2D)comp; }
2021.09.12

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号