Yawn, teach me how to write my first Java program, asshat!

How does one write their first java program?

We are going to make our computer say,

Hello Human, I am your servent..

I’ll do as you please!

I bow down to you master. 

But (I like big butts and I cannot lie, sorry I can’t stop singing that song).. but before that, we need to do some shit called “setup” for writing our first java program.

Your first Java program is going to look lengthy and wordy compared to other programming languages such as Python. So, I say fuck setting up your computer for now. Heck, Java’s “hello world” scares off people even if it is dumb easy just due to sheer length. Now, if I made you download a bazillion files and made you follow 10 different step to set up things, you are going to run the fuck away. 

My intention is to show you, Java is a fucking easy language. It’s not C++ which you’re only qualified to write if you’re a nerd with no sex life (ba dum diss). So, I suggest you go over here. 

An online coding environment will save us from so many steps that will come between you and your code. Fuck that for now. 

You talk a lot, show me the code 

Okay. Just in a bit..

See.. a java program has a structure to it that looks like,

Screen Shot 2018 08 06 at 11.41.14 PM - Yawn, teach me how to write my first Java program, asshat!

So, a java program is a bunch of thingies called classes that have code inside. That’s all to it for now. 

How does one define a class?

All you need to do is use a class keyword. 

class myClass{

//code

}

Okay, how does one write the program you mentioned above?

public class IAmTheBoss {
public static void main(String args[]) {
System.out.println("Hello Human, I am your servent..");
System.out.println("I'll do as you please!");
System.out.println("I bow down to you master.");
}
}

In JDoodle it’ll look like this if you hit the execute button. 

Screen Shot 2018 08 06 at 11.49.40 PM - Yawn, teach me how to write my first Java program, asshat!

Explain the code, please

I knew you’d ask. Let’s break down the code. 

Iteration 1

public class IamTheBoss{

}

This is our class definition. The public here is something called access modifier. Ignore what that means for now. Just think of it like our class can be accessed from anywhere within the same folder if it’s set to public.

Iteration 2

public class IAmTheBoss {
public static void main(String args[]) {

} // main ends here
} //class ends here

Java programs require something called the “main method” to run. The class that has this main method is called the main class. You need one main class in your java program.

Now methods are synonymous with functions. But if you don’t know what “function” means don’t sweat it. We’ll have a whole article on that. 

public static void main(String args[])  is a way to define the main method in java. Now, each of the words there such as static, void, String etc. have certain meanings which we’ll explore in some other article. For now, just understand that it’s needed to define the main method thingy. You don’t need to rote memorize it either. If you type main and press tab on Jdoodle, it’ll generate the code for you. 

Iteration 3

public class IAmTheBoss {
public static void main(String args[]) {
System.out.println("Hello Human, I am your servent..");
System.out.println("I'll do as you please!");
System.out.println("I bow down to you master.");
}
}

System.out.println displays the output on the screen. If you type println and press tab on Jdoodle then it’ll generate the whole thing for you. println means the thing you want to display is going to be printed on a new line. So, you could do System.out.print but everything would be on the same line. 

There’s a reason behind x.y.z kinda shit in Java. It means z exists inside y which exists inside x. So, System.out.print thingy means that the “print” function resides inside “out” which further resides inside the “system”. 

So, what else can I do?

I suggest you play around with Jdoodle. And see what works and what does not. And subscribe/bookmark to this blog to read more articles on Java.

What the hell is Java programming language?

What is Java? Isn’t it coffee or something?

The Java(TM) is programming language which is a bit different from coffee java as you might have guessed. 

If you search for “Java” in Wikipedia.org, it’ll answer the following

Java is an island of Indonesia. At about 138,800 square kilometers, the island is comparable in size to England.

And if you click see Java (programming language), it’ll return

Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented. It is intended to let application developers “write once, run anywhere” (WORA) meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.

The first definition seems like it was written in English. It’s easy to understand. The second one seems like it was written by someone whose third or fourth language is English. It seems like it was written by someone who’s been a professional Java programmer for a while and has lost the sense of how new students find it hard to decipher the technical jargon.

But it’s still more readable than what’s in the official docs at least.  You probably skimmed through it  and are like “Okay.. so it’s a programming language and you can write it once and run it anywhere whatever that means.” And some words such as “concurrent” flew right over your head. 

If you have never programmed before. Or you just had some introductory QBasic and C shit. A lot of words in there don’t fucking make sense. 

What in the hell is a general-purpose programming language? Is it another way of saying that it’s a mainstream programming language and not for hipsters? 

What the hell is object oriented? Does it mean that Java is sexist and treats women as objects?

What is the actual hell is recompilation now? And this recompilation thing, is it that bad? Why is it bad? Maybe it’s good. Who the fuck knows?

 

Let’s define Java the way we’d like to

All those jargony words. They mean something in their own context. Those are some fancy features of the language which we don’t need to understand right now so fuck it. 

I’d say .. 

Java helps humans write instructions for machines such your laptop, mobile phone etc. so that we can make the machine do whatever the hell we want to. Like every other programming language in the observable universe.  

Sure, it has its own way of doing things with those fancy sounding words. And this “my way or the highway” attitude of Java can be a gift or a curse depending on the situation. It can be a gift because you don’t have to think much about things yourself. The language will dictate how you write and organize your code. It can be a curse when you feel like thinking outside of Java’s opinionated box. 

 

Enough Talk. How do I make this Java thingy make my computer do something for me? 

Well, we’ll look into that in the next post. Be patient. We’ll use and abuse this so-called programming language together to make our computers do shit for us. Until then chug some coffee and call Oracle service center and ask them if chugging a mug of coffee is the proper way to download Java.