java code updated

better structure - same functionality