Learn basic java from basic,learn basic java from basic, learn java from basic, understand java program from basic, pass string to java program, pass number to java program, java basic dynamic program, accept number and print using java program, accept name and display message java dynamic program, java type casting programming example
Hi friends in this blog post i am sharing with you java basics concepts this is day two tutorial .
in assignment one we are going to print simple hello word message
in second program we are going to pass string parameter to java program and
in third assignment we are going to pass number parameter .
to understand you must know the
basic structure of java program
lets understand basic structure of java program
java program start with class name java class as shown in following program
we use class ClassName { }
(remember class name always start with Capital letter below eg )
in class we use to write
in class we use to write
public static void main(String args[])
main is a starting point of java program contains parameter as array of strings i have given name args you can use as s , p , a as you wish , value contain args is string value
as first value find in args[0], you can pass n number of values to java program
Save as One.java
public class One{
public static void main(String args[])
{
System.out.println("good one \n ");
System.out.println("good Morning \n");
}
}
open cmd
javac One.java
java One
2)Java Program to print simple message
accept user name
(string Value) as a parameter.
Java program to accept username dynamically and
display good morning massage to that name
Save as Two.java
public class Two{
public static void main(String args[])
{
System.out.println("good morning"+args[0]);
}
}
javac Two.java
java Two Prakash
utoput : good morning Prakash
3)Java Program to accept number as argument and print it
Save as Three.java
class Three{
public static void main(String args[])
{
int a;
int add=0;
a=Integer.parseInt(args[0]);
System.out.println("Number entered= \t"+(a));
}
}
javac Three.java
java Three 10
outoput : Number entered 10
Comments