Chapter 1: Head First Java

Featured Post Image

If you are in android development,  Java could be a vital use.

The reason it’s very powerful is not because its object oriented but also the opportunities aren’t less with just this skill in hand, as it’s used in desktops, mobile and web applications.

Not only that, it’s also a platform independent, that means you don’t need to write your code again if the device running that code has the JVM installed.

In other words the java source code can run on all operating systems

I’m learning this language from Head First Java and I thought it might a good idea to share my learning as I progress with this book

I highly recommend to check out this book

But lemmi tell you one thing here, it’s not a reference book, it’s an experience,  at least the authors Kathy Sierra & Bert Bates say this in the book.

The reason I chose this is because unlike any book on java this has a very different mind friendly approach to teach things

So let’s get started by answering some of the most common questions you come across when you learn java

How does java work?


1: You write java program in the source file with the “.java extension” –> 2. And then you compile it. The compiler checks the entire file for error checking –> 3. On the step three, the compiler creates a new document, coded into Java byte code. Any device capable of running Java will be able to interpret or translate into something it can run. The compiled bytecode is platform independent. –> 4. Your friends have a running Java in the software form in their devices that makes the bytecode function.

Look how easy it is to write java

My Fav Part image

And that’s one of my favorite part in the beginning of this book

It’s sort of like how we pronounce or understand Java statements in our human language

It actually makes sense when we pronounce each situation and understand it better this way

So when somebody ask in the interview, how we write an integer type variable? and how do we assign value to it?

We can think of this table and understand the question and immediately answer it.

What goes in a source file?

A source file holds one class definition, the class represents a piece of your program. This must go within a curly braces.

You know what?, a tiny little application could have only one class!

What goes in a class?

Within the curly braces, you write your methods


The above demonstration just shows that in the Dog class, method bark will hold the instruction of how the Dog will bark.

Your method must be declared within a class or within a curly braces of class

What can you say in the main method?

Like i said earlier, in the main method you write the statements to instruct how the method should behave. Other than that you could write loops, if statements and many more things.

note: every statement must be end with semicolon

System.out.print vs System.out.println

If I write

System.out.print(“this prints on a single line”);

System.out.print(“this also prints on a single line continuously”);

The output will be

This prints on a single linethis also prints on a single line continuously

But, if this happened to be in this way

System.out.println(“This prints on next line”);

System.out.println(“This prints on a new line”);

The output will be

This prints on next line

This prints on a new line

I know you spotted the difference

But let me explain it anyway

When we are using “.print”, it will print on a single line, everything will be continually without a break

This becomes opposite when we use “.println” as this prints on a new line.

Think of “.println” as “printnewline” while “.print” keeps printing to the same line

What we learned so far, means this


Over time I have experienced that in order to learn something, it’s always a good idea to share it with others with some practical’s

So it’s time to put together everything we learned till now and build something

We are going to build a tiny application with these goals in mind

  1. We are going to have a party with having 99 beers in the tub
  2. By passing one to our friend we will say something like this “take one down” “pass it around”
  3. After we pass it, it will also let us know, how many beers are left
  4. The party is over when no more beers left

This is what we come up with

BeerParty code demonstration

I know it’s a tiny little program but to be genuine it’s just enough to understand the concept

Some of you might feel something missing in this post but I m not trying to get into everything here, I’m just posting a basic idea this chapter has, although you still might want to share your opinion here and guess what? You are most welcome to do that.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at

Up ↑

%d bloggers like this: