my dog learned polymorphism*
The moose likes Java in General and the fly likes How to make my code more fast, secure and robust ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to make my code more fast, secure and robust ?" Watch "How to make my code more fast, secure and robust ?" New topic
Author

How to make my code more fast, secure and robust ?

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

Recently I have started putting emphasis on making my applications run faster as well as take advantage of all the cores in the CPU , but this is new area of learning for me , can any experience guy who has gone through this help me to accomplish this ?
alL I want to learn is
1. How can I make sure that my programe will take utilization of all the cores in any CPU ?(I Guess just creating multiple Threads will not solve this problem ?)
2. How can I make sure that my programe will take minimum memory ?
3. And finally how to write a robust more secure code ? (which is tough for other peoples to break)

any books, suggestions, articles on the net is most welcome
thanks..........


The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

naved momin wrote:1. How can I make sure that my programe will take utilization of all the cores in any CPU ?(I Guess just creating multiple Threads will not solve this problem ?)

Find places in your program that can be parallelized, and you can submit them as tasks in an executor service. However, this is usually only useful for responsiveness of the program, and not necessarily for absolute speed, since there is an overhead in using multiple threads. Save this for big tasks, such as handling requests or transactions from remote clients, and not for nano-optimizations such as performing a merge-sort concurrently.

2. How can I make sure that my programe will take minimum memory ?

Just program neatly and in a simple manner, and memory usually takes care of itself. If you jump through silly hoops to increase performance (either memory use or speed), you usually end up hurting performance instead. Make sure that variables you don't use anymore go out of scope, and you don't accidentally save them somewhere. Breaking up big methods in smaller ones that do simple things helps with this.

3. And finally how to write a robust more secure code ? (which is tough for other peoples to break)

Write simple methods with a clear contract, enforce the requirements in the method (by throwing exceptions when necessary) and program defensively. You should read Jushua Bloch's Effective Java to learn a lot about writing good clean code.
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692


thanks stephan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make my code more fast, secure and robust ?