I’m really newbie in Java Programming
Hi…greeting. At least 5 months ago I started to learn Java programming. The very basic Java. Here I will share all knowledge I’ve got. But if I do so many mistakes here, please pardon me…
Or you can also give me suggestion, to make myself better. Thank you for read this articles.
Java language is one of most popular machine languages. It is commonly use to make applications.
Java is categorized into 3 editions:
1. J2SE (Java 2 Platform, Standard Edition): to make desktop and applet applications.
2. J2EE (Java 2 Platform, Enterprise Edition): to make multitier applications enterprise scale.
3. J2ME (Java 2 Platform, Micro Edition): to make applications in micro environment like hand phone and PDA.
To make programs with Java language, your system requires software Java 2 SDK, which could be downloaded in sun website.
Also, need software to make program such as NetBean, Eclipse, etc.
Now, I’ll start to introduce parts of the languages.
- Java programs are built from classes. (classes which made inside package)
Note: one package contain some classes
- A class is a template to build objects and contains members of the following type:
Fields – Data belonging either to class or object of the class.
Methods – Collections of statements that operate on fields.
Classes – Nested or inner classes defined inside a class.
Here the syntax to make class:
TypeOfClass NameOfClass{ Body; }
Note: in Java syntax for give name, forbidden to using space.
While for the body, contain: Fields, Constructor, Methods
Here the Syntax for:
- Fields: TypeOfVariabel nameOfVariabel;
- Constructor: nameOfConstructor (parameters if necessary){ code; }
- Methods: typeOfMethod NameOfMethod(parameters if necessary){ code; }
Let’s just started with a simple program.
This is the very easy program, print words. Start with make package and classes.
public class Lesson {
Lesson(){
}
public void PrintWords(){
System.out.println("This is it");
}
public void PrintWords(String words){
System.out.println(words);
}
}
package lesson1;
public class Main {
public static void main(String[] args) {
Lesson l = new Lesson();
l.PrintWords();
l.PrintWords(“This word”);
}
}
We made package named lesson1 and contain of 2 classes. First class is Lesson. There is a constructor Lesson(){} with methods public void PrintWords(){ System.out.println("This is it"); } and public void PrintWords(String words){ System.out.println(words); }
Which System.out.println will print in monitor the sentence written inside (“”);
While method used parameter String words mean it will print data type String, which the data input in main class. The data is value of variable “words type String”, that we can give in main class.
So for make it works, need a class that contain main method such this: public static void main(String[] args) {}
Then to call methods we have made, we need to make a new object to call it. Here the object is “l”. It is made in class Lesson with constructor Lesson(); more or less written with this syntax:
Lesson l = new Lesson();
To call the methods, use syntax like this:
l.PrintWords();
If we run the program, it will show result like this:
This is it
This word
Ok, I guess that’s all I could share today. Hope it helps…^_^V
”Never stop learn, never stop share”