A common question asked by new developers starting out, especially during the first few months of learning, is ‘when does it start to get easier?’
The reality is it never really gets ‘easy’, but with experience it does get easier. When you’ve seen enough similar problems and previously worked out solutions before, that knowledge and experience helps you approach new problems.
A completely new problem that you’ve never seen before obviously takes more time and effort to work out an appropriate solution. A problem that you’ve already seen before takes less time because you’re able to apply the previous knowledge and solution.
The point where things start to get easier is where you’re able to pull from previous similar problems that are different from the current problem you’re working on, but enough knowledge and previous experience helps to find a solution to a completely new problem.
When do you reach this point? It varies for everyone, it depends what you’re working on. If you’re working in an environment where you’re working on very similar problems day after day, you’re not encountering enough variety to grow your experience so will take you longer. If you’re lucky enough to be working in an environment when you’re exposed to a broad range of problem types, then you’ll develop your experience quicker.
Float and double types in Java are approximations – they don’t represent exact values. This is by design to allow faster calculations of approximate values at the cost of exact accuracy.
If you are new to Java, at some point you will run into this, or you’ll come across someone else you work with who may tell you to never use floats and doubles to represent Money, but maybe you’re not sure why. The reason is because of how floats and doubles represent approximate values.
If you’ve never come across this before, try this experiment:
float result = 0.01f + 0.01f + 0.01f;
You would expect this calculation to represent 0.03, but if you compare the value of result with 0.03f you’ll find this snippet of code unexpectedly prints false:
This is a common error when starting out with Java:
DefaultValues.java:5: error: variable example might not have been initialized
In Java, Class instance properties are initialized to default values if not explicitly defined with an initial value. For local variables however (e.g. variables local within method or a block scope), default values are not automatically assigned, meaning that you must explicitly initialize them otherwise you’ll see the compile error above.