Learn Java01

来源:互联网 发布:一键越狱软件 编辑:程序博客网 时间:2024/05/18 02:26

1.== and equals

the operator == wiil say if they are the same, if you want to check if they are logically equal

2.Arrays in Java are also objects.

3.float a=1.0f; or float a=(float) 1.0;

4.Foreach

char[] chars={'a','b','c'};

for(char c:chars)

{

}

5.The Arguments of Functions

I always like to say that arguments to Java methods are passed by value.

Student joe = new Student("joe");Student jack = new Student("jack");bar2(joe, jack);
In bar2

just like 

Student s1 = joe;Student s2 = jack;
s1== joe is true. This means that running methods on s1 will change the object joe. But if we'll change the value of s1 as a reference, it will not affect the reference joe.

Summary

  • Every Java method has to be within a class
  • Static methods belong to a class while non-static methods belong to objects
  • All parameters to functions are passed by value, primitives content is copied, while objects are not copied and some would say 'passed by reference'

原创粉丝点击