A First Java Program

A First Java Program
SYNTAX TO DEFINING A CLASS: -

class Identifier
{
Member Definition
}

JAVA Program: -

					 
					 public class FirstProgram 
					{ 
						public static void main(String args[]) 
						{ 
							System.out.println("Sunil kumar"); 
						} 
					} 
				
				
public: -

To make main () method global because to execute this class must be accessible by JRE.

static:-
When a member is declared static, it can be accessed before any objects of  its class is created, and without reference to any object.
void : -
In C/c++ we can write “int main” but in java we don't why?
Ans: - c/c++ program is run by Microprocessor via compiled form means compiled program firstly load into program counter which is part of Microprocessor and after microprocessor run that whole loaded program. In c/c++ at last we return int to microprocessor to tell it program is executed successfully.
But java is platform independent so “jre” run the program not only that even it checks the output result of program for security purposes so there is no need to tell or instruct them about the successfully compilation notification.
So we write only void together with main() method.
main() :-
            The main() method is where your program starts running.

String : -
Because string is easy to access all types of data types values means string can take float, int, double values in easily and it is easy to convert into other format.
Now take this “System.out.println(“Sunil kumar”);”
Here System is class and println is method.
Now about out.
Generally println() is not method of System Class, it is method of different one lets have look in example.
										   
										   class PrintStream // print() & println () methods of PrintStream class
											{
												public void print(String s)
												{
													:::::::::::::::::::::::::
												}
												public void println(Sting s)
												{
													:::::::::::::::::::::::::::
												}
											}
											class System
											{
												public static Printstream out;
												:::::::::::::::::::::::::
											} 
										   
										   
										   

So, System.out.println(“Sunil Kumar”);. We got resultant stuff.

 



 

Latest Tutorial


Most Visited Tutorial