It’s time to write some Java code, but first make sure you’ve completed the Java setup.Before you go ahead, you need to learn something, so for every Java file it will appear with extension. And it is a case-sensitive language, so ensure whatever you write is cross-checked. Without further ado let’s jump to write code.

Where to Write Code, & Basic Prerequisite to know

We will be focusing on the Main.Java, Here you go…

  • Under Project Directory you will find Src and within the Src directory you have your Package name. There you have your Main where you have to write code.
  • 1st line of code shows where you are writing your code.
  • Next line will be Class, In java we write code under class. **So whatever you have you have to write it should be under class and fall under the same class. (You can rename or change it accordingly, and The file will be saved .java extension which appear on the top of the tab.)

  • Under Main Class or any Class, the code referred as Functions **A function is like a piece of code that does some work, like if you press the Num key on your keyboard, it will enable the Num keypad. It’s like you have commanded it to perform a certain task with instructions to finish the task..
  • Whenever a code is been executed, Function Call used. We will first learn about Main function, later will cover what are the methods, and how you can create more functions.
  • What written in Grey or with // its called Comment. Which isn’t a part of the code, and will be ignore by the complier while executing the project. **For your own help, you write whatever you want accordingly in your language. 
  • To write the comment in multiple line use, Start with /**/ and press enter in the /**/ To better understand refer to the down image.

How to Write Hello World

We are beginning to write our first program, and the first thing that we are going to write is Hello World. A simple program, and everyone’s favorited code to start with.

  • Let’s Start with writing the output statement System.out.println(“Hello world!”);
    Here, println itself is a function. Which to be written under class. Therefore, We also use ” (Semicolon) to indicate our line is end.
  • To execute the code, if you are the first time user you might don’t be able to run from the Run button which appear on the upper-right because you haven’t choose which file you have to run. For this, Use the Navigation bar on top, and then Click on Run and Choose the 2nd Run option. Unless you do this, the Run won’t be executing and will be showing the Grey. Either you can use the Alt + Shift + F10
  • Choose the File you want to Run, Choose Main.

  • Your code output will be on the bottom, and Yes we have successfully Run our Hello World.

Note: code which doesn’t have any errors. Our exit code will be 0 if there is any error, and the code will be 1.

Things to take away

Instead of using println you can also use print  and output will be same but there is a slight difference. There won’t be any line-space. So whenever you use println there will be a line-space and with print there won’t be any.

Another thing is, a quick command to use Print. Simply write sout and then enter tab to enter.

So it help you to make things easier, and don’t require to write the statement (System.out.println();) respectively.

So. this is how you can write codes and some basic things you need to remember in Java Syntx. You can lear more things by clicking on the following link to jump on the tutorials. We are open to feedback, we try to improve the article by updating do comment and share you feedback in the comment section down below.