Your Second program

What would I do just greeting the world with Hello World ?
I wish my program could greet me as well.

Well, many of my reader are thinking such even I thought the same way...

So, breaking the traditional way of Java tutorials where after the program, it starts theory again. But, this is the last one for now and again we'll be studying some concepts. Otherwise we can't grow.

Again open Notepad, copy the following and save it in file system wth name MySecondProgram.java


 import java.io.BufferedReader;  
 import java.io.IOException;  
 import java.io.InputStreamReader;  
 /**  
  *   
  */  
 /**  
  * @author Palash  
  *   
  */  
 public class MySecondProgram {  
      /**  
       * @param args  
       * @throws IOException  
       */  
      public static void main(String[] args) throws IOException {  
           BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  
           System.out.println("Please enter your name: ");  
           String user = br.readLine();  
           System.out.println("Hello " + user);  
      }  
 }  

Now compile the program using javac MySecondprogram.java and run using java MySecondProgram


Congratulations, you have successfully instructed your machine to greet you by your own. How obedient your slave is. Isn't it ???

Next, we are going to know some theory on Object Oriented Programming...


Prev     Next
Palash Kanti Kundu

No comments:

Post a Comment