18 February 2009

11 February 2009

Encapsulation though access control

Encapsulation does not necessarily means getters and setters. And have more than one aspects:

  • Inside structure control.
  • Input data validation.
  • Outside access control.

Lets consider 'Outside access control'.

While we directly do not know which class calls method, it's hard to limit context of (method) call. It is possible, but amount of work is to big now time.
Any way what solutions do we have?

4 February 2009

Using Strings and Objects in Switch case statements.

Lets consider enhancement on Sun Bug Database : 5012262

It's about letting us using String in switch.

3 February 2009

Memory management in Java


 
Different look on memory leak problem.

We have garbage collector in Java, but this do not prevent us from make memory to leak. What more even standard library isn't leak-free.

How can we spare memory easly?

String.intern() is one of the easiest way.

  • It do not interfere with gc.
  • It's fast.
  • Multi thread safe.
I just need to check if .intern() work with .substring(...)

Where we loose memory quietly?

Most Classes created to store high amount of dynamic data have their own memory menage system. ArrayList, StringBuilder, ... they all allocate *2 memory. Which mean that is we have 1024 elements and need to add one while no free space is available then space will be extended to 2024.

How much memory do we loose?

Calling .trimToSize() can spare approximately 10% of memory.
On String.intern() I used to save up to 70%.

2 February 2009

1 February 2009

Genesis of Programming

Wikipedia: Tower of Babel

1 At one time the whole earth had the same programming language and vocabulary. 2 As people migrated from the asembler, they found a valley in the land of Shinar and settled there 3 They said to each other, "Come, let us make libraries ." They had objects for stone and patterns for mortar. 4 And they said, "Come, let us build ourselves a language and a standard library with everything programmer can need under the sky. Let us make a name for ourselves; otherwise, we will be scattered over the face of the whole earth."

5 Then the marketing came down to look over the language concepts and the library that the men were building. 6 The marketing said, "If, as one people all having the same language, they have begun to do this, then nothing they plan to do will be impossible for them. 7 Come, let Us go down there and forbid them to create language so that they will not be able to create programs for all the platforms."

8 So the marketing scattered them from there over the firms on the whole earth, and they stopped building the language. 9 Therefore its name is called Babylon, for there the marketing confused the programmers of the whole earth, and from there the marketing scattered them over the face of the firms on the whole earth.