Java is a versatile language that is great for beginners. Learning to code in Java is also fairly easy to learn how to use and has many applications. Java is an Object Oriented Programming (OOP) language. This means that by defining objects using Java we can create our own variable types. If you are new to java coding feel free to check out my other pages on what an IDE is and how to download one, how to use jGrasp, and how to use Eclipse. I will be using Eclipse to show you how to start coding.
Take this very confusing looking piece of code:
This is where we will be starting:
When coding in Java you need to understand that the code is linear so, the code will be read by your computer from top to bottom. But it always starts with the main method. I will explain in more detail later about methods but for now just know it is where you put code that is going to be run.
Our First Code in Java
The most simple program that one can write when one wants to code in Java, and the standard for most introductory courses, is a program that outputs the word “Hello World”. To do this you set up your class like so:
Then you write the command: System.out.println(“Hello World”); in the main method, like so:
This is telling the compiler that you want to print what is in the quotes to the console. When you run the code this will be output to the console:
Make sure that you do not forget the semicolon. Semicolons are very important when you code in Java and it is important to pay attention to when they are needed and when they are not.