filmov
tv
NEVER WRITE CODE LIKE THIS | Top Common Mistakes by Java Developer Best Coding Practices Code Decode
Показать описание
In this video of code decode we have covered top programming mistakes done by experienced java programmers and best coding practices also
Udemy Course of Code Decode on Microservice k8s AWS CICD link:
Course Description Video :
Not using Transparent and User-Friendly Naming Conventions
Before you get too deep into your project, make sure you give clear names to classes, interfaces, methods, and variables.
Remember, big software projects can have lots of different teams working on them. So, it's really important to agree on one way of naming things. That way, everyone is on the same page and it's not confusing.
Not using Transparent and User-Friendly Naming Conventions
Here are some simple guidelines for creating clear and easy-to-understand names in your code:
Classes: Use only nouns, and start their names with a capital letter.
Packages: Use all lowercase letters for package names.
Interfaces: start with a capital letter and capitalize each new word.
Variables: You can mix uppercase and lowercase letters in variable names.
Methods: Use verbs for method names and capitalize the first letter of each word.
Empty Catch Blocks
In Java, we use try-catch blocks to deal with problems that might happen in our code. We put the code that might cause issues inside the "try" block, and if something goes wrong, we use the "catch" block to handle it.
Imagine if something unexpected, like dividing by zero or not finding a file, happens in the "try" block. The "catch" block helps us manage these problems.
Now, it's technically possible to have an empty "catch" block, but it's a bad idea. An empty "catch" block doesn't tell us what went wrong in our code, which makes fixing bugs much harder. So, it's better to have a meaningful "catch" block that provides information about the problem.
Using String For String Manipulation
The main difference between StringBuilder/Buffer and regular String objects is that String objects cannot be changed once created (they're immutable), but StringBuilder/Buffer objects can be modified.
Now, there's a thing called the "String Constant Pool." When you create a String object, it takes up some memory in this pool. If you change the String, it creates a new memory space each time you make a change, which isn't efficient and wastes memory.
On the other hand, StringBuilder and StringBuffer objects are allocated memory in the computer's main storage area (HEAP) just once. When you modify the text in them, it changes within the same memory space, which is more memory-efficient and avoids waste.
Ignoring DRY & KISS Principle
DRY = Don’t Repeat Yourself
KISS = Keep It Simple Stupid
DRY is a basic principle of software development aimed at reducing repetition of information. The DRY principle is stated as, “Every piece of knowledge or logic must have a single, unambiguous representation within a system.”
Divide your code and logic into smaller reusable units and use that code by calling it where you want. Don’t write lengthy methods, but divide logic and try to use the existing piece in your method.
KISS is a design principle which states that designs and/or systems should be as simple as possible. Wherever possible, complexity should be avoided in a system — as simplicity guarantees the greatest levels of user acceptance and interaction.
Hibernate Interview Questions and Answers:
Spring Boot Interview Questions and Answers:
Subscriber and Follow Code Decode
#commoncodingmistake #codedecode #bestcodingpractices
Udemy Course of Code Decode on Microservice k8s AWS CICD link:
Course Description Video :
Not using Transparent and User-Friendly Naming Conventions
Before you get too deep into your project, make sure you give clear names to classes, interfaces, methods, and variables.
Remember, big software projects can have lots of different teams working on them. So, it's really important to agree on one way of naming things. That way, everyone is on the same page and it's not confusing.
Not using Transparent and User-Friendly Naming Conventions
Here are some simple guidelines for creating clear and easy-to-understand names in your code:
Classes: Use only nouns, and start their names with a capital letter.
Packages: Use all lowercase letters for package names.
Interfaces: start with a capital letter and capitalize each new word.
Variables: You can mix uppercase and lowercase letters in variable names.
Methods: Use verbs for method names and capitalize the first letter of each word.
Empty Catch Blocks
In Java, we use try-catch blocks to deal with problems that might happen in our code. We put the code that might cause issues inside the "try" block, and if something goes wrong, we use the "catch" block to handle it.
Imagine if something unexpected, like dividing by zero or not finding a file, happens in the "try" block. The "catch" block helps us manage these problems.
Now, it's technically possible to have an empty "catch" block, but it's a bad idea. An empty "catch" block doesn't tell us what went wrong in our code, which makes fixing bugs much harder. So, it's better to have a meaningful "catch" block that provides information about the problem.
Using String For String Manipulation
The main difference between StringBuilder/Buffer and regular String objects is that String objects cannot be changed once created (they're immutable), but StringBuilder/Buffer objects can be modified.
Now, there's a thing called the "String Constant Pool." When you create a String object, it takes up some memory in this pool. If you change the String, it creates a new memory space each time you make a change, which isn't efficient and wastes memory.
On the other hand, StringBuilder and StringBuffer objects are allocated memory in the computer's main storage area (HEAP) just once. When you modify the text in them, it changes within the same memory space, which is more memory-efficient and avoids waste.
Ignoring DRY & KISS Principle
DRY = Don’t Repeat Yourself
KISS = Keep It Simple Stupid
DRY is a basic principle of software development aimed at reducing repetition of information. The DRY principle is stated as, “Every piece of knowledge or logic must have a single, unambiguous representation within a system.”
Divide your code and logic into smaller reusable units and use that code by calling it where you want. Don’t write lengthy methods, but divide logic and try to use the existing piece in your method.
KISS is a design principle which states that designs and/or systems should be as simple as possible. Wherever possible, complexity should be avoided in a system — as simplicity guarantees the greatest levels of user acceptance and interaction.
Hibernate Interview Questions and Answers:
Spring Boot Interview Questions and Answers:
Subscriber and Follow Code Decode
#commoncodingmistake #codedecode #bestcodingpractices
Комментарии