Docsity

Best Practices for Java Programming: Memory Efficiency and Code Optimization - Prof. Aung, Summaries of Science education

Toggle sidebar
bg1
Ensure the code follows standard naming conventions
Class names should start with Capitals:
Employee, Student,
Make sure it handles constants efficiently
Constants help improve memory as they are cached by the JVM. For values that are reused across
multiple places, create a constant file that holds static values.
Check for proper clean Up
It is common during development to use procedures that help with your coding and debugging (hard
coded variables, for example). It is good practice to remove these items and others such as:
•Console print statements
•Unnecessary comments
•Use @deprecated on method/variable names that aren’t meant for future use
pf3
pf4

Partial preview of the text

Download Best Practices for Java Programming: Memory Efficiency and Code Optimization - Prof. Aung and more Summaries Science education in PDF only on Docsity!

 (^) Ensure the code follows standard naming conventions Class names should start with Capitals: Employee, Student,  (^) Make sure it handles constants efficiently Constants help improve memory as they are cached by the JVM. For values that are reused across multiple places, create a constant file that holds static values.  (^) Check for proper clean Up It is common during development to use procedures that help with your coding and debugging (hard coded variables, for example). It is good practice to remove these items and others such as:

  • (^) Console print statements
  • (^) Unnecessary comments
  • (^) Use @deprecated on method/variable names that aren’t meant for future use

 (^) Handle strings appropriately If you need to perform a lot of operations on a String, use StringBuilder or StringBuffer. Strings are immutable, whereas StringBuilder and StringBuffer are mutable and can be changed. Additionally, a new String object is created for every concatenation operation. Rather than creating multiple items, using a mutable object is preferred.  (^) Optimize to use switch-case over multiple If-Else statements Rather than using multiple if-else conditions, use the cleaner and more readable switch-case. Doing so makes the logic cleaner and optimizes the app's performance.  (^) Avoid unnecessary comments in code? Comments should not be used to explain code. If the logic is not intuitive, it should be rewritten.

Benefits

Enhanced Efficiency

Risk of project failure is reduced

Minimal Complexity

Easy to Maintain

Bug Rectification

A Comprehensive Look

Cost-Efficient

Risks

projects fail due to problems while developing

software.

If a code is complex, there are higher chances of it

being vulnerable to