基本数据类型:

整型:byte、short、int、long -》 默认值是:0;
浮点型:float、double -》 默认值是:0.0;
字符型:char -》默认值是:’\u0000’;
字符串型:stinrg -》默认值是:
布尔型:boolean -》默认值是:false
引用数据类型:数组、类、接口 -》默认值是:null

7e0e50913efddc7150575c917e5b8a24.png

深入了解数组:

1.数据组引用变量只是一个引用,这个引用变量可以指向任何有效的内存,只有当该引用指向有效内存后,才可以通过该数组变量来访问数组元素。
2.实际数组对象是存储在堆(heap)内存中的。如果引用数组的变是局部变量则在栈中(stack);

a3f2a90aaac9557df60630eb970fe1d6.png

数组排序:

Java基础知识 - 图3

  1. public class TestDemo4{
  2. public static void main(String args[]){
  3. int data [] = new int [] {9,8,5,6,4,2,1,0,3,7};
  4. sort(data);
  5. printfArray(data);
  6. }
  7. public static void sort(int arr[]){//实现数组的升序排序
  8. for(int i = 0 ;i < arr.length - 1 ; i++){
  9. //控制循环的次数
  10. for(int j = 0 ; j < arr.length - i - 1; j++){
  11. if(arr[j]>arr[j+1]){
  12. int temp = arr[j];
  13. arr[j] = arr[j+1];
  14. arr[j+1] = temp;
  15. }
  16. }
  17. }
  18. }
  19. //定义一个专门用于数组输出的方法
  20. public static void printfArray(int temp[]){
  21. for(int i = 0; i < temp.length; i++){
  22. System.out.println(temp[i] + "、");
  23. }
  24. }
  25. }