A Java class is a group of Java methods and variables.

Each Java source code file can contain one public class. The name of this public class must match the name of the Java source code file. If the public class is called "HelloWorld", then the filename would be "HelloWorld.java".

A sample Java class is written below:

 public class HelloWorld {
  private String name;

  public HelloWorld(String name) {
    this.name = name;

  public void sayHello() {
    System.out.println("Hello " + name);

  public static void main(String[] args) {

    HelloWorld hw = new HelloWorld("Java Tips");