Java: A Newbie Crash Course
Are you new to Java?
Welcome to the club!
Java can be intimidating at first with all the new terminology it uses. I learned Python first, which helped me break down Java syntax using classes and object references.
If you know Python's language, think of Java as the layers within.
Learning Python first and Java second is backward learning. It is easier because Python sets you up with named variables, strings, integers, floats, and other long-listed items. Python will define the line type for you. In Java, you are required to name the type and make sure your value for the variable is correct.
For example:
In Python, you could simply declare a variable like:
x = 1
or declare a listed variable like:
fruits = []
fruits = ["banana", "orange", "apple"].
To add to the list, you would say: fruits.append("pear") or fruits.append() = "pear", "grapes"
In Java, you would need to say:
int x = 1;
or
String fruits = 'banana', 'orange', 'apple';
String[] fruits = new String [(set a number)];
To add to the list, you would say: fruits.add('pear')
In Python or Java, whether you use single quotes or double quotes does not matter. Just keep it consistent throughout your program.
It looks the same, right?!
There are some differences between print and string statements for Python and Java.
In Python:
print("Hello, I am a newbie!")
In Java:
System.out.println("Hello, I am a newbie!");
or
System.out.print("Hello, I am a newbie!");
Differences...
This is the difference between receiving input from a user and seeing it on the same line or the next.
In Python, to receive an input:
print(input("Hello, Newbie! What is your name? "))
...
# You can place the rest of your code here
BTW, the # is an indicator to Python to ignore whatever comes after it. It means just commentary.
In Java, to receive input, it is required to have:
import java.util.Scanner;
Scanner scanner = new Scanner(System.in);
System.out.println("Hello, Newbie! What is your name? ");
String noob = scanner.next();
...
// You can place the rest of your code here.
BTW, the // is an indicator to Java to ignore whatever comes after it. It means just commentary.
If You're Ready to Dig Deeper Into Java...
Remember, I am currently a noob too!
I'm sharing how I understood some of the concepts and hope it will make your Java journey easier to comprehend.
Within some of the Java posts, you will see links to some YouTube pages that explain processes easily and some websites where you can practice coding.
And as always...
Comments
Post a Comment