Learning New Java Concepts Using The Beginner’s Mindset

Samuel Teixeira
2 min readSep 23, 2021

--

I have to watch basic Java as part of a Master that I started. I’ve been working with Java for some years and I would prefer to not have this kind of basic course but I can’t skip it (this the life). I am not saying I know everything about Java and this is why I decided to open up and use the beginner mindset in it.

Photo by Nicole Wolf on Unsplash

We can learn more when we are willing to do it.

Is it possible in a basic Java coding exercise to learn new concepts?

I could say YES. I learned from a beginner exercise two new concepts, but only because I wanted to go further.

This is the code that I had to create for the first exercise of this discipline:

As you can see we have one Class with only five methods (including the main), only one as an instance method. I did this pretty fast and started to think if I had to prove that this was working as intended, what would I do? The answer is what I do in my daily work, we create tests, in this case, it could be a Unit test.

Testing the static methods is not that difficult, we just call the method with the correct argument and check the result. I am using Junit, so we can call the assert methods and check the results.

The same for the instance method, I created a method to setUp the instance of my class and I could use it in the itTestWasOjGuilty test.

I hope you still reading because now is the interesting part.

how do I know that by sending the input to my main function, the result would be the desired output to the user?

I started the search on how to capture the main output and how to provide input to scanner functions.

Is possible to use the PrintStream with ByteArrayOutputStream to get the System output, and use InputStream to simulate the user input when running the program?

This is the test for the Film Rating, getting the user movie name, and movie rating, and displaying to them: Move rating is 5.

The full test class is like this.

I never needed to do this kind of test and was a good surprise to see how easy it is, at least for a simple Class like this exercise. I feel now that I need to keep investing time to learn using the beginner mindset to learn more and more because we learn something new every day.

--

--

Samuel Teixeira

Developer (15+ years) | Staff Engineer at IAS | Master of Computer Science | Interests — Backend Dev , Machine Learn, Code performance, System Design