java基础知识整理

1.数据类型:

  八大基本数据类型:整byte、short、int、long(1、2、4、8字节);浮float、double(8、16位有效数字);布boolean;字符char

  三大引用数据类型:对象、接口、数组

  

  这里特变强调一点:java传参时,即使你传的是引用数据类型,依然走的是值传递!!!!!

  值传递:传入的是一个副本值!!

  如若传入的是对象,则是传入的对象地址副本!可以通过这个副本地址调用原副本的方法,但是改变这个副本地址,对原对象毫无影响!!

 1 package test;
 2 
 3 public class test {
 4 
 5     static B b;
 6 
 7     public static void main(String[] args) {
 8         b = new B("hehe");
 9         System.out.println("befor:" + b.hashCode() + ":" + b.name);
10         change(b);
11         System.out.println("later:" + b.hashCode() + ":" + b.name);
12     }
13 
14     private static void change(B b) {
15         b.name = "da";
16         b = new B("heheda");
17     }
18 }
19 
20 class B {
21     String name;
22 
23     public B(String name) {
24         super();
25         this.name = name;
26     }
27 
28 }

 

 

2.自动类型转换与强制类型转换:

  自动:int a;byte b;a=a+b;这里,b是1个字节的,只能转向高字节的int参与运算

  注意:byte b;b=b+5;这就报错了,原因是5是int,int+byte只能按int计算,完事儿后就成了int,所以不能直接赋值给byte型的b

  强制:接上 b=(byte)b+5;

3.数组

  定义方式:

  a. 元素类型[]  数组名=new 元素类型[size]

    int[] arr = new int[5];

  注意元素类型可以是对象

  b. 元素类型[]  数组名=new 元素类型[]{元素1,元素2...}

    int[] arr = new int[]{3,5,1,7};

    int[] arr = {3,5,1,7};

 二维数组

  int[][] arr = new int[3][2];

  int[][] arr = new int[3][];

  int[][] arr = {{1,2,3},{1,2},{1,2,3,5}};

posted @ 2015-07-29 13:11  洱海  阅读(264)  评论(0编辑  收藏  举报
.First { margin: 10px 0; font-family: 'Microsoft Yahei'; text-align: left; padding: 6px 20px; color: #fff; background: #55895B; font-size: 20px; border-radius: 4px; clear: both; } .Second { margin: 10px 0; font-family: 'Microsoft Yahei'; padding: 6px 20px; background: #93C8A2; color: white; font-size: 18px; border-radius: 4px; clear: both; } .Third { margin: 10px 0; padding: 6px 20px; font-family: 'Microsoft Yahei'; margin: 15px 0; font-size: 16px; color: black; background: #C6EFD2; border-radius: 4px; clear: both; } .note { margin: 10px 0; padding: 15px 20px 15px 60px; background: #FCFAA9 url('http://images.cnblogs.com/cnblogs_com/libaoheng/305804/o_yellow-pin.png') no-repeat 20px 0; font-size: 15px; font-family: 'Microsoft Yahei'; box-shadow: 0 0 8px #aaa; clear: both; } .demo { text-align: left; padding: 6px 20px; overflow: auto; border-radius: 4px; background: orange; color: #fff; font-size: 16px; clear: both; } .cnblogs_Highlighter { border: solid 1px #ccc; clear: both; } .cnblogs_code { background: #EFFFF4; border: solid 0px #939393; font-size: 14px; clear: both; padding: 10px 20px; } .cnblogs_code pre { font-size: 14px; } .cnblogs_code span { font-family: Courier New; font-size: 14px; }