How to create java class
In this post, we are going to learn about how to create java class, using NotedPad++. You should set your language to Java. You can easily find the menu "Language" on the top menu bar.
Step 1. Write codes to create class
It is formal definition of declaring a class called "Customer". Let me break it down a bit from the bottom.
1. public is an identifier. Its main purpose is to set visibility of a class. To put it simply, it is about whether any other classes can use this class or not. Then, public means that this class can be used or interacted with other classes. In most cases, a class
has public identifier which means that it can be used or interacted with others except for singleton class. Basically there are three types of identifiers which are Public, Private, Protected. More on identifier and singleton class later…
2. class is keyword by which you basically tell that it is class !!!!. Whenever you declare a class, you have got to put this keyword "class" before class name otherwise the program is not able to identify your class.
3. Customer is class name. It is simply the name of your class. Notice that all class name must be capitalized.
※ When you have more than one word for
attribute, class and method name, it has got to be Camelcased. For example, public
class Soccer Player à public class SoccerPlayer. Do not put space between the two words.
You can make the first letter of second word upper case. It is basic Java convention, you must follow.
4 {} is basically for telling the start and end of a class. Therefore, all attributes and methods
should be between the brackets.
Step 2. Write a code for attributes of a class
As you an see, i have declared three attributes for this class. They are formal definition of creating attributes in Java. It is actually organized into attribute type + attribute name + actual values for it.
※ You have also got to put identifier before attribute type, but this is lesson and i don't want you to be confused with too many new technical terms and definitions rules. So I am going to describe it in more detail on the next tutorial
1. String, int, String are the types of attributes. When you want to create a attribute for a class, you have got to declare the type for it. String is for the attribute to have number and character values. In this case, this attribute has got value called "Mika". int is for integer value. In this case, the attribute "balance" has got value of "10".
2. name, balance, address are simply the name of my attributes. You don't have to capitalize the name.
3. When you declare String attribute, you have got to have " " between your value.
4. Lastly, you have got to put semi colon at the end of your attribute definition so that the program identifies the end of it.
Post a Comment