The java syntax may seem hard for beginners, but it can be learned using some simple rules.
In my last post you learned about lists which are sometimes useful in programming.
There are a few that allow you to follow the java syntax easily, if you apply them all:
Math and String every other object you use needs to be imported like this:import path.ObjectName;List out of the java standard library the import statement will look like this:import java.util.List;class name {…};.type variable;type variable = someValue;Object variable = new Object(…);variable = someValue;doSomething(…);variable = getSomeValue(…);return;return someValue;break;continue;( { [) there has to be a corresponding closing bracket() } ]) somewhere in your code and you cannot have structures like (…{…)…}.{…} every time you are using if, else, while, foror when creating a function:if(someThingIsTrue) {…}else {…}while(someThingIsTrue) {…}for(int i = 0; i < length; i++) {…}returnType functionName(…) {…}{ in front of it.public static void main(String [] args) {…}type variableName = someValue;type variableName;
…
variableName = someValue;
Here you can see a small program that is syntactically correct(by the way it can draw fractals, but that doesn't matter here):
As you can see in the image, there is a way to declare multiple variables of the same time in one line:
type name1 = someValue1, name2 = someValue2, …;
Or without initial assignment:
type name1, name2, …;
I wouldn't recommend using these for beginners, but they can be sometimes more readable, when used for variables of the same context like x and y.
I think structures like these are what confuses newcomers the most. They are not essential to programming, but they are sometimes used to simplify, but for people who don't know them they can be confusing.
That's why I will try not to include them here too often.
Just write a program that is syntactically correct and have fun with it!