5 Things Only Experienced Devs Can Teach You About Java
An overview of everything you need to know before diving deep into developing Java.
Join the DZone community and get the full member experience.Join For Free
there are numerous tools, methods, environments and features that change the way you handle your code, that you usually don’t come across during school years. while it offers the first foot through the door in the java development world, most of the actual learning happens on the job.
in the following post, we’ll go over some key elements you only learn about as you get more experienced. these will include the basics and mix in some philosophy. get your notebook ready, it’s back to school time.
congrats, you’re about to fudge up
while learning to code we face pure problems: figuring out how algorithms work, identifying the right data structures to use and knowing how to fix the code that we wrote ourselves. however, the real world has a lot of new issues that we’ve never encountered before: adjusting your code to fit the coding standards of the team, understanding someone else’s code and… finding the best taco truck in the neighborhood.
the first line of code we’ll write will probably be different than the 10,000th one, since we learn, adjust and develop along the way. as part of this process we might fail or fudge up big, and that’s ok since it’s a part of any learning curve. but there are a few things we can be ready for in advance, to try and minimize the destruction of the code, db or application we’re working on.
write, merge, debug, repeat
every engineer knows that coding is a big part of the job, but writing it is probably the easiest part. it’s the adjustments and elements around it that make it a challenge. there are a lot of topics to cover here, but we decided to focus on those you can actually learn in advance, starting with:
1. merging files
it might sound basic, but there are a lot of ways to mess this up. one of the most common actions you’ll come across is a merge. it’s the action of joining two (or more) development histories, text files, arrays or any other objects together. for example, committing a whole branch is pretty basic, but what if you only want to commit some of it? you better learn how to actually do it before you mess up everyone’s hard word. that’s why it’s important to know what’s going on in this process, being able to see and understand the code before hitting commit.
you can go for the manual method, actually looking at the files, identifying the changes and see how they might affect the code, or you can choose a tool that helps spot the changes. there are a number of tools you can use, such as intellij idea’s conflict resolution tool , kdiff3 , meld , guiffy , kompare and others.
2. understanding the debugging process
once your code is out and in the wild, or at least running on your development environment, it’s time to see if it actually works. the debugging process itself is pretty basic, but in order to make it even more helpful, you need to focus on your logs.
there are different levels to choose from:
- trace : most detailed information.
- debug : detailed messages that are written to the log.
- info : runtime events that are visible on your console.
- warning : message about potential problems.
- error : unexpected conditions.
- fatal : severe errors.
while there are frameworks that write these messages for you, it’s important to give as much information as possible, to know how to handle and solve different issues.
first of all, you need to identify the correct level of each message. for example, use debug to log anything that happens in the program, to better debug your code and understand what’s going on before sending it to production. use info to know which actions are created by users, and use warn to mark events that might end up as an error, if you’d like to keep track of them and of course.
second, make sure you give your logs as much information as needed. sure, right now you know what this means:
but you have to think about your co-workers trying to understand your code. you don’t want them calling you up during your vacation asking what car you’re talking about, and you don’t want to find yourself 2 years from today wondering what you were thinking while writing this. treat your code the way you’d like to receive it – with as much information as possible, so others will know how to handle it.
also, if you practice good logging skills you’re bound to make everyone do the same.
3. using exceptions for your advantage
there are a lot of exceptions in java, and recently we’ve published a collection of tips and insights for handling a number of java exceptions . but how can you use exceptions for your own good in the development stage? through breakpoints.
you can manually set breakpoints for thrown exceptions, and mark where execution should pause when you are running your application in development. whenever a breakpoint is executed, a message will be printed in the debugger console with the relevant information needed.
it’s like a pause button for your application, that lets you inspect and see exactly what happened up until that point. there are different types of breakpoints that stop the execution of your application it reaches a certain method, class, variable or line of code – so you can play and test as you wish.
on the other hand, if you’re looking for a tool that will help you know when, where and why your code breaks in production , you can try overops. it’s the only tool that shows you the complete source code and variable state across the entire call stack for every exception, logged warning, and error. check it out .
4. handling a production environment
after all the hard work, you’ve deployed your code and it’s live in production. if you’ve written meaningful log messages you’ll be able to know when an exception is thrown, but sometimes it will be harder to understand why it actually happened.
one of the things you have to keep in mind when moving over to production, is this gap. we’re not talking about rail passengers and trains, we’re talking about your local environment vs production. this is the recipe for numerous errors that’ll waste your time trying to figure out where they came from, and why.
you need to understand why these environments are different, and how you can deal with this gap. if you’re looking for some advanced java debugging techniques, check out this post . another way to configure applications for multiple environments can be implemented with docker, and you can read a quick guide for it here .
5. thinking about future teammates
we’ve got 2 words for you: backwards compatibility. imagine this: you have java 8 installed on your machine, while production runs java 6, and you don’t understand why things are breaking. or maybe one of the customers is running an old version of the application and your newest feature doesn’t work for them. it’s a sticky situation that can be avoided easily.
you need to keep in mind that each team has a past, and a list of decisions that were made long before you arrived. that’s why you have to think of the past in order to move forwards (we said we were gonna get philosophical, right?).
when writing new code, take the time to test, identify and fix whatever might break old versions of the app. it’ll help you along the way, and will make everyone happier since they won’t have to face old or even surprising bugs for big customers that are not willing to update their application version.
the hardest part of the job is getting in the zone. we’re not talking about that morning pick-me-up cup of coffee, we’re talking about productivity hacks that will boost you work and help you do it even better.
there are a number of things you can use, such as special bash scripts, self-made command line hacks or even special tools to help you monitor everything better. if you’re looking for some tips and tricks, check out a few productivity tips we’ve gathered from the java community .
the hardest part is getting started. it doesn’t matter if it’s the first day of a new job, or even a new blog post about it – there’s a lot of research and learning during this process. don’t be afraid to ask as many questions as you have, since it’s the best way to understand how the team, code and application works.
if you have any other key features for new employees you think we’ve missed, we’d love to hear about them in the comments below!
Published at DZone with permission of Henn Idan, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.