Friday, 19 December 2014

List of Java Programs
1. Program1 – WAP to display the List of even numbers
2. Program2 - Factorial of a number
3. Program3 - Compare Two Numbers using else-if
4. Program4 - Determine If Year Is Leap Year
5. Program5 - Fibonacci Series
6. Program6 - Palindrome Number
7. Program7- Generate prime numbers between 1 &
given number
8. Program8- Pyramid of stars using nested for loops
9. Program9 - Reversed pyramid using for loops &
decrement operator.
10. Program10 - Nested Switch
11. Program11 - Calculate Circle Area using radius
12. Program12 - Factorial of a number using
recursion
13. Program13 - Pyramid of numbers using for loops
14. Program14 - To Find Maximum of Two Numbers.
15. Program15 - To Find Minimum of Two Numbers
using conditional operator
16. Program 16 - Write a program that will read a
float type value from the keyboard and print the
following output.
->Small Integer not less than the number.
->Given Number.
->Largest Integer not greater than the number.
17. Program 17 - Write a program to generate 5
Random nos. between 1 to 100, and it should not
follow with decimal point.
18. Program 18 - Write a program to display a greet
message according to Marks obtained by student
19. Program 19 - Write a program to find SUM AND
PRODUCT of a given Digit.
20. Program 20 - Write a program to find sum of all
integers greater than 100 and less than 200 that are
divisible by 7
21. Program 21 - Write a program to concatenate string
using for Loop
22. Program 22 - Program to Display Multiplication
Table
23. Program 23 - Write a program to Swap the values
24. Program 24 - Write a program to convert given
no. of days into months and days.(Assume that each
month is of 30 days)
25. Program 25 - Write a program to Display Invert
Triangle using while loop.
26. Program 26 - Write a program to find whether
given no. is Armstrong or not.
27. Program 27 - switch case demo
28. Program 28 - Write a program to generate
Harmonic Series.
29. Program 29 - Write a program to find average of
consecutive N Odd numbers and even numbers.
30. Program 30 - Display Triangle as follow: (using
for loops)
1
2 3
4 5 6
7 8 9 10 ... N */
Programs to work out
1.WAP to display a color name depending on color value
using switch.
2. Accepting single character, int, float, string and
double value from the keyboard.
3. To grade the students using switch and if-else.
4. To compute the power of 2 using for loop
5. To find the sum of the digits of a given integer
number.
6. Given the month , identify the season using switch.

Program1 – List of even numbers
/*
List Even Numbers Java Example
This List Even Numbers Java Example shows how to find and list even
numbers between 1 and any given number.
*/
public class ListEvenNumbers {
public static void main(String[] args) {
//define limit
int limit = 50;
System.out.println("Printing Even numbers between 1 and " +
limit);
for(int i=1; i <= limit; i++){
// if the number is divisible by 2 then it is even
if( i % 2 == 0){
System.out.print(i + " ");
}
}
}
}
/*
Output of List Even Numbers Java Example would be
Printing Even numbers between 1 and 50
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50
*/
Program2 - Factorial of a number
/*
This program shows how to calculate
Factorial of a number.
*/
public class NumberFactorial {
public static void main(String[] args) {
int number = 5;
/*
* Factorial of any number is! n.
* For example, factorial of 4 is 4*3*2*1.
*/
int factorial = number;
for(int i =(number - 1); i > 1; i--)
4
{
factorial = factorial * i;
}
System.out.println("Factorial of a number is " + factorial);
}
}
/*
Output of the Factorial program would be
Factorial of a number is 120
*/
Program3 - Compare Two Numbers using else-if
/*
Compare Two Numbers Java Example
This Compare Two Numbers Java Example shows how to compare two numbers
using if else if statements.
*/
public class CompareTwoNumbers {
public static void main(String[] args) {
//declare two numbers to compare
int num1 = 324;
int num2 = 234;
if(num1 > num2){
System.out.println(num1 + " is greater than " + num2);
}
else if(num1 < num2){
5
System.out.println(num1 + " is less than " + num2);
}
else{
System.out.println(num1 + " is equal to " + num2);
}
}
}
/*
Output of Compare Two Numbers Java Example would be
324 is greater than 234
*/
Program4 - Determine If Year Is Leap Year
/*
Determine If Year Is Leap Year Java Example
This Determine If Year Is Leap Year Java Example shows how to
determine whether the given year is leap year or not.
*/
public class DetermineLeapYearExample {
public static void main(String[] args) {
6
//year we want to check
int year = 2004;
//if year is divisible by 4, it is a leap year
if(year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))
System.out.println("Year " + year + " is a leap year");
else
System.out.println("Year " + year + " is not a leap year");
}
}
/*
Output of the example would be
Year 2004 is a leap year
*/
Program5 - Fibonacci Series
/* Fibonacci Series Java Example
This Fibonacci Series Java Example shows how to create and print
Fibonacci Series using Java.
*/
public class JavaFibonacciSeriesExample {
public static void main(String[] args) {
//number of elements to generate in a series
int limit = 20;
long[] series = new long[limit];
//create first 2 series elements
7
series[0] = 0;
series[1] = 1;
//create the Fibonacci series and store it in an array
for(int i=2; i < limit; i++){
series[i] = series[i-1] + series[i-2];
}
//print the Fibonacci series numbers
System.out.println("Fibonacci Series upto " + limit);
for(int i=0; i< limit; i++){
System.out.print(series[i] + " ");
}
}
}
/*
Output of the Fibonacci Series Java Example would be
Fibonacci Series upto 20
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
*/
Program6 - Palindrome Number
/*
This program shows how to check for in the given list of numbers
whether each number is palindrome or not
*/
public class JavaPalindromeNumberExample {
public static void main(String[] args) {
//array of numbers to be checked
int numbers[] = new int[]{121,13,34,11,22,54};
//iterate through the numbers
for(int i=0; i < numbers.length; i++){
int number = numbers[i];
int reversedNumber = 0;
int temp=0;
/*
* If the number is equal to it's reversed number, then
* the given number is a palindrome number.
*
* For ex,121 is a palindrome number while 12 is not.
*/
//reverse the number
while(number > 0){
temp = number % 10;
number = number / 10;
reversedNumber = reversedNumber * 10 + temp;
8
}
if(numbers[i] == reversedNumber)
System.out.println(numbers[i] + " is a palindrome");
else
System.out.println(numbers[i] + " not a palindrome ");
}
}
}
/*
Output of Java Palindrome Number Example would be
121 is a palindrome number
13 is not a palindrome number
34 is not a palindrome number
11 is a palindrome number
22 is a palindrome number
54 is not a palindrome number
*/
Program7- Generate prime numbers between 1 & given
number
/*
Prime Numbers Java Example
This Prime Numbers Java example shows how to generate prime numbers
between 1 and given number using for loop.
*/
public class GeneratePrimeNumbersExample {
public static void main(String[] args) {
//define limit
int limit = 100;
System.out.println("Prime numbers between 1 and " + limit);
//loop through the numbers one by one
for(int i=1; i < 100; i++){
boolean isPrime = true;
//check to see if the number is prime
for(int j=2; j < i ; j++){
if(i % j == 0){
isPrime = false;
break;
}
}
// print the number
if(isPrime)
System.out.print(i + " ");
}
9
}
}
/*
Output of Prime Numbers example would be
Prime numbers between 1 and 100
1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
*/
Program8- Pyramid of stars using nested for loops
/*
Java Pyramid 1 Example
This Java Pyramid example shows how to generate pyramid or triangle
like given below using for loop.
*
**
***
****
*****
*/
public class JavaPyramid1 {
public static void main(String[] args) {
for(int i=1; i<= 5 ;i++){
for(int j=0; j < i; j++){
System.out.print("*");
}
//generate a new line
System.out.println("");
}
}
}
/*
Output of the above program would be
*
**
***
****
*****
*/
Program9 – Reversed pyramid using for loops &
decrement operator.
/*
10
Java Pyramid 5 Example
This Java Pyramid example shows how to generate pyramid or triangle
like given below using for loop.
12345
1234
123
12
1
*/
public class JavaPyramid5 {
public static void main(String[] args) {
for(int i=5; i>0 ;i--){
for(int j=0; j < i; j++){
System.out.print(j+1);
}
System.out.println("");
}
}
}
/*
Output of the example would be
12345
1234
123
12
1
*/
Program10 - Nested Switch
/*
Statements Example
This example shows how to use nested switch statements in a
java program.
*/
11
public class NestedSwitchExample {
public static void main(String[] args) {
/*
* Like any other Java statements, switch statements
* can also be nested in each other as given in
* below example.
*/
int i = 0;
int j = 1;
switch(i)
{
case 0:
switch(j)
{
case 0:
System.out.println("i is 0, j is 0");
break;
case 1:
System.out.println("i is 0, j is 1");
break;
12
default:
System.out.println("nested default
case!!");
}
break;
default:
System.out.println("No matching case found!!");
}
}
}
/*
Output would be,
i is 0, j is 1
*/
13
Program11 - Calculate Circle Area using radius
/*
This program shows how to calculate
area of circle using it's radius.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CalculateCircleAreaExample {
public static void main(String[] args) {
int radius = 0;
System.out.println("Please enter radius of a circle");
try
{
//get the radius from console
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
radius = Integer.parseInt(br.readLine());
}
//if invalid value was entered
catch(NumberFormatException ne)
{
System.out.println("Invalid radius value" + ne);
System.exit(0);
}
catch(IOException ioe)
{
System.out.println("IO Error :" + ioe);
System.exit(0);
}
/*
* Area of a circle is
* pi * r * r
* where r is a radius of a circle.
*/
//NOTE : use Math.PI constant to get value of pi
double area = Math.PI * radius * radius;
System.out.println("Area of a circle is " + area);
}
}
/*
Output of Calculate Circle Area using Java Example would be
14
Please enter radius of a circle
19
Area of a circle is 1134.1149479459152
*/
Program12 - Factorial of a number using recursion
/*
This program shows how to calculate
Factorial of a number using recursion function.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class JavaFactorialUsingRecursion {
public static void main(String args[]) throws NumberFormatException,
IOException{
System.out.println("Enter the number: ");
//get input from the user
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
int a = Integer.parseInt(br.readLine());
//call the recursive function to generate factorial
int result= fact(a);
System.out.println("Factorial of the number is: " + result);
}
static int fact(int b)
{
if(b <= 1)
//if the number is 1 then return 1
return 1;
else
//else call the same function with the value - 1
return b * fact(b-1);
}
}
/*
Output of this Java example would be
Enter the number:
5
Factorial of the number is: 120
*/
15
Program13 – pyramid of numbers using for loops
/*
Generate Pyramid For a Given Number Example
This Java example shows how to generate a pyramid of numbers for given
number using for loop example.
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class GeneratePyramidExample {
public static void main (String[] args) throws Exception{
BufferedReader keyboard = new BufferedReader (new
InputStreamReader(System.in));
System.out.println("Enter Number:");
int as= Integer.parseInt (keyboard.readLine());
System.out.println("Enter X:");
int x= Integer.parseInt (keyboard.readLine());
int y = 0;
for(int i=0; i<= as ;i++){
16
for(int j=1; j <= i ; j++){
System.out.print(y + "\t");
y = y + x;
}
System.out.println("");
}
}
}
/*
Output of this example would be
Enter Number:
5
Enter X:
1
0
1 2
3 4 5
6 7 8 9
10 11 12 13 14
----------------------------------------------
17
Enter Number:
5
Enter X:
2
0
2 4
6 8 10
12 14 16 18
20 22 24 26 28
----------------------------------------------
Enter Number:
5
Enter X:
3
0
3 6
9 12 15
18 21 24 27
30 33 36 39 42
*/
18
Program14 – To Find Maximum of Two Numbers.
/*
To Find Maximum of 2 Numbers using if else
*/
class Maxoftwo{
public static void main(String args[]){
//taking value as command line argument.
//Converting String format to Integer value
int i = Integer.parseInt(args[0]);
int j = Integer.parseInt(args[1]);
if(i > j)
System.out.println(i+" is greater than "+j);
else
System.out.println(j+" is greater than "+i);
}
}
Program15 – To Find Minimum of Two Numbers using
conditional operator
/*
To find minimum of 2 Numbers using ternary operator
*/
class Minoftwo{
public static void main(String args[]){
//taking value as command line argument.
//Converting String format to Integer value
int i = Integer.parseInt(args[0]);
19
int j = Integer.parseInt(args[1]);
int result = (i<j)?i:j;
System.out.println(result+" is a minimum value");
}
}
20
Program 16
/* Write a program that will read a float type value from the keyboard and
print the following output.
->Small Integer not less than the number.
->Given Number.
->Largest Integer not greater than the number.
*/
class ValueFormat{
public static void main(String args[]){
double i = 34.32; //given number
System.out.println("Small Integer not greater than the number :
"+Math.ceil(i));
System.out.println("Given Number : "+i);
System.out.println("Largest Integer not greater than the number :
"+Math.floor(i));
}
Program 17 - Write a program to generate 5 Random nos.
between 1 to 100, and it should not follow with decimal
point.
class RandomDemo{
public static void main(String args[]){
for(int i=1;i<=5;i++){
System.out.println((int)(Math.random()*100));
}
}
21
}
Program 18 - Write a program to display a greet message
according to Marks obtained by student.
class SwitchDemo{
public static void main(String args[]){
int marks = Integer.parseInt(args[0]); //take marks
as command line argument.
switch(marks/10){
case 10:
case 9:
case 8:
System.out.println("Excellent");
break;
case 7:
System.out.println("Very Good");
break;
case 6:
System.out.println("Good");
break;
case 5:
System.out.println("Work Hard");
break;
case 4:
System.out.println("Poor");
break;
case 3:
22
case 2:
case 1:
case 0:
System.out.println("Very Poor");
break;
default:
System.out.println("Invalid value Entered");
}
}
}
Program 19 - Write a program to find SUM AND PRODUCT of
a given Digit.
class Sum_Product_ofDigit{
public static void main(String args[]){
int num = Integer.parseInt(args[0]);
//taking value as command line argument.
int temp = num,result=0;
//Logic for sum of digit
while(temp>0){
result = result + temp;
temp--;
}
System.out.println("Sum of Digit for "+num+" is : "+result);
//Logic for product of digit
temp = num;
23
result = 1;
while(temp > 0){
result = result * temp;
temp--;
}
System.out.println("Product of Digit for "+num+" is : "+result);
}
}
Program 20 - Write a program to find sum of all
integers greater than 100 and less than 200 that are
divisible by 7
class SumOfDigit{
public static void main(String args[]){
int result=0;
for(int i=100;i<=200;i++){
if(i%7==0)
result+=i;
}
System.out.println("Output of Program is : "+result);
}
}
Program 21 - Write a program to concatenate string
using for Loop
Example:
Input - 5
24
Output - 1 2 3 4 5 */
class Join{
public static void main(String args[]){
int num = Integer.parseInt(args[0]);
String result = " ";
for(int i=1;i<=num;i++){
result = result + i + " ";
}
System.out.println(result);
}
}
Program 22 - Program to Display Multiplication Table
class MultiplicationTable{
public static void main(String args[]){
int num = Integer.parseInt(args[0]);
System.out.println("*****MULTIPLICATION TABLE*****");
for(int i=1;i<=num;i++){
for(int j=1;j<=num;j++){
System.out.print(" "+i*j+" ");
}
System.out.print("\n");
}
}
}
25
Program 23 - Write a program to Swap the values
class Swap{
public static void main(String args[]){
int num1 = Integer.parseInt(args[0]);
int num2 = Integer.parseInt(args[1]);
System.out.println("\n***Before Swapping***");
System.out.println("Number 1 : "+num1);
System.out.println("Number 2 : "+num2);
//Swap logic
num1 = num1 + num2;
num2 = num1 - num2;
num1 = num1 - num2;
System.out.println("\n***After Swapping***");
System.out.println("Number 1 : "+num1);
System.out.println("Number 2 : "+num2);
}
}
26
Program 24 - Write a program to convert given no. of
days into months and days.(Assume that each month is of
30 days)
Example :
Input - 69
Output - 69 days = 2 Month and 9 days */
class DayMonthDemo{
public static void main(String args[]){
int num = Integer.parseInt(args[0]);
int days = num%30;
int month = num/30;
System.out.println(num+" days = "+month+" Month and "+days+" days");
}
}
Program 25 - Write a program to Display Invert Triangle
using while loop.
Example:
Input - 5
Output :
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
27
*/
class InvertTriangle{
public static void main(String args[]){
int num = Integer.parseInt(args[0]);
while(num > 0){
for(int j=1;j<=num;j++){
System.out.print(" "+num+" ");
}
System.out.print("\n");
num--;
}
}
}
Program 26 - Write a program to find whether given no.
is Armstrong or not.
Example :
Input - 153
Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */
class Armstrong{
public static void main(String args[]){
int num = Integer.parseInt(args[0]);
int n = num; //use to check at last time
int check=0,remainder;
while(num > 0){
remainder = num % 10;
28
check = check + (int)Math.pow(remainder,3);
num = num / 10;
}
if(check == n)
System.out.println(n+" is an Armstrong Number");
else
System.out.println(n+" is not a Armstrong Number");
}
}
Program 27 - switch case demo
Example :
Input - 124
Output - One Two Four */
class SwitchCaseDemo{
public static void main(String args[]){
try{
int num = Integer.parseInt(args[0]);
int n = num; //used at last time check
int reverse=0,remainder;
while(num > 0){
remainder = num % 10;
reverse = reverse * 10 + remainder;
num = num / 10;
}
29
String result=""; //contains the actual output
while(reverse > 0){
remainder = reverse % 10;
reverse = reverse / 10;
switch(remainder){
case 0 :
result = result + "Zero ";
break;
case 1 :
result = result + "One ";
break;
case 2 :
result = result + "Two ";
break;
case 3 :
result = result + "Three ";
break;
case 4 :
result = result + "Four ";
break;
case 5 :
result = result + "Five ";
break;
case 6 :
result = result + "Six ";
break;
30
case 7 :
result = result + "Seven ";
break;
case 8 :
result = result + "Eight ";
break;
case 9 :
result = result + "Nine ";
break;
default:
result="";
}
}
System.out.println(result);
}catch(Exception e){
System.out.println("Invalid Number Format");
}
}
}
Program 28 - Write a program to generate Harmonic
Series.
Example :
Input - 5
Output - 1 + 1/2 + 1/3 + 1/4 + 1/5 = 2.28 (Approximately) */
class HarmonicSeries{
31
public static void main(String args[]){
int num = Integer.parseInt(args[0]);
double result = 0.0;
while(num > 0){
result = result + (double) 1 / num;
num--;
}
System.out.println("Output of Harmonic Series is "+result);
}
}
32
Program 29 - Write a program to find average of
consecutive N Odd no. and Even no.
class EvenOdd_Avg{
public static void main(String args[]){
int n = Integer.parseInt(args[0]);
int cntEven=0,cntOdd=0,sumEven=0,sumOdd=0;
while(n > 0){
if(n%2==0){
cntEven++;
sumEven = sumEven + n;
}
else{
cntOdd++;
sumOdd = sumOdd + n;
}
n--;
}
int evenAvg,oddAvg;
evenAvg = sumEven/cntEven;
oddAvg = sumOdd/cntOdd;
System.out.println("Average of first N Even no is "+evenAvg);
System.out.println("Average of first N Odd no is "+oddAvg);
}
}
33
Program 30 - Display Triangle as follow.
1
2 3
4 5 6
7 8 9 10 ... N */
class Output1{
public static void main(String args[]){
int c=0;
int n = Integer.parseInt(args[0]);
loop1: for(int i=1;i<=n;i++){
loop2: for(int j=1;j<=i;j++){
if(c!=n){
c++;
System.out.print(c+" ");
}
else
break loop1;
}
System.out.print("\n");
}
}
}
34
Extra Programs 1 - Write a program to Find whether
number is Prime or Not.
class PrimeNo{
public static void main(String args[]){
int num = Integer.parseInt(args[0]);
int flag=0;
for(int i=2;i<num;i++){
if(num%i==0)
{
System.out.println(num+" is not a Prime Number");
flag = 1;
break;
}
}
if(flag==0)
System.out.println(num+" is a Prime Number");
}
}
35
Program 2 - Write a program to find whether no. is
palindrome or not.
Example :
Input - 12521 is a palindrome no.
Input - 12345 is not a palindrome no. */
class Palindrome{
public static void main(String args[]){
int num = Integer.parseInt(args[0]);
int n = num; //used at last time check
int reverse=0,remainder;
while(num > 0){
remainder = num % 10;
reverse = reverse * 10 + remainder;
num = num / 10;
}
if(reverse == n)
System.out.println(n+" is a Palindrome Number");
else
System.out.println(n+" is not a Palindrome Number");
}
}
36
Program 3 - Display Triangle as follow
0
1 0
1 0 1
0 1 0 1 */
class Output2{
public static void main(String args[]){
for(int i=1;i<=4;i++){
for(int j=1;j<=i;j++){
System.out.print(((i+j)%2)+" ");
}
System.out.print("\n");
}
}
}

Some useful data validation code for NetBeans IDE

What is Data Validation?
Data Validation is the process of ensuring that a program operates on clean, correct and useful data. It uses routines, often called "validation rules" or "check routines", that check for correctness, meaningfulness, and security of data that are input to the system.
Example - A name text field should not allow user to enter numbers or characters such as '+','=',''&', etc. Mobile numbers should only include digits and '+' sign.
Some Useful Data Validation Code
  1. Allowing only Numeric values in a text field
For this purpose we should use KeyTyped event handler of textField. Every KeyTyped event handler receives a KeyEvent object by default.
Char kc=evt.getKeyChar();
If(!(kc>=’0’ && kc<=’9’))
Evt.consume();

private void jTextField4KeyTyped(java.awt.event.KeyEvent evt) {                                    
        char kc = evt.getKeyChar();
        if (!(((kc >= '0') && (kc <= '9')) || kc == KeyEvent.VK_BACKSPACE)) {
            evt.consume();
        }
  1. Checking for 'No Input'
    Users often miss out to enter data in some fields or sometimes they assume a necessary field to be an optional one. So, a program must check if the user has entered the required data or not. If the user has not provided the required data the program must not run further.
    Checking for empty textfields - You can check if the textfield is empty or not by the following coding:
    if (jTextField1.getText().isEmpty() || jTextField2.getText().isEmpty())
            JOptionPane.showMessageDialog(null, "One of the required field is empty!", "Error", JOptionPane.ERROR_MESSAGE);
or you can use the following method:

if (jTextField1.getText().length()==0 || jTextField2.getText().length()==0)
        JOptionPane.showMessageDialog(null, "One of the required field is empty!", "Error", JOptionPane.ERROR_MESSAGE);
Here, jTextField1 and jTextField2 are the fields which cannot be left empty. You can also notify user about the field that has been left empty by using if..else construct. The same coding, will work for jTextArea and jPasswordField.

3. Checking for 'No selection from list' 
Another run-time error occurs if the user does not select any value from the list component. User must be notified for the same.
if (jList1.getSelectedIndex()==-1)
       JOptionPane.showMessageDialog(null, "Please select a value from list");
This will show a message to user for a null value from list i.e no value selected by user.

4. Checking for 'No selection from Radio buttons' 
Checking if user has not selected any choice from a group of radio buttons.
Remember, always put radio buttons in a button group, otherwise all radio buttons could be selected at a particular time.

if (jRadioButton1.isSelected()==false && jRadioButton2.isSelected()==false)
        JOptionPane.showMessageDialog(null, "Please Select your Gender!");
or you can try the following code:

 if (jRadioButton1.isSelected())
        gender="Male";
    //Instead do your functioning!
    else if (jRadioButton2.isSelected())
        gender="Female";
    //Instead do your functioning!
    else
        JOptionPane.showMessageDialog(null, "Please Select your Gender!");
You can use the same piece of code for checkbox.

5. Prohibiting characters in numbers field
This code will help you to prohibit users from entering characters other than digits in numbers field like Moblie Number.
Write the following code on the KeyTyped event of a text field.

char k=evt.getKeyChar();
if (!(k>='0' && k<='9'))
        evt.consume();
Now, if a user types characters other than digits, the event will be consumed.
The below coding will prevent user from typing digits in a field placed for characters(eg- Name field)

char k=evt.getKeyChar();
if (k>='0' && k<='9')
        evt.consume();
6. Prohibiting multiple selection in a list
Set the selectionMode property of list to Single_Selection by the following code to prevent user from selecting multiple items from list. Default isMultiple_Interval_Selection.

jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
Also, each GUI form must have a Exit and Clear button.
Exit Button -
System.exit(0);


Clear Button -

Clearing TextFields

jTextField1.setText("");
jTextField2.setText("");
Clearing selection from list

jList1.clearSelection();
Clearing selection from Combo Box

jComboBox1.setSelectedIndex(-1);
Clearing selection from Radio Buttons

buttonGroup1.clearSelection();
Clearing the contents of a table

DefaultTableModel model=(DefaultTableModel) jTable1.getModel();
    int rows=model.getRowCount();
    if (rows>0){
       for(int j=0; j<rows; j++){
           model.removeRow(0);
       }
   }


Saturday, 28 September 2013

Getting Started with Swing UI (User Interface) Components (Some Important Questions with Answers) For Class XI

Chapter 4

 Getting Started with Swing UI (User Interface) Components

Some Important Questions with Answers

1. Which window is used to design the form?
Ans: Design window
2. Which window contains the Swing Controls components?
Ans: Palette window
3. What is the most suitable component to accept multiline text?
Ans : Text Area
4. What will be the output of the following command?
Learning.concat("Java")
Ans : Error
5. What will be the output of the following command?
"Learning".concat("Java")
Ans: LearningJava
6. Name the different list type controls offered by Java Swing.
Ans: (i) jListBox
        (ii) jComboBox
7. Name any two commonly used method of ListBox.
Ans: getSelectedIndex() and getSelectedValue()

8. Write code to add an element (“New Course”) to a list (SubList) at the beginning of the list.
Ans: SubList.add(0,”New Course”);
9. Describe the three common controls. Also give some of their properties.
Ans:
(i) jButton text,icon
(ii) jLabel text,border
(iii) jTextField text,font
10. By default a combo box does not offer editing feature. How would you make a combo box editable.
Ans: By setting its editable property to false.
11. Write Name the component classes of Swing API for the following components-
(a) frame (b) button
Ans:(a)JFrame(b)JButton
12. What is the name of event listener interface for action events?
Ans: ActionPerformed
13. What does getpassword() on a password field return ?
Ans: a character array
14. What is event driven programming?
Ans: This programming style responds to the user events and is driven by the occurrence of user events.


15. What are containers? Give examples.
Ans: Containers are those controls inside them e.g., frame (JFrame), Panel (JPanel), label (JLabel) etc. are containers
16. which method of list is used to determine the value of selected item, if only one itm is selected.
Ans: getSelectedValue()
17. Which type of storage is provided by variables?
Ans: temporary
18. Explain the following terms:
a) IDE
b) Form
Ans: a) IDE : IDE is an acronym for Integrated Development Environment which is a work environment that integrates all tools necessary for Application Development and makes them available as part of one environment.
b) Forms: Forms are used to accept data (input) and submit data to an external agent for processing.
19. Explain the usage of the following methods :
a) setText()
b) toString()
c) concat()

a) setText() : It is used to change the display text of a component (label, text field or button) during run time.
b) toString() : It is used to convert an Integer value to String type.
c) concat() : The concat() method or the string concatenation symbol(+) may be used to add two strings together.
20. Differentiate between:
a) Text field and Text area components :
The Text Field allows the user to enter a single line of text only. But Text Area component allows to accept
multiline input from the user or display multiple lines of information.
b) Text field and Password field components:
The Text Field displays the obtained text in unencrypted form whereas password field displays the obtained
text in encrypted form. This component allows confidential input like passwords which are single line.
c) parseInt() and parseDouble() methods:
parseInt() is used to convert a string value to Integer type whereas parseDouble() is used to convert a
string value to type Double.
21. What is casting? When do we need it?
Ans: Casting is a conversion, which uses the cast operator to specify the type name in parenthesis and is
placed in front of the value to be converted.
For example: Result = (float) total / count ;
They are helpful in situations where we temporarily need to treat a value as another type.
22. Is Java case sensitive? What is meant by case sensitive?
Ans: Yes java is case sensitive. Case sensitive means upper case letters and lower case letters are treated
differently.
23. Is a string containing a single character same as a char?
Ans: No
24. What is the main difference between a combo box and a list box?
Ans: The List Box does not have a text field the user can use to edit the selected item, where as a Combo
Box is cross between a text field and a list.


Thursday, 26 September 2013

Tips to get 100 out of 100 in informatices Practices

TIPS FOR SCORING FULL MARKS IN EXAM

·         Prepare those questions first, which you feel easy for you.
·          Important terms of a topic must be memorized.
·          Practice the solutions in writing rather than just reading.
·          Practice on similar type question at a time.
·         Read all the questions carefully, before answering.
·         Attempt such questions first, for which you are confident          that it will leave a good impression.
·         Don't stretch the answer unnecessarily.
·         Try to write answer in points.
·         Important point should be underlined but be careful                   don't waste your time.
·         Try to illustrate your answer graphically, if it is possible.
·         Don't leave any question unanswered.
·         Solve previous years question papers, it is very important
·         Make precise and concise notes, point wise for exam time         preparation.
·         Plan your study judiciously (At least ½ hour daily for full           marks).
·         A proper timetable for study should be followed strictly.
·         Take healthy and timely diet during examinations. Also             take sound sleep every day.
·         Take a break from time to time in each study period.
·         Do not forget to revise all the topics one day prior, to the           day of examination.
BEST OF LUCK

And remember The Target is 100/100

Friday, 20 September 2013

Important Extra questions and answers of chapter 2 open source concepts class xii i.p. Target 100%

EXTRA QUESTIONS BANK
TARGET 70/70
IMPORTANT QUESTIONS AND ANSWERS OF
CHAPTER 2 OPEN SOURCE CONCEPTS

Q.1.     What is OSS?

 It refers to Open Source Software, which are modifiable, redistributable but may or may not be available free of cost. Source code is available to the users.

Q.2      What is free software? How is it different from Open Source Software?

Free software means the software is freely accessible and can be freely used , changed and distributed by all who wish to do so, no payments need to be done for free software.
Open Source software is one whose source code is available with the software but which may not be available free of cost.

Q.3      What is a freeware? How is it different from free software?

Free software is the software available at no cost and no restrictions i.e. it can be copied, modified and redistributed also. Freeware on the other hand is free of cost, can be copied and redistributed but it cannot be modified as its source code is not available

Q.4      compare and contrast
            i) Open source Software (OSS) and FLOSS

OSS refers to software whose source code is available to customers hence it can be modified and redistributed without any restrictions  it may be available Free of Cost  or  on a payment as decided by the developers of the software
FLOSS  refers to a software which is both free of cost as well as open source software where LIBRE is a Spanish word which refers to FREEDOM

            ii) Proprietary Software and Free Software

Proprietary Software is one which is neither free  nor open source software . Its use is regulated and further distribution and modification is either forbidden or requires prior permission by the supplier or vendor.  Source code is normally not available for these software
Free software is the software available at no cost and no restrictions i.e. it can be copied , modified and redistributed also.

            iii)        Freeware and shareware
The term Freeware is generally used for software which is available free of cost and which allows coping and further distribution but no modifications as its source code is not available.
Shareware is a software , which is made available with the right to redistribute copies , but it is stipulated  that if anybody intends to use the software after a certain period  then a license fee should be paid. No modifications are allowed and no source code is available for these software.

Q.5      Expand the terms :-
            OSI                 Open Source Initiative
            FLOSS           Free/Libre and Open Source Software
            FSF                 Free software foundation
            GNU               GNU’S Not Unix
            GPL                General Public License
            W3C               World Wide Web Consortium
            OSS                 Open Source Software

Q.6      Explain the use of following software

            Linux                          it is an open source operating system
            Mozilla Firefox          It is a web browser
PHP                            it is a programming language primarily used for server side applications and developing dynamic web content
            Python                         it is an interpreted , interactive , programming language used for scripting
Apache                       it is a web server or HTTP server available for multiple platforms such as BSD, Linux and Unix etc
MySQL                      it is a multithreaded , multiuser  SQL relational database server.

Q7.      What is the openoffice.org?
It is an office applications suite compatible with Microsoft Office.

Q8       What do you mean by computing?
It refers to applying a set of techniques on data  in order to define and solve problems pertaining to  specific information based task.

 Q9.     What is Business Computing?
            Computing applied to solve business related problems , is known as business computing


Q10.    Name some application areas of business computing
  • Inventory Control
  • Payroll management
  • Financial Accounting
  • Banking Applications

Q11.    What do you mean by an information system?
It can be defined as set of interrelated components that collect, process, store and distribute data ans information to provide a feedback mechanism to meet an objective.

Q12.    List some Information Systems
            TPS                 Transaction Processing System
            MIS                 Management Information System
            DSS                 Decision Support System
            ESS                 Executive Support System

Q 13    Name four building blocks of an Information System
            Four building blocks of an Information System are
            DATA - These are raw facts about the organization and business transactions  that are used to produce useful information.
            PROCESS These are the tasks to be performed to complete the mission of the business
            INTERFACE  -These are the interconnection of one system with the other and how the system is presented to the user.
            GEOGRAPHY-It defines how the data , processes and interfaces are distributed to different business locations and the movement of data from one location to another.

Q 14.   What do you mean by user interface ?
            It refers to the software , which interacts with the user  , and is responsible for obtaining user’s requests , queries , responses etc. and sending them for further processing.

Q.15    What do you mean by a front end ?
            It is the user interface which the user can see , and which is responsible for interacting with the users , collecting their requests and passing them on to the back end for further processing
            e.g  A form designed in V.B.

Q16.    What is a Back End?
            It is the program which handles all database accesses through one or more servers , and is responsible for maintaining and  processing the data as per the requirements of the database users.

Q 17.   What do you mean by a database? 
            It is a collection of interrelated data files stored at a centralized place .

Q 18.   What does inventory control system do?
             It is used to maintain optimum inventory levels , control inventory costs and track merchandise movement.

Q 19.   Name some tables used to maintain inventory data
            Item table        To maintain details of items  available in the store
            Orders Table   To maintain a record of items which are ordered to the various vendors
            Shipment Table To maintain a detail of items that have been sold to the customers / wholesalers

Q 20.   Name any two reports available for inventory control system
            Inventory Status report
            Inventory valuation report

Q 21.   Name some database tables and their purpose, required  for maintaining student record
keeping system
            Student Table  -           keeps the details of all students enrolled
            Marks Table    -           keeps a record of marks scored by students in the tests/exams
            Fee Table         -           keeps a track of fee paid by the students

Q 22    What is payroll processing system?
            It is the software that is used to keep a record of salary details of  the employees of an organization

Q 23.   Name some tables required for payroll processing system
            Employee Table          to keep a track of employees working in a organization
            Salary Table                to keep a track of monthly salary , leaves details of the employee

Q24.    Name some reports produced by payroll processing system?
            Monthly pay slip for employee
            Pay register
            Monthly Bank Statement
            Bank Statement for Loans and Advances

Q25.    What is the role of a personal management system / Human Resource system?
            It is responsible of keeping a track of employee details , their growth pattern , training requirements / grievance redressal details , positional changes etc.

Q26.    Name some tables required for human resource System
            Employee Master
            Department master
            Transfer details

Q27.    Name some reports produced by human resource System
            Employee Master report
Training Details report
            Retirement Report

Q28.    Name some tables required for maintaining financial accounting system
            Business transaction  Table
            Assets Table
            Liabilities Table

Q29.    Name some reports generated by financial accounting system
            Income Statement
            Balance Sheet

Q 30.   Write short notes on the following

GNU               This is a project initiated by Richard M. Stallman with an objective to create a system compatible with UNIX  but not identical to it. It offers a wide range of software  including applications apart from operating system.

LINUX           It is a popular computer operating system . It is the most famous example of free software and open source development, as it is not only freely available but its source code is also available which can be modified and redistributed.

Mozilla            It is a software which is free , cross platform  and internet suite  program that includes  a web browser , an E-Mail client  , a HTML editor and and IRC client as its components

Apache            it is a open source web server available to work with different plateforms such as Linux and Unix. . it is developed and maintained by open community of developers.

PostgreSQL    It is a free Object – relational database server , released under the flexible  BSD style lisence. It offers an alternative to other open source database systems as well as proprietary systems such as Oracle etc.

Python             It is an interpreted  , interactive programming language managed by non profit  Python Software Foundation. It can be used for  scripting  of program codes that can be used on Internet.

PHP                 it is a recursive acronym for  PHP Hypertext Processor  , which is a widely used open source  programming language  used primarily for server side programming and developing dynamic web contents.

Open Office /Openoffice.org it is an office  application suite  intended to be compatible and  directly compete with ms-office.

OSI                 Open source initiative , it is an organization dedicated to the cause of promoting open source softwares. It specifies the criteria for open source software and properly defines the  terms and specification of  open source software.

TOMCAT       it is a program that serves as a serve let container  and considered to be an application server. It implements servelets and java server pages.

Q.31    Name  some websites dedicated to open source software                                                
           
            www.sourceforge.net .           www.openRDF.org     www.opensource.org
            www.linux.com                      www.gnu.org

Q 32.   What do you mean by transaction and transaction processing system
A transaction is any  business related exchange of data in the database such as payments to employees , supplies to retailers , payments done to suppliers etc.
                                                            OR
A transaction processing system is an information system that captures and processes data generated during an organizations , day to day transactions.

Q 33.   What is Data Warehouse?

The Data Warehouse is a system for storing and delivering massive quantities of data. It is a centralized data repository that store and provides already transformed and summarized data, therefore, making it an appropriate environment for more efficient DSS and EIS application.

Q 34.   What is Data Mining?

            Data Mining refers to the extraction of hidden predictive information patterns from  large database.
            Data Mining helps in predicting future trends and behaviours that are useful in making proactive 
            Knowledge-driven decision.

Q 35.   How is Object Oriented Programming different from the other traditional approaches?
The Object Oriented Programming approach see the data in terms of object involved rather than procedure involved with it.


Q 36.   What is DDLC? How it is different from SDLC?
            DDLC stands for Database Development Life Cycle, which is the process for designing and developing  Database. It is different from SDLC as SDLC emphasizes upon the business application logic i.e. it is more function oriented, DDLC is more data oriented.


                                                                                                              
Q 38. What is Data Dictionary?
          The data dictionary is a database about data and database structure i.e. metadata. It maintains a catalog of all data elements, containing their names, structures, and information about their usage.                      
Q 39. What is a class and an object?
           A class represents a group of objects that share common properties and relationship.
           Object is an identifiable entity with some characteristics and behavior.

Q 40. What do you understand by Object Modeling?
Object Modeling  refers to building models and performing activities so that all this leads up to the deployment of a good OO system.

Q 41. What is UML? What  is UML diagram?
UML stands for Unified Modeling Language. It is an open and industry standard visual modeling language for object oriented system.
UML diagram are the graphical representation of a model of a system. Each UML diagram consists of a set of nodes and arcs, where
--- The nodes represent the model elements.
--- The arcs represent relationship between the model elements.

Q 42. What is a SDLC?
          The SDLC stands for System Development Life Cycle- it is a set of activities that are carried out to
          develop and implement an information system.

Q 43. Define Cost-Benefit analysis.
         Cost-Benefit Analysis can be defined as the method by which we find and estimate the value of the gross  benefits of a new system specifications.

Q 44. What is ER-Model?
         The ER Model or Entity-Relationship Model is a high level, conceptual model that describes data as
         entities, attributes and relationship.

Q 45. What are the different stages of SDLC?
          (i) Preliminary Study/Survey                                               (ii)Feasibility Study
          (iii) Investigation & Fact Recording                                   (iv)System Analysis
          (v) System Design                                                               (vi) Implementation Maintenance , review
                                                                                                               
Q 46. What are fat and thin client.
          A fat client is an application that itself is responsible  for its processing power and application logic, and a    
          thin client is an application that does not have much of processing power of application logic, rather it    
          provides a user interface only.

Q 47. Differentiate between entity and attributes with the help of an example?
An entity is an object that exists and is distinguishable from other objects e.g. a student, a Book, a Bank-Account etc. An entity is denoted by rectangle in E-R Diagram.


Q 48.Explain the terms software, Hardware and firmware using suitable examples?
Software are the computer program that govern the operation of computers, Hardware contains the physical component which can be seen and touch e.g. Mouse, keyboard. Pre-Written program permanently stores in computer’s read only memory are known as firmware e.g. ROM-BIOS.

Q 50. What is Process Chart?
 A process chart is a form which an analyst can fill when studying a process. An analysis of the filled charts helps identify duplicate and redundant steps and suggests area of potential saving in times.

Q 51. What is Metadata?
 The data about data is called Metadata.

Q 52. What is 3-tier computing model?
In 3 tier computing model there exists three tiers (i) Client tier (ii) Middle tier         (iii) Database server tier.

Q 53. What is 2-tier computing model?
In 2 tier computing model there exists two tiers (i) Client tier  (ii) Database server tier. Processing tasks and application logic are shared between database server and the client.

Q 54. Name some techniques used in Data Mining.
          Some techniques used are:-Artificial neural network, decision tree etc.

Q 55.What do you understand by the term Decision-Tree.
 A decision tree is a diagram that looks like a tree and that relates conditions and actions relating to a process , sequentially.

Q 56. What type of information is depicted in process chart?
A process chart is a chart that enlist each step of the process along with its activity type, time taken and volume involved.

Q 57. What are three basic elements of Structure chart?
           The three basic elements of structure charts are:
           (i)Module                               (ii)Connectors                                      (iii) Couples

Q 58. What is Flow-Chart?
           It is an Graphical Representation of a system’s data and how the actions in a system.

Q 59. Explain the importance of post implementation review briefly?
 A post implementation review is an evaluation of a system in terms of the extent to which the system accomplishes stated objectives and actual project costs exceeds initial estimate.

Q 60. What is Feasibility study?
The basic purpose of Feasibility study or survey is to determine whether the whole process of  system analysis leading to computerization would be worth the effort for the organisation.