Take a look at how printing hello world in Java is different from in python. Click The Code to edit it
As you can see, it takes a bit more code to print "Hello World" in Java. But why?
What you may notice at first is that stuff surrounding it you don't exactly understand
Don't Worry About that right now, we will discuss that stuff another day.
The Part you probably do understand is the System.out.println("Hello World");
It has that print thingy! very similar to the one in Python
But Wait! Why does it say println in Java,
but print in Python????
Thats a good question
In Python the print() function:
prints the specified message
Then it moves the cursor to the next line
Let's look at an example
In Java the print() function {
prints the specified message
}
I Wonder What Would Happen If I ran this Code...
In Java, System.out.print(); prints what's inside the ()
In Java, System.out.println(); prints what's inside the () and then moves the cursor down to the next line
These are called, "Curly Braces"
They are used to structure code.
Lets see an example code segment
Hey, this is similar to python. But in Python instead of curly braces ( { } ), we used Colons ( : )
Indentation is NOT required in Java.
Meaning all of the following would work (In Java not Python)
How to structure code using curly braces
Variables are containers that hold data values
__________________________________________________________________________________________________________________________________________
These are the data Types:
String
Text, such as "Hello World", or "I would like to eat a banana"
Integer
Integers (Positive and negative numbers without decimoles) Such as 6 or -7
Boolean
True or False, such as true or false
Float and Double
Numbers with decimoles, such as 4.5, or 8.7 (Floats can hold up to 7 decimole digits and Doubles can hold up to 15-16)
Character
Characters (1 letter, 1 number, or 1 symbol), such as 'T' or '?'
__________________________________________________________________________________________________________________________________________
To use a variable you must declare it
Declare it like this:
Pro Tip: Variable names must follow these rules
(I hope that website is not blocked)
Let's see it in some code
You can do operations with, and while declaring variables. See more operators
Comparisons. see more comparisons
Remember to end statements with a semicolon ( ; )
statements are executed, one by one, in the same order as they are written