Java
In this tutorial we will learn about Classes in Java programming language.
Java is an Object Oriented Programming OOP language and so the code we write are all in classes.
We have been using classes since the beginning of this tutorial series. Now lets talk about what classes are in detail.
So, open your favourite Java IDE and lets write some code.
A Class in Java is a wrapper that wraps data and methods that acts on that data.
To create a class in Java we use the class keyword.
class
class ClassName { // some code... }
Where, ClassName is the name of the class.
ClassName
Remember the following points when naming classes.
while
break
Following are valid class names.
class HelloWorld { } class FindAverage { } class Super_User_Account { }
Following are invalid class names.
// can't start with digit class 123 { } // can't use space class Hello World { } // use of special character like * is not allowed class *Hello { }
Lets say we are writing a Java program for a company that handles packaging of items in boxes.
So, for this we can create a Java class by the name lets say PackagingBox and our code will look like the following.
PackagingBox
class PackagingBox { // some code... }
In the next tutorial we will learn about member variables that will help us to store data.