First program of any programming language is hello world
So here’s a twist
I will take a input from user and display it on screen…..
Basically it’s an stage which usually come after 3-5 steps of starting to learn it
But as you had already seen basic program in c/c++
So just let’s start
First open text editor and write this code in it.
Program code :
import java.util.Scanner; // importing header file for taking input
class input // name should be same as the filename you are going to save with .java extension
public static void main(String args) //don’t get confused now as you will get to know about those words later …..
Scanner input = new Scanner (System.in); // creating object of the scanner class for taking input
String name; //declaring string variable type to store input in it
System.out.println(“Enter your name: “);
name = input.next();
System.out.println(” Hello “+name+” !!!”); // + is used to concatenate hello with variable name
Enter your name: vicky
Hello vicky !!!
Save this file as input.java
To run this program
Open your cmd window I’m assuming that you have installed java packages in your os
Enter this command in cmd
javac input.java now hit enter
It will compile your program.and create a new file input.class
To see output
java input now hit enter
Then you will get the output as shown above….
Go ahead and try doing this simple program and if some queries come to your mind feel free to ask.