package com.example.PracticingJava
public class HelloWattpad{
public void displayHelloWorld(){
System.out.println("Hello World");
}
public static void main(String[] args){
HelloWattpad hello = new HelloWattpad();
hello.displayHelloWorld();
}
}
===============================
Result:
hello world.
==============================
package
package is the folder where your file is located. Classes is stored inside the package.
public
public is a modifier. A modifier is for the availability of your program. This is the means on how everyone is controlling or shall I say hiding their program from those hackers. This public modifier means that your program can be access by anyone. This means that anyone can use it. So, it is better to avoid using public if not needed. There are other types of modifiers which will be discuss later. Note, the code above should be enclose in a class which has a modifier too.
class
class is like a blueprint of the object. For example, the blueprint of your house.
HelloWattpad
HelloWattpad is the name of the class. You can name the class with any name you want. It usually begins with capital letter as a naming convention but it is not required.
static
Static is used by the class. You used the class name to access the function or variable and not the object created from the class.
void
Void means no return.
displayHelloWorld
displayHelloWorld is the name of the function you created. Just like the class, you can name it whatever you want. The naming convention is to use a camel case letter, which is small letter for the first world and the rest of the word or words begin/s with a capital letter.
main
Main is a name of the function. You can name the function any name you want except for the main. All java programs always start with the main function.
HelloWattpad hello = new HelloWattpad()
This is how you create an object by using the keyword new. The hello is the name of the variable with a data type of HelloWattpad. You are creating an object of HelloWattpad class in here.
hello.displayHelloWorld()
You can call the function displayHelloWorld by using the object hello with the dot connector. The dot connector is use to call the fields and methods of the class.
String
String is a data type but not part of the primitive data type. This is more like an object or class or an array of characters.
[]
This Bracket symbol means that the variable you creating is an array of variables.
args
args is just a name used for that data type String. Others used argv or any name.
{}
This Braces symbol signifies that this is where you can find the body of the function or a class. Opening brace is where it starts and Closing brace is where it ends. You put your code inside the body. Just like the code for printing the hello world.
System
System is a class from a library of classes. Common functions such as printing or encoding of text in a command prompt is place in this class.
out
out is either a static method or an inner class of the System class. An inner class is a class within a class. I'm not sure if out is a method or a class but you used the same dot connector to call or invoke a method or an inner class.
println
println means printing the text inside the quotation marks in the command prompt. This means that you want to display the text in your screen. This is a method use for printing or displaying text.
==================================================
Note: The above keywords with definition might kind of vague. For much clearer explanation, please do visit the tutorial link of oracle that included.
YOU ARE READING
Java Programming
Randomhttps://docs.oracle.com/javase/tutorial/ This is the link where I learned my java lessons online. I choose java as first programming language. I am a career shifter. I just want to start something new. I choose to write it here in Wattpad so that I...