Disclaimer!
If you find any mistakes in this post or you don't know what to do at a specific point? Feel free to write me a comment! π
Greets from Germany βοΈ
How to install the IDE | Next part |
---|---|
<- Download, install and launch the IDE | #02 Variables and Arithmetic Operators -> |
1. Create our first class
Now that we have created our project, we need to know how to create our classes, where we gonna put in all the code we write.
A) Simply open your project by clicking on the little arrow left from the name.
B) Then click on the folder called "src"
C) Now click on the top bar on "New Java Class"
Now you will come to this screen:
Noticed what I entered in Package? Just type in the same if you don't know what to enter or just leave it blank.
Now enter a name. In my case I used the name "Main", because it is our main class in this folder (From there, we gonna control the entire program in the future).
After this step, your screen should look like this:
2. The actual coding
Now we have done all these steps, we can start to program. At the beginning we just place in this text inside the two brackets:
public static void main(String[] args){
}
This is our main method. Inside this we can run everything we want.
Don't forget to save! With the shortcut CTRL + S or STRG + S we can save it faster.
Then we have to add some code inside our main method, so it has something to run. The best code you could give him for the start is the following one:
System.out.println("Hello World!");
So it should look like this
Save this code by pressing CTRL + S or STRG + S and run it by pressing the key F11 on your keyboard. Now the console will print out the following line:
Congratulations! You have print your first line! ππ
Now we want to go one step further, by putting the same code, one line below.
Don't forget to save! It is really important to save your code every time when you have done something!
Run this code again by pressing F11
... and what does the console saying now??
Now we can talk! Two lines printed Hello World!! We can do it as often as we want, but just think of your processor in the background. If it isn't the best one than the chance is high, that Eclipse just crashes.
But there is also one another form of this code:
System.out.println("Hello World!");
... namely this one:
System.out.print("Hello World!");
As you might see, the ln
at the end just disappeared.. and what does it mean to our program? The ln
at the end stood for line. Without this, we don't go to the next line after executing this instruction. After executing, this would look like this:
Not very fancy. But now you know how you can print text out to your console. Whether on the same line or on another line.
Support this project by upvote this post and commenting ^^
How to install the IDE | Next part |
---|---|
<- Download, install and launch the IDE | #02 Variables and Arithmetic Operators -> |
Remember: I'm not a genius too! I'm 16 years old but I know quite a lot, because Java or programming in general is fascinating me so much (and yes I have friends and other hobbies :)). So don't give up! Follow you dreams and in some day, they will get true.