Search Blog

Search duranek.blogspot.com

Wednesday, January 18, 2012

PreparedStatement vs Statement

PreparedStatement vs Statement

PreparedStatement'in java ile alakasi yok aslinda. Database server'in yaptigi
bir is. Precompilation yapiyor, execution plan'i hazirlayip cacheliyor, boylece
ileriki execute larda hizli oluyor.

PreparedStatement, ilk ucunu hazirliyor. Yani db ye iki defa gidilir.

The following occurs when a database receives a SQL statement:

1) The database parses the statement and looks for syntax errors.
2)The database validates the user to make sure the user has privileges to execute the statement.
3)The database validates the semantics of the statement.
4)The database figures out the most efficient way to execute the statement 
and prepares a query plan. Once the query plan is 
created, the database can execute the statement.

1)    Performance
2)    SQL injection'i onler. 
3)     Runtime sirasinda Parametre yazabiliriz.
4)    PreparedStatement larin tercih edilmedigi yerler daha cok memory yedigi
    icin embed cihazlar olabilir. Cok az ram'i olan.

Cross Join

What Mean SQL Cross Join ?

This is cartesian multiplication. Multiplying first
table with the second.

SELECT * FROM [TABLE 1] CROSS JOIN [TABLE 2]

OR

SELECT * FROM [TABLE 1], [TABLE 2]


Immutable Class


immutable class:

1) class must be final
2) All methods must be final
3) All members must be private and final
4) There will be no setter methods
5) Constructor is public
6) If member variable is an Object, then getObject method must return 
a new Object with same values. Don't return the reference
7) If member variable is an Object then constructor must create new Object with
the values of the object.
8) If you want to change an amount in the class for example, you always create
new Object with new value.
9) Eger member variable larda List varsa, listi get yaparken,
Collections.unmodifiableList(mOBList);
yapacaksin. Listenin icindekiler de immutable olmak zorunda.

Tuesday, January 17, 2012

Flyweight Pattern ( Structural )

Flyweight Pattern ( Structural Design Pattern )

1) Iskambil Oyunu yapacagiz. 52 Tane kagit var. Bu 52 kagitta 4 tip olur. 
   Kupa Karo Maca Sinek
   Her birinden 13 tane var. 
   Eger iskambil kagidi bir obje ise, o objenin hem tip hem de numara variable'i olacak.
   Basite indirgeyelim. Her variable 1 byte olsun.
   52 kagit icin, toplam 52x2 = 104 byte yer gerecek.
   Fakat Her tipi obje yapip, variable'lara o objenin referansini versek,
   52 kagit var, numaralar icin 52, tip icin 4 olacak, boylece 56 byte yer ayiracagiz.
   Her tipi de ihtiyac oldugumuz zaman yaratsak, performans da cok hizli olacaktir. 
   Bunu map ile yapiyoruz.
2) Bu durumda, FlyweightFactory class'i, bize istenen tipi dondurecek. Icinde bir map olacak.
O map te tip varsa dondurecek, yoksa yaratacak, yarattigini map'e atacak ve dondurecek.
Burada da flyweight tip oluyor.


Monday, January 16, 2012

RMI in 2011

RMI in 2011

1) Java to Java ya limited.
2) Bir tarafta yapilan degisikligi diger tarafa da deploy etmek
lazim. serilizationVersionUID den dolayi. Load balancer'larda
daha da sorun cikartabiir.
3) RMI son donemlerde pek dikkat cekmiyor.
4) Performansı iyi.
5) Web service daha low coupling.
    

Serialization Rules

Serialization Rules 

1) Objenin full serializable olmasi icin Obje ve Super obje Serializable 
implemente edecek 
2) Superclass serializable degilse de serialize olur. 
Fakat superClass'in no-arg constructor'u olacak. 
YOksa readObject() de java.io.InvalidClassException alir. 
Bir objenin default olarak no-arg constructor'u vardir, 
fakat o objeye herhangi bir argumanli constructor yazarsaniz, 
no-arg constructor'u ayrica implemente etmeniz gerektigini hatirlatalim. 
3) Serializable olmayan superclass in 
constructor'u deserialization sirasinda calisir. 
4) Butun primitive type ler serializable 
5) transient serialize olmaz. 
6) Static field lar serialize olmaz. 
7) Serializable object'in non serializable objesi varsa compile eder 
ama runtime de hata alir.

Facade Pattern ( Structural )

Facade Pattern ( One Of Structural Patterns ) 1) Simple interface to a larger body of code. Class Library. 2) Wrap a poorly designed collection of APIs with a single well-designed API. 3) Utility Class is a facade. 4) Calling a one function for a set of functions 5) JOptionPane.showMessageDialog() ornek bir facade. AWT ile bir suru sey yazacagina kolay bi sekilde hallediyorsun. Sık kullanılan, ve terzi usulu olmayan bir isi, yani almost her zaman aynı şekilde yapılan bir işi tek fonksiyona indirmek. 6) Facade aslinda bir obje, onu yaratip onun uzerinden is yapiyorsun. Yani bir singleton gibi, yok constructor private olacak, yok getInstance static olacak gibi kurallari yok. Bir mucize aramamak lazim. Zaten herkesin dogal olarak yaptigi utility fonksiyonlarini bir class ta toplarsan, ona facade deniyor. 7) Also Facade is not the only entry point to the sub-system but is a convenient point of communication to the subsystem and client can always have the direct access to the subsystem. 8) Facade ayni zamanda singleton olabilir, birden fazla yaratilmasina gerek yoksa, ama boyle bir sart yok.