- Open Command Prompt ( cmd).
- Type cd\jdk1.6\bin then pres enter
- After that type javac demo.java press enter.
- Now type java demo and press enter
Copy below program and paste in notepad save with this name “demo.java” with double qoutes in bin folder
import Java.lang
class demo
class demo
{
public static void main(String g[])
{
System.out.print(“this is my first program”);
}
}
public static void main(String g[])
{
System.out.print(“this is my first program”);
}
}
Output: this is my first program
Discription !
Import : import word is used to call the package .It same work as #include do in c/c++ to call library function exp. (printf() ,clsrc(), scanf, cout(), cin() getch(); etc..)
Java.lang : This is default package no need to define in the program.
Class demo : In object oriented programming language every thing is done within the class. In the above program “demo” is a class.
public static void main(String g[]) :
System.out.print(String g[]) : Basically this statement is used in Java to print the value on the screen. To print the statement (“the text goes here..! within the in the double quote”);
“System ” is a class, “out” is a inbuilt object of class, “print” is a method of “System” class
What is package, class /interface and library function
Package //package collection of class, package contain classes
Class/interface //class/interface is collection of function, class contain function
Library function
How to Indentify Package, Classes, and function,
While writing the program, there becomes a problem to indentify to package , classes and function. And in which manners they must be written. There is following some point by using that, you can easily identify and write these words.
Package : All character in the package must be in small letters. Exp. (import.java.lang etc..)
Class/Interface: Only first character will be capital of class name Exp.(System, String g[], etc..)
Function: Only first character will be small of first word and first letter of else word will be capital. Exp. (print, readLine etc..)
- The above program must be saved with name “java.demo” in bin folder
- The file name and class name must be same(the class name used in main method)
- Every statement in program must be end with ; “semi colon” excluding conditional statement. Exp. (loop stateme
No comments:
Post a Comment