Menu

Java Programming Tutorial


Java is an object-oriented programming (OOPs) language.

Object-oriented programming is a methodology to design a program using class and object.

About this tutorial

In this tutorial basically, we provide different Java programs that helps a beginner to write java program easily and create a java project of his own.

Tools needed for run Java program

Java programming Example

Examples are better than 1000 words. Examples are often easier to understand than text explanations. So in this tutorial we only provide the example.

Let’s start with a simple Hello World! program

Hello world program

public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello world!");
}
}

import java.lang.*;

It is used to Import predefine classes and interfaces which contain methods.This process is called package insertion.A package is a collection of predefined classes and interfaces.

public class HelloDemo

We should declare class(interface) with public modifier to access within entire application or in different package.We have to use class keyword subsequent with class(interface)name.

public static void main(String[] args) { }

This is a main() method. JVM start execution from this line.We have to write same [public static void main(String[] args)] while declaring main() method.

Public is an access modifer which is accessable by JVM.Static is a key word.

Here main() method is declared as static means It can access only static variable which is declared out side the class but we can't create veriables out side the class but JVM may internally provide static variable which is accessed by the main() method.

void is a return type and its menas return nothing because we know java is platefome independent and no need to return value to operating system or JVM.

main is the special user define function. Though it is user define but We can't change the name.

String[] args means we create a string type array. It is useful when we pass the value through command line while execute the program.

Note : args is an array name therefore it is treated as an idetifire means we can change the it and put any name.

System.out.println("Hello World!");

This is output statement.We use print() or println() method to print the message or value of variables.

print() method is define under predefined class System (under PrintStream). print() method is called through out object which is also predefined.

we can create own output object which call print() method.

Example

PrintStream myprint = new PrintStream(System.out, true);
myprint.println("Hello World!");








Subscribe with us to get latest topic update






Choose a Language



Subscribe