Tuesday 30 July 2013

SCJP QUESTIONS

SUN CERTIFIED JAVA PROGRAMMER

Question - 1
What is the output for the below code ?
1. public class A {
2. int add(int i, int j){
3. return i+j;
4. }
5.}
6.public class B extends A{
7. public static void main(String argv[]){
8. short s = 9;
9. System.out.println(add(s,6));
10. }
11.}

Options are 
A.Compile fail due to error on line no 2
B.Compile fail due to error on line no 9
C.Compile fail due to error on line no 8
D.15

Question - 2
What is the output for the below code ?
public class A {
int k;
 boolean istrue;
 static int p;
public void printValue() {
System.out.print(k);
System.out.print(istrue);
System.out.print(p);
}
}
public class Test{
 public static void main(String argv[]){
A a = new A();
a.printValue();
 }
}
Options are 
A.0 false 0
B.0 true 0
C.0 0 0
D.Compile error - static variable must be initialized before use


Question - 3
What is the output for the below code ?
public class Test{
int _$;
int $7;
int do;
 public static void main(String argv[]){
 Test test = new Test();
 test.$7=7;
 test.do=9;
 System.out.println(test.$7);
 System.out.println(test.do);
 System.out.println(test._$);
 }
}
Options are
A.7 9 0
B.7 0 0
C.Compile error - $7 is not valid identifier.
D.Compile error - do is not valid identifier

Question -4:
What is the output for the below code ?
package com;
class Animal {
 public void printName(){
 System.out.println("Animal");
 }
}

package exam;
import com.Animal;
public class Cat extends Animal {
 public void printName(){
 System.out.println("Cat");
 }
}

package exam;
import com.Animal;
public class Test {
public static void main(String[] args){
 Animal a = new Cat();
 a.printName();
}
}
Options are 
A.Animal
B.Cat
C.Animal Cat
D.Compile Error

Question No-5:
What is the output for the below code ?

public class A {
int i = 10;
public void printValue() {System.out.println("Value-A");
};
}
public class B extends A{
int i = 12;
public void printValue() {
System.out.print("Value-B");
}
}
public class Test{
 public static void main(String argv[]){
 A a = new B();
 a.printValue();
 System.out.println(a.i);
 }
}
Options are 
A.Value-B 11
B.Value-B 10
C.Value-A 10
D.Value-A 11

Monday 29 July 2013

JAVA LAB PROGRAM ALGORITHM:

1. Develop a Java package with simple Stack and Queue classes.  Use JavaDoc comments for documentation

ALGORITHM:
step 1:Define package pack1 with the keyword package.
step 2:Define the class ArrayQueue with the integers.
step 3:Using a 1 argument constructor,the max size of the queue is assigned.
step 4:Define the method insert() with an item in object type as argument to insert an item.
step 5:Define the method remove() to delete an item from the queue.
step 6:Define the method peek() to return the item which is at the top of stack.
Step 7:Define the method displayAll() to display the contents of the queue.
step 8:Terminate the class .Create an another package pack1 using the keyword package.
step 9:Define the class ArrayStack with an object array'a' and an integer top as datamembers.
step 10:Using a one argument constructor define the size of the array.
step 11:Define the method push() to push an item into the stack.
step 12:Define the method pop() to delete an item from the stack.
step 13:Define the method peek() to return the item at the top of the stack.
step 14:Terminate the class.
step 15:Import the package pack1,define the class StackQueueDemo.
step 16:Define the main() in the class.
Create objects for the classes ArrayStack and ArrayQueue and access the methods using the objects.
step 17:Display the result.
step 18: terminte the main() and terminate the class.


2. Design a Date class similar to the one provided in the java.util package

ALGORITHM
step 1:Define the class MyDate with members date,month,year,hour,min,sec.
step 2:USing a default constructor,set the values using the predefined Dateclass.
step 3:use parameterised constructors to set the values for the members.
step 4:Define the methods getYear(),getMonth(),getDate(),  to return the year,month,date .
step 5:Define the methods setYear(),setMonth(),setDate. to set the values for year,month,date,.
step 6:Define the method after() with the return type boolean to check whether the given date is after the current date.
step 7:Define the method before() with the return type boolean to check whether the given date is before the current date.
step 8:Define the method compareTo() with the return type integer to compare two dates.it will return 0 if both are same,will return 1 if date is after currrent date else it returns -1.
step 9:terminate the class.
step 10:Define the datetest and define the main() in it.
step 11:Create many objects for the class MyDate and access the methods of the class using different objects.
step 12:Display the result.
step 13:terminate the main() and class.

Sunday 21 July 2013

IT2305  java Lab programs:

1. Develop with suitable hierarchy, classes for Point, Shape, Rectangle, Square, Circle, Ellipse, Triangle, Polygon, etc.  Design a simple test application to demonstrate dynamic polymorphism.

Algorithm:
step 1:Define the class point.
step 2:Define the method show().
step 3:Teminate the class.
step 4:Define the class shape which extends from point.
step 5:Define the class show() make a call for the super class show().
step 6:Terminate the class.
step 7:Define the class rectangle that extend from the class shape.
step 8:Declar the datamembers l&b in integer.
step 9:Define the method getdata() to get the l and b values.
step 10:Define the show() to display the area.
step 11:Terminate the class.
step 12:Define the class square that extend from the class shape.
step 13:Declar the datamembers a in integer.
step 14:Define the method gdata() to get the a values.
step 15:Define the sarea() to display the area.
step 16:Terminate the class.
step 17:Define the class circle and triangle that extend from the class shape and display the result.
step 18:Define the shapetest and define the main() method in it.
step 19:create objects for the classes rectangle,square,circle and triangle and access their methods.
step 20:display the result.
step 21:Terminate the main and class.

2.Matrix addition and Multiplication

3.Arrays Class methods.
Note:
1.Write the algorithm for above three programs
2.Without the observation don't enter into lab.

Monday 8 July 2013

TOMORROW LAB PROGRAM

1. Design a class for Complex numbers in Java.  In addition to methods for basic operations on complex numbers, provide a method to return the number of active objects created.

ALGORITHM:
step 1:Define the class complex with the members real,img in double.
step 2:Declare a static integer variable n and initialise it as 0.
step 3:Using default constructor,increment the 'n' value by 1 and initialize read & img as0.0.
step 4:Define the method add() with the returntype complex to add two complex numbers.
step 5:Define the method sub() with the returntype complex to sub two complex numbers.
step 6:Define the method read() to get real&img.
step 7:Define the static method objcount() to count the number if objects created.
step 8:Define the method print() to display the real & imaginary part.
step 9:Terminate the class.
step 10:Define the class compresult and write the main() in it.
step 11:Create objects for the class complex and access the methods using the objects.
The method objcount can be accessed using the classname only.
step 12:Display the result.
step 13:Terminate the main() and the class.  

Wednesday 3 July 2013

JAVA CLASS TEST QUESTION

RAJALAKSHMI ENGINEERING COLLEGE
DEPARTMENT OF INFORMATION TECHNOLOGY
IT2301 – JAVA PROGRAMMING
QUESTION BANK FOR CLASS TEST 1
 11.What is the difference between a constructor and a method?
    2.What is JVM?
   3.Why java is called as Platform Independent Language?
  4.4.List the features of Java Language.
   5.What is the use of static keyword in main method?    

PART-B

     

     What is constructor in java? Why constructor does not have return type in java? Explain its types with proper example.