Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Monday, July 30, 2012

CJ-10: Print a message 5 times-While loop

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************
import java.io.*;
class loop1
{
public static void main(String args[])
{
int i=0;
while(i<=4)
{
  System.out.println("Welcome to JAVA");
  i++;
}
}
}
=========================================================================
Output :
Welcome to JAVA
Welcome to JAVA
Welcome to JAVA
Welcome to JAVA



CJ-9: Odd or Even checking

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************
import java.io.*;
class oddeven
{
public static void main(String arg[])
{
   int number;
   try
   {
      DataInputStream x=new DataInputStream(System.in);
      System.out.println("Enter a number :");
      number=Integer.parseInt(x.readLine());
      if(number%2==0)
      {
System.out.println("Number is Even");
      }
         else
         {
    System.out.println("Number is Odd");
}
    }
catch(Exception e)
{
}
}
}
=========================================================================
Output :
Enter a number :
7
Number is Odd


Sunday, July 29, 2012

CJ-8: Print Day according to number

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************

import java.io.*;
class day
{
public static void main(String args[])
{
   int n;
   try
   {
DataInputStream x=new DataInputStream(System.in);
System.out.println("Enter a number upto 7");
n=Integer.parseInt(x.readLine());
  switch(n)
  {
                case 1:
System.out.println("Sunday");
break;
case 2:
System.out.println("Monday");
break;
case 3:
System.out.println("Tuesday");
break;
case 4:
System.out.println("Wednesday");
break;
case 5:
System.out.println("Thursday");
break;
case 6:
System.out.println("Friday");
break;
case 7:
System.out.println("Saturday");
break;
default:
System.out.println("Invalid Number");
break;
}
}
   catch(Exception e)
   {
   }
}
}
=========================================================================
Output :
Enter a number below 8
7
Saturday





Saturday, July 28, 2012

CJ-7: Check whether eligible for vote

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************
import java.io.*;
class chk
{
public static void main(String args[])
{
int age;
try
{
   DataInputStream x=new DataInputStream(System.in);
   System.out.println("Enter age :");
   age=Integer.parseInt(x.readLine());
if(age>=18)
{
System.out.println("Eligible for vote");
}
else
{
System.out.println("Not Eligible for vote");
}
}
catch(Exception e)
{
}
}
}
========================================================================= 
Output : 
Enter age :
20
Eligible for vote.




CJ-6 : Four Calculations-Floating no

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************
import java.io.*;
class math1
{
public static void main(String args[])
{
 float a,b,result;
 try
 {
  DataInputStream x=new DataInputStream(System.in);
  System.out.println("Enter the first number :");
  a=Float.parseFloat(x.readLine());
  System.out.println("Enter the second number :");
  b=Float.parseFloat(x.readLine());
   result=a+b;
   System.out.println("Addition = "+result);
   result=a-b;
   System.out.println("Subtraction = "+result);
   result=a*b;
   System.out.println("Multiplication = "+result);
   result=a/b;
   System.out.println("Division = "+result);
 }
 catch(Exception e)
 {
 }
}
}
========================================================================= 
Output : 
Enter the first number
12.24
Enter the second number
12.28
Addition=24.52
Subtraction =-0.03999996
Multiplication =150.30719
Division=0.99674267

Refer Four Calculations-Floating no also.




CJ-5 : Four Calculations-Integer no

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************
import java.io.*;
class math
{
public static void main(String args[])
{
int a,b,result;
try
{
DataInputStream x=new DataInputStream(System.in);
System.out.println("Enter the first number :");
a=Integer.parseInt(x.readLine());
System.out.println("Enter the second number :");
b=Integer.parseInt(x.readLine());
result=a+b;
System.out.println("Addition = "+result);
result=a-b;
System.out.println("Subtraction = "+result);
result=a*b;
System.out.println("Multiplication = "+result);
result=a/b;
System.out.println("Division = "+result);
}
catch(Exception e)
{
}
}
}
========================================================================= 
Output : 
Enter the first number
8
Enter the second number
4
Addition=12
Subtraction =4
Multiplication =32
Division=2


Refer Four Calculations-Floating no also.







CJ-4 : Sum(user defined values)

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
*********************************************************************************************
Refer Sum(predefined values) also.
*********************************************************************************************
import java.io.*;
class Adduser 
{
public static void main(String args[]) 
{   
     int a,b,sum;
     try
{
DataInputStream x=new DataInputStream(System.in);
System.out.println("Enter two numbers :");
a=Integer.parseInt(x.readLine());
b=Integer.parseInt(x.readLine());
sum=a+b;
System.out.println("Addition= "+sum);
}
   catch(Exception e)
   {
   }
}
}
========================================================================= 
Output : 
Enter two numbers :
30
20
Addition=50.



CJ-3 : Sum(predefined values)

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
************************************************************************************
Refer Sum(user defined values) also.
************************************************************************************
class Add 
{
public static void main(String args[]) 
{   
     int a,b,c;
     a=20;
     b=40;
     c=a+b;
     System.out.println("Addition="+c);
}
}
=========================================================================
Output : Addition=60.



Friday, July 27, 2012

CJ-2 : Welcome Program-Window Application


For a complete list, click JAVA


Refer Introduction to JAVA before going through your first program.

And for theory part , refer "Some Theory Part in JAVA"

=========================================================================
class firstprogram
{
public static void main(String args[ ])
{
System.out.println("Hai...Welcome...");
}
}
=========================================================================
  • Here, firstprogram is the program name.(See, class firstprogram ).The name after declaring the class , is the program name.We have to use the same name , while saving.
  • Also note the capital letters of the words String and System. They are case sensitive.
Instead of typing the program  in NOTEPAD or DOS prompt , here , we are using some softwares like NETBEANS or ECLIPSE etc..
========================================================================= 

(A) : Familier with NETBEANS platform:

Download NetBeans IDE 


Download NetBeans from here for free. (You need JDK or Java Development Kit for installing NetBeans . If you have no Java platform on your system , download from here (which contains JDK+NetBeans ) .



When clicking this , we get  :


We will get a window as shown below :




Click ; File--> New Project.
Then we can see,



Select JAVA from Categories;  and JAVA APPLICATION from Projects.
Click , Next .
Then , another window will appear as : 


Give a project name , and click Finish.
Then we can see the NetBeans IDE for typing the program.It will look like ;



In our program , we need to type the last println statement only.
The sentenses like /**/  does not tken by the Compiler.So, no need to bother about the extra sentenses you see there.
After typing the println statement to display "Hai....Welcome..." , we have to run it.
right click on the page , and select Run the File , from the drop down menu( or , select from the main menu....or , you can use ShiftF6).
The output will displayed in the bottom....as ; 



=========================================================================

(B) : Familier with ECLIPSE platform:

When clicking this , we get  :  


After giving the details as done before , we can see the Eclipse IDE for typing the program.
I just did the programs and you can see the output there.
(It is also more or less same as NETBEANS , so i just skip the steps for taking the Eclipse IDE here....)


Monday, July 23, 2012

CJ-1 : Welcome Program-Consol Application


For a complete list, click JAVA

Refer Introduction to JAVA before going through your first program.

And for theory part , refer "Some Theory Part in JAVA"

=========================================================================
class firstprogram
{
public static void main(String args[ ])
{
System.out.println("Hai...Welcome...");
}
}
=========================================================================
  • Here, firstprogram is the program name.(See, class firstprogram ).The name after declaring the class , is the program name.We have to use the same name , while saving.
  • Also note the capital letters of the words String and System. They are case sensitive.
Type this program in NOTEPAD.


Then , save the program in the same folder , in which the JAVA software is installed.
Here, I installed the JAVA in C disk , jdk 1.3 is the version and bin is the directory.
So , the path is C:\jdk1.3\bin .
(Note the path of the JAVA of your computer.So dont blindly follow the path I described :)


Note the path in above picture.
And it saved as firstprogram.java .

Next, open DOS .


Choose the path in which JAVA is installed..
To do this , follow the steps given.
  1. Type cd\ and press entre . Then we get C:\>
  2. Now choose the directory in which JAVA is installed. Here , my path is jdk 1.3\bin. So, type cd jdk1.3\bin .Then we get , C:\jdk1.3\bin>
  3. Now , compile the program , by typing, javac followed by program name. Here, our program name is firstprogram . Dont forget to put the extension .JAVA  . That is we have to type , javac firstprogram.java
  4. Then Run the program by typing , java followed by program name . That is , java firstprogram.
Then we get the result : Hai...Welcome...
 See the picture below : 



(You can save the JAVA programs in any of the Directory you want , but you havr to give the JAVA installed directory thereafter , using the path command.That is ,

  1. First choose the program directory in DOS prompt.
  2. Then choose the JAVA installed directory , followed by path command.
That is , after giving the location of your program path , type : 
path jdk1.3\bin>

Then compile and run the program.

How to use DOS platform to type\save\edit JAVA:

  1. Type cd\ and press entre . Then we get C:\>
  2. Now choose the directory in which JAVA is installed. Here , my path is jdk 1.3\bin. So, type cd jdk1.3\bin .Then we get , C:\jdk1.3\bin>
  3. Now type , edit followed by the program name.java ( Here, edit firstprogram.java )
Then we can see ;

We can edit the same NOTEPAD program in DOS prompt too...

If we give a new name , then we can type new program in that DOS prompt, then SAVE it in the JAVA directory as told before .

File--> Exit will return to the normal DOS prompt.