Matchlogger: March summary and stats!

It is April already, so it’s time for some summary on my „Get Noticed” contest results so far. Did it go as I expected?

Application

First of all, things go a little bit slower than expected. 8 commits to the repository in March isn’t a great result. By now I have a working login and an ability to add teams (which I still want to restrict so that users could propose teams and an admin needs to accept them). My immediate goals are adding matches and, of course, deployment. BTW, did I mention that I own matchlogger.com? 馃槈 I would like the application to be available to the end users as soon as possible to be able to iterate with further development.

In total, the project now has 837 lines of code:

  • Java – 14 classes, 437 LOC
  • XML – 3 configuration files, 177 LOC
  • HTML – 5 files, 158 LOC
  • .properties – 6 files, 43 LOC
  • CSS – 1 file, 7 LOC
  • .yml – 1 file, 7 LOC
  • JS – 1 file, 6 LOC
  • .md – 1 file, 2 LOC

Blogging

I wrote 7 blog posts with tag DSP2017 in March. That’s around the planned amount. The most popular were:

  • Choose your Licence, Luke! – 41 views
  • Google OAuth2 login with Spring Boot – 37 views
  • Spring Boot: saving OAuth2 login data in DB using PrincipalExtractor – 11 views.

Those three were also the most popular posts on my blog during March. Looks like if the posts are focused on explaining one topic and have examples, they are the most popular. Likely this update post won’t be nearly as interesting as those three 馃槈

Extra stats

Time spent

In March, I spent 14 hours, 11 minutes and 10 seconds on Matchlogger development (data thanks to Toggl). Further 12 hours, 24 minutes and 56 seconds were spent on blogging – mostly for this contest. That means that in total, I spent around 51 minutes daily on the contest.

Code frequency

Looks like I tend to work in bursts. Those bursts are likely the days where I didn’t have any other plans, so I spent a lot of time on Matchlogger.

Branching

I’m not using full git flow, but branch my code and merge it to master through pull requests. It is enough for my project needs. As you can see, I usually have up to two branches open. You can also notice that there’s one case where a branch didn’t get merged – that was my modern approach to Vue.js development that turned out to freeze my IntelliJ on assets lookup even before I could exclude node_modules from scanning.

Timeslots

Nothing too unexpected here. On weekends I work throughout the day (I’m writing this post at 9 am), during the working week I tend to sit and code in the evening as during the day I’m at work.

Even if not everything goes as smooth as expected, I really like my pet project. I already learned new things and it can be satisfying at a time. 10/10, would participate again.

15 things you learn about Java for OCA exam

It is fairly controversial to take Oracle’s Java certificates. One of the very vocal opponents of them in the local Java scene is Wojciech Seliga, who claims that he noticed that people with certificates performed worse at job interviews at Spartez than those that don’t have them (around 4:15). Even with such claims, I decided that I want to pass OCJP this year as I thought that it might be a good idea to review my Java fundamentals knowledge and make sure I don’t miss anything. What surprised me a bit is that with Java 8, the certification process is different than a few years ago and now one needs to first pass an OCA exam. At first, I was a bit dismissive – come on, this is just an exam that shows you how to write for loops – but then I took an example exam and scored… 25%.

So I learned. One important thing to notice is that Oracle’s Java exams test if you can be a compiler – there are multiple cases where they aim to trick you into parsing something that won’t compile. One can be surprised how much caveats there might be and that’s where a good point is to read a good book that prepares for an exam. I read a book by Jeanne Boyarsky and Scott Selikoff and highly recommend that one. The benefit of those preparations is that I structured some of the core Java knowledge – some things I haven’t yet seen in practice (thanks to Flying Spaghetti Monster!) as they aren’t usually good code examples – but at least when I see it in some legacy project in future I won’t run away screaming. Some of them are just something that’s easy and quite obvious, yet it can surprise.

Examples below aim mostly for junior/wannabe developers, but they might be a good refresher also for a developer with some experience. You can see all examples in my Github repository.

1. Can we use a different args name in main() method?

Yes, we can! The name can be any valid Java identifier.

2. Will that code compile?

Yes. We can have only one public class in the file and the file is named just as the public class.

3. What will be the output?

The output is 1. Number variable will be first assigned 2, then 3, then 1. With 3 you can see a static block initialization.

4. That’s a legal number?

A nice, fancy way to write 1000000.000222. Usually used to separate by three numbers, like int result = 1_000_000. Underscores cannot be at the beginning, end and around dot sign.

5. What will that code print?

A trick one. We abuse the fact that assigning a variable returns the variable. The result will be Hello!. It would work that way only with boolean. I highly discourage you from doing that.

6. Which statements are valid?

Line 5 is fine. Same with line 6 – we assign a value to s1 and s2 is declared without a value. Line 7 does not compile – we cannot declare variables with two types in one statement – even if the type is actually the same. Line 8 is okay, it’s just two statements in one line. Line 9 – does not compile. We didn’t provide a type for i4. If we declared i4 somewhere above with a type, it would be fine.

7. Why doesn’t this compile?

Division of two shorts gives us an int that cannot be implicitly cast to short. We need to explicitly do the casting:

8. Does this compile?

Nope. The first line is an int because it’s outside short’s range. Second one lacks an L sign at the end and is too large to be an int. BTW, did you know that you can add plus signs before numbers? Not that it’s helpful, but you can 馃槈

9. What will that code return?

Well, it won’t return anything because it won’t compile! In Java 8, one cannot switch on long and boolean types. In Java 7, switch on String was added that also previously wasn’t possible.

10. What will be the output?

The output here is:

Weekday
Saturday

Note that we use a static code block for the output. The main trick is that we put default not as the last one (as you would expect) and we forgot to put a break; there.

11. What does this code output?

1234
5

We use a label to break out of two for loops at once. Feels a bit like goto, but can be used only in certain cases.

12. Are these strings the same? What will be the output here?

true
false
true
true
true
false

In this case I’ll guide you to a good answer on string constant pool from StackOverflow. One more thing to notice is that this pool is an implementation of Flyweight design pattern.

13. Can we get a new dog? What will be the result of running this code?

Exception in thread "main" java.lang.UnsupportedOperationException
	at java.util.AbstractList.add(AbstractList.java:148)
	at java.util.AbstractList.add(AbstractList.java:108)
	at pl.mmkay.oca.Level13ListFromArray.main(Level13ListFromArray.java:12)

Arrays.asList creates an array-backed List implementation. In that one we cannot add or remove elements. We could only replace an element. That’s why we needed to create a new ArrayList to add a dog.

(That one is actually a real-life example, in a flat that I currently rent with my wife, we have a contract saying that we cannot have more than 2 pets at a time ;))

14. What will be the output here?

1
-2

It’s good to know what Arrays.binarySearch return values are. If an element is found, it will return an element’s index. If not, it will return a negative number that is

 -1 * index - 1 

where index is what would be the index of this element if it was in the array.

Important thing here is that array must be sorted beforehand! If it’s not, the results might be quite surprising.

15. Which element will stay in the list?

The only one that will stay will be 1. There are two remove methods in List class:

remove(int index)
remove(Object o)

For the first removal, the best match was the one with index. The second one looked for the right object.

That’s all, folks!

Hope you liked the examples. Now you know a bit more on how to act like a compiler.