How to create Class in JAVA (Beginners)

Fetching Comments ...

Hello dear readers !!!

In last post I have written about types of JAVA Classes and we have studied about JAVA’s built in classes and User Defined classes. So in this lesson I will teach you that how to create classes in JAVA.

below is Syntax of creating JAVA Class :



In this syntax, “class” is a keyword to create JAVA Class and its in small characters. “CLASS_NAME” is name of class which you want to create. The basic Naming Convention of JAVA class is First character of each word should be in Capital letters. for example :

“HelloWorld”,“Test”,“Hello”,“World”. etc

if you not wrote first letter in Capital then there is no issue of error. but this Naming Convention is to easily understand/find JAVA classes. for example if your program has 500 lines, and you are checking your code then you can easily point out that which are classes in that program.

example of creating class in JAVA :

class HelloWorld{
  public static void main(String[] args){
    System.out.println("Just Testing ...");

So this is simple example of creating Classes in JAVA programming language. In this example you can easily point out that “System” and “String” both are classes, because they are written in First Capital and remaining in small letters. but if you think that “Just Testing” are also classes then you are wrong, they are String, because they are written in double qouts.

and “public”,“static” these are special keywords which are used to define anything. in this example they are defining that “main” is public and static. I will explain what is “public” and “static”, in next upcomming lessons.

Share This:

LearnPainLess On Instagram

Get The Best Of All Hands Delivered To Your Inbox

Subscribe to our newsletter and stay updated.