refresh java logo

Basic terms in java program

This tutorial will cover brief description about some of the basic terms used in a java program. The detail description will be given in later sections. For beginners it's necessary to understand these terms.

java programming terms

Keywords - Every programming language defines a set of words which has a predefined meaning in that programming language. These words are known as keywords. You can not use these words for variable names, method names, class names or any other identifier names, as these are reserved words. Java has also defined some words which programmers uses while writing java program. These reserved words has a predefined meaning in java programming language syntax.

For example, in statement int a = 10, int is keyword which represents the data type of variable a. You can not use int keyword as your variable, method or class names. Similarly class, public, static, void are java keywords in above program. You can refer Identifier Naming Convention section to see the list of all java keywords.

Are keywords case sensitive in java ?

Yes, keywords in java are case sensitive. All letters of keyword must be small.

What if I use keywords as my variable, class or method name ?

Your program won't compile, hence you will not be able to run your program.

class - class is a keyword which is used to define a class in java. In java every program must have a class. A class contains set of methods and variables. After class keyword programmers need to write the name of the class, as in above program MyFirstProgram is the name of class. Everything that is inside balanced {} after the class name are the part of class. You will get more detail about class in later chapters.

Statement - A statement is similar to a sentence in english language. As sentences makes a complete idea, similarly java statement makes a complete unit of execution. In above program line 5,7,8 are statements.

Method - A method is set of statements that performs specific task or call other methods. It has a name and signature. Everything before the name of method is known as signature. A class can have multiple methods. In above program main is the method name and public static void is it's signature. Everything that comes in balanced {} after method name are the part of method. Every java program must have a main method if it needs to be run independently. main method is the starting point of execution of a program in java. You will get more detail about methods in later chapters.

block - A block is a group of zero or more statements. it starts with curly braces { and ends with balanced }. All statements inside balanced {} is the part of block. A block is generally used to group several statements as a single unit. A block can have another block inside it.

public - public is a modifier that decides the visibility or accessibility of variables or methods. As main method is called by JVM at the time program execution that is why it should be public, otherwise JVM won't be able to find the main method in your program and your program will not execute. It is also a keyword in java.

static - static is a keyword in java. A method or variable declared with static keyword can be called without creating the object of that class. As main method is called by JVM without creating the object of class, that is why it should be static, otherwise JVM won't be able to call the main method.

return - return is also a keyword in java. It is used to return value from the method to the caller of the method. Every method must have a return type, if it's not returning anything then return type of that method should be void. As main method doesn't return a value, so it's return type is void.

Parameter - A parameter is special kind of variable which receives the value from the caller of the method. A parameter can be used within the method in which it is declared. In above example args is a parameter of type String array. Any argument passed to program while running, is stored in args variable.

Variable and data type - Variable in java is very similar to variable in mathematics, used to store value. Data type of a variable defines what type of data that variable can contain. In above program a is a variable and int is it's data type, which means a can contain only integer type value.

System.out.println() - It is used to print the output on console. Anything passed to println method will be printed on console. A console is basically a window or terminal where you can pass input to program or print the output of a program. Command prompt(cmd) in windows acts like a console.

After reading this tutorial you may have got some understanding about basic terms in java program but still you may have number of questions, don't worry we will get to know more detail about these terms in later chapters.

  • All letters of method name main that need be called by java JVM must be small, can not use Main, mAin, maiN etc.
  • Every method name must be preceded by return type of method. Use void in case method is not returning any value.
  • Every method name must be followed by (). A method may or may not contains parameters.
  • The name of parameter args is programmers choice, you can rename it as well, but it's type must be of String array.