Tuesday, September 15, 2009

Program to check two object of the same pojo same class having same valur or not

//This is Pojo class with two property name and email
class PojoBean {
private String name;
private String email;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}


}
// main class to test pojo object
class PojoMain
{
public static void main(String[] args)
{
//create first instance of the Pojo Class and set property values.
PojoBean pBeanOne = new PojoBean();
pBeanOne.setName("Pushpa");
pBeanOne.setEmail("ashish@gmail.com");


//create second instance of the Pojo Class and set property values.
PojoBean pBeanTwo = new PojoBean();
pBeanTwo.setName("ashish");
pBeanTwo.setEmail("ashish@gmail.com");

//code to check two object is having same data or not.
if(pBeanOne.getName().equals(pBeanTwo.getName())){
System.out.println("Two object is having same Name");
}
// second property email
if(pBeanOne.getEmail().equals(pBeanTwo.getEmail())){
System.out.println("Two object is having same email");
}



}
}

Read data from console and print in one file.

//Read data from console and print in one file.
import java.io.*;
class ReadDataFromConsole
{
public static void main(String[] args)
{
try{
String fileStr = ""; // declare a string variable
for(int i = 0; i'<'args.length; i++){ // for loop start with argument size

fileStr = fileStr + " " + args[i];
}


//create an instance of the random acces file "rfile'.
RandomAccessFile rfile = new RandomAccessFile("C:/Temp/text.txt","rw");
// write object into the file.
rfile.writeBytes(fileStr);


}catch(Exception ex){
ex.printStackTrace();

}
}
}

Tuesday, August 18, 2009

Fibonacci Series

class FibonacciNumbers
{
public static void main(String[] args)
{
System.out.println("Hello World!");
if(ContainNumber.onlyNumbers(args[0])){
int number = Integer.parseInt(args[0]);
int num1;
int num2= 0;
int num3 = 1;
while(number>0){
System.out.println(" F Series : " + num2);
num1 = num2;
num2= num3;
num3 = num1+num2;
number--;
}

}


}
}

//Program to Find Factorial of given number

class FindFactorial
{
public static void main(String[] args)
{

if(ContainNumber.onlyNumbers(args[0])){
int number = Integer.parseInt(args[0]);
int result = 1;
while(number>0){
result = result*number;
number--;
}
System.out.println("Factorial of given number : " + result);

}
else{
System.out.println("Enter number is not positive integer");
}
}
}

Friday, August 14, 2009

programe Compare Two No

import java.io.*;

class CompareTwoNo{
public static void main(String[] args) {
try{
int num1 = Integer.parseInt(args[0]);
int num2 = Integer.parseInt(args[1]);

if(num1'/<'/num2){
System.out.println("Number " + num1 +" <" + " Number " +num2);
}
else
{
System.out.println("Number " + num1 +" >" + " Number " +num2);
}
}
catch(Exception ex){
ex.printStackTrace();
}
}
}

Monday, May 4, 2009

Draw Triangle


Problem Statement:
Draw a triangle for a given size, using given character and pointing toward given direction.

Language:
Java

Platform:
Command Prompt

Command:
[Program] -size [Size] -char [Char] -direction [Direction]

Expected Input:
[Size]: Any positive integer. Error should be printed if non-positive integer or string is given.
[Char]: Any single char. Error should be printed if more then one char is given.
[Direction]: R/L/U/D for Right / Left / Up / Down. Error should be printed if any other input is given.
Note: The order of parameters may change.
Hint: First make programme with fix order of parameter to get a working code. Then attempt to process the command line input for parameter reordering. This approach is known as modular approach for programming.

Expected Output:
Print the triangle of given size in given direction using given character. See example for better understanding.

Example:
Interface:
$ java DrawTriangle -size 5 -char A -direction R
Output:
A
AA
AAA
AAAA
AAAAA
AAAA
AAA
AA
A

Saturday, May 2, 2009

Make Table


Problem Statement:
Write a program to generate a table of given number from command prompt.

Language:
Java

Platform:
Command Prompt

Command:
[Program] [Input Number]

Expected Input:
[Input Number]: Any Integer (positive or negative)

Expected Output:
Table of given integer from 1 to 10.

Example:
Interface:
C:\Program> java table 5
Output:
5 X 1 = 5
5 X 2 = 10
5 X 3 = 15
5 X 4 = 20
5 X 5 = 25
5 X 6 = 30
5 X 7 = 35
5 X 8 = 40
5 X 9 = 45
5 X 10 = 50

Thursday, April 30, 2009

Input from Command


Problem Statement:
Take input from command prompt.

Language:
C and Java

Platform:
Command Prompt

Command:
[Program] [Input]

Expected Input:
[Input] : Any Message
Note: message is always separated by Space!

Expected Output:
Message 1: [Input 1]
Message 2: [Input 2]
...

Example:
Interface in C:
C:\Program> ./read_cmd.exe reading from cmd
Interface in Java:
C:\Program> java read_cmd reading from cmd

Output (Same for both C and Java):
Message 1: reading
Message 2: from
Message 3: cmd

Hello World


Problem Statement:
Print "Hello World" on screen.

Language:
C and Java

Platform:
Command Prompt

Command:
[Program]

Expected Input:
None

Expected Output:
Hello World

Example:
Interface in C:
C:\Program> ./hello_world.exe
Interface in Java:
C:\Program> java hello_world

Output (Same for both C and Java):
Hello World

Fundamentals of Computing in IITK

Course website of Java Programming for 1st year BTech Students in IIT Kanpur.


You can find lectures, tutorials and assignment in proper sequence for learning.

Welcome

Dear Readers,

Programming is simpler then you really think... But in case, if you think that programming is not as simple as I think, then you are at right place. If you want to learn or revise programming, then this blog may help you. Here we will be posting the programming task and you will find solutions in the comment sections as it will be solved by us. This is because I am making this blog by writing each program one by one and revising my programming skill as well.

Good Luck.