----------------------------------------------------------------------------------------------------------
strictfp是指:strict float point 精確浮點
如果希望浮點去處精確且跨不同的硬件平臺而可用些關鍵字。
要點:
該關鍵字可用於限定類、方法及接口。
不可用於構造函數及接口的方法。
----------------------------------------------------------------------------------------------------------
Java的Serialization機制:Java對象實現Serializable接口,後可將之序列化,序列化後可將之存儲於硬盤或傳之於網絡。在某種情況下,比如,將用戶信息對象傳送,其中的密碼是敏感信息,故不希望序列化之。transient用於Java對象序列化時限定某一成員變量,使之不被序列化。
DEMO:
public class TransientDemo implements Serializable{
private static final long serialVersionUID = -7119218349702402135L;
private String userName;
// private String password;
private transient String password;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
String path = "C:"+File.separator+"object.txt";
System.out.println(path);
File file = new File(path);
TransientDemo demo = new TransientDemo();
demo.setPassword("lotus");
demo.setUserName("jungle");
ObjectOutput output = new ObjectOutputStream(new FileOutputStream(file));
output.writeObject(demo);
ObjectInput input = new ObjectInputStream(new FileInputStream(file));
TransientDemo readedDemo = (TransientDemo)input.readObject();
System.out.println(readedDemo.password+":"+readedDemo.userName);
}
}
----------------------------------------------------------------------------------------------------------
volatile的價值:
線程同步價值最小化!
線程同步的代價,顯而易見的是,其覆蓋的代碼域越大其代價越高。而volatile是變量級別的同步,故該關鍵字可以極大的降低同步代價。
待續。。。。
Java關鍵字之strictfp、transient及Volatile
最新推荐文章于 2021-03-13 20:04:06 发布