• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..........
 
Stephan van Hulst
Bartender
Pie
Posts: 6114
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

thanks stephan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic