您的位置:首页 > 移动开发 > Objective-C

Read notes for core java: Objects and classes

2010-04-28 14:53 543 查看
 

Due the data types in java are all referrence type,we must follows as bellows:

 

1. not to write accessor methods that return referrences to mutable objects.

2. always use clone whenever you need to return a copy of a mutable data field.

  

    example:

    class Employee

    {

         . . .

         public Date getHireDay()

         {

              return (Date) hireDay.clone();

         }    

         . . .

     }

 

Method parameters


 

The method paramters in java is always passed by value. Object references are passed by value.


 

1. A method cannot modify a parameter of primitive type( that is, numbers or boolean values);

2. A method can change the state of an object parameter;

3. A method cannot make an object parameter refer to a new object.

 

Private keyword


 

Variables must explicitly be marked private or they will default to being package visible.

 

The Class Path


 

The javac complier always looks for files in the current diretory, but the java virtual machine launcher only  looks into the current directory if the "." directory is on the class path. If you have no class path set, this is not a problem--the default class path consists of the "." directory. But if you hava set the class path and forgot to include the "." directory, your programs will compile without error, but they won't run.

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息