Top 7 Tips For a Rookie Java Developer

If once upon a time you woke up and saw your future in the Java World you would definitely use some help with the hardest part: the start. In this article, Baris Okuneu a Java team lead at Belitsoft left an early Christmas present of useful tips which will help avoid the pitfalls and raise the quality of your code to the next level.

1. Follow the coding standards In short, it’s a special set of rules that tell us how the source code should look. This includes naming conventions, directory hierarchy, source files structure, formatting and layout, code documentation etc. There are also numerous guidelines and code conventions that have been upheld for years. Some of them are:

  1. Don’t use an object to access a class (static) variable or method. Class name works better. Embedded assignments rarely help improve run-time performance. Don’t waste your time doing the job of the compiler. Avoid inadvertent wrapping of loop counters. Unless coded properly, a while or for loop may execute forever, or until the counter wraps around and reaches its final value.
By following the standards, you create a clear, readable and maintainable code that increases your productivity and decreases risks of mistakes.

2. Learn and use Collections. A wide array of standard libraries and collections is often called one of the main advantages of Java alongside its robustness, platform independence, and scalability. As Wikipedia states, the Java collections framework (JCF) is a set of classes and interfaces that implement commonly reusable collection data structures. Plainly speaking, collections are containers that store a bunch of features in a single unit and display them when needed. Source: proft.me Java is replete with collection interfaces such as Queue, List, Set, Map, and variety of implementations. What do the collections provide:

  1. Reduced development effort Increased code efficiency Reusable data structures Advanced functionality
So in most cases, it’s better to pick the right collection out of the box, rather than spend time on reinventing the wheel.

3. Empty collections vs null. This piece of advice is about a method, that may or may not return a collection of elements. For example, to implement a request, the code returns a list with specific data. One way to deal with a query to an empty list is to write a null. In this case, after running the code you’ll see a NPE (NullPointerException). An error that should be followed by a number of “if (… !=null{)”. Moreover, the programme will have to check every variable in the code over and over to make sure there are no null cases. To avoid wasting resources, Java developers take the second path – empty collections. If you return an empty collection, you can avoid null-checks in the code that uses the method.

4. Know and follow the SOLID principles. SOLID is an acronym for 5 class design principles: S — Single Responsibility Principle(S.R.P) – A class should have only a single responsibility. O — Open-Closed Principle – Software entities should be open for extension, but closed for modification. L — Liskov Substitution Principle – Derived classes must be substitutable for their base classes. I — Interface Segregation Principle – Many client-specific interfaces are better than one general-purpose interface. D — Dependency Inversion Principle – Depend on abstractions, not on concretions. Following these will make the code more understandable and grant you respect from other people who have to check your work.

5. Learn VCS branching strategy. Each feature or bugfix should be processed in its own branch. This helps to structure work, simplify the code review and makes it easy to revert changes if needed and possible to control feature delivery in time. Source: www.stackoverflow.com It’s nice to have VCS integrated with issue tracking system so that it’s easy to see what has been done in terms of a certain issue. A good example of such integration is Jira/Git/Stash. You are going to use those on real projects, so make sure you know what you are dealing with.

Understand Design Patterns. Software Design Patterns are reusable solutions to software design problems. Design patterns are formalized best practices that a programmer can use to solve common problems when designing an application. Patterns can be classified in different categories, of which the main categories are: Creational Patterns (e.g. Abstract Factory, Singleton), Structural Patterns (Adapter, Facade etc.), and Behavioral Patterns (Mediator, Observer and more). In the meantime, just when the plot goes too smoothly and well, the “bad” guy appears. In software engineering, those bad characters are anti-patterns. As wikibooks says, “In software engineering, an anti-pattern is a pattern that may be commonly used but is ineffective and/or counterproductive in practice.” Some specific examples of anti-patterns include: Singleton Overuse Functional Decomposition Poltergeist Spaghetti Lazy Class and many more.

7. 0-50-500 Rule. In big software packages, maintaining code becomes very challenging. Wrong structure design may cause Monolithic Code or Spaghetti Code. There is a simple rule to avoid that or keep the code clean and maintainable: 10: No package can have more than 10 classes. 50: No method can have more than 50 lines of code. 500: No class can have more than 500 lines of code. If these recommendations are ignored, the programme’s insides would look like that:

Conclusion So, what do we have in the end? All the above-mentioned tips are a light that leads you to explicit and effective code-writing: One. Following the coding standards, you make the outcome much more clear and maintainable. Avoid time-wasters like rookie mistakes and additional lines. Two. By learning and applying collections Oracle has been developing for decades will save you time. Three. The usage of empty collections and understanding of null prevents hours of the puzzling search and fixing. Four. SOLID principles are a sketch you use to create the correct architectural object. Five. VCS strategy turns your code writing into a well-structured process where every bugfix knows its place. Six. Patterns are like cheat codes you wish you had in real-life. Knowing them will make your code more structured, as well as help you pass technical interviews later on. Seven. This tip is one of the favorites. Like cleaning up the room, you store classes and lines accurately and primp the code using only three lines of text in mind.

Florida
Texas Plumbing
VA Licensing
CSL Exam Prep
TN
0
Cart Icon