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.

Thursday, 17 November 2011

ANNAUNIVERSITY QUESTION PAPER:

B.E./B.Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2010

IT 2301 — JAVA PROGRAMMING
PART A — (10 × 2 = 20 Marks)
1. What is the difference between static and non-static variables?
2. What is the purpose of finalization?
3. What is the difference between the String and String Buffer classes?
4. Can an abstract class be final? Why?
5. What is an anonymous inner class?
6. What is the difference between the File and Random Access File classes?
7. What are the advantages of the event-delegation model?
8. What happens if an exception is not caught?
9. What is the use of Reflection API?
10. What are three ways in which a thread can enter the waiting state?

PART B — (5 × 16 = 80 Marks)

11. (a) Explain briefly the following object oriented concepts.
(i) Abstraction and Encapsulation. (4)
(ii) Methods and messages. (4)
(iii) Inheritance. (4)
(iv) Polymorphism. (4)
Or

(b) (i) How objects are constructed? Explain constructor overloading with
an example. (Marks 10)
(ii) Write short notes on access specifiers in java. (Marks 6)

12. (a) What is a Package? What are the benefits of using packages? Write down
the steps in creating a package and using it in a java program with an
example. (Marks 16)
Or
(b) What is Dynamic binding? Show with an example how dynamic binding
works. (Marks 16)

13. (a) What is object cloning? Why it is needed? Explain how objects are cloned.
(Marks 16)
Or
(b) How is a Frame created? Write a java program that creates a product
enquirer form using frames. (Marks 16)

14. (a) With a neat diagram explain the Model view controller design pattern
and list out the advantages and disadvantages of using it in designing an
application. (Marks 16)
Or
(b) What is an Exception? Explain how to throw, catch and handle
Exceptions. (Marks 16)

15. (a) What is Generic programming and why is it needed? List the limitations
and restrictions of generic programming. (Marks 16)
Or
(b) Explain how to create threads. Write a java program that prints numbers
from 1 to 10 line by line after every 5 seconds. (Marks 16)





  
B.E./B.Tech. DEGREE EXAMINATION, APRIL/MAY 2011
Fifth Semester Information Technology
IT 2301 — JAVA PROGRAMMING
PART A — (10 × 2 = 20 marks)
1.  Give the properties of abstract classes and methods and write a suitable
example.
2.  Why does Java not support destructors and how does the finalize method
help in garbage collection?
3.  Write a declaration to convert the value ‘‘Programmer’’ in the string
variable ‘convert’ to ‘‘programming’’.
4.  Distinguish between static and dynamic binding.
5.  How does the declaration of a local inner class differ from the declaration
of an anonymous inner class?
6.  Write a code to copy the contents of the file input.txt one byte at a time to
output.txt using FileInputstream and FileOutputStream.
7.  When do the following events occur?
  (a) AdjustmentEvent
  (b) ItemEvent
8.  Write down the statements used to create a JFrame and a JButton and
then add the JButton to the JFrame.
9.  List any two advantages of type parameters.
10.  When would you use the CountDownLatch synchronizers and Exchange
Synchronizers?
PART B — (5 × 16 = 80 marks)
11.  (a) (i) Write a program to find whether a number is a palindrome or
not.   (8)
   (ii) Discuss the working and meaning of the ‘‘static’’ modifier with
suitable examples.   (8)
Or
  (b) Explain in detail as to how inheritance and polymorphism are
supported in Java with necessary examples. (16)
12.  (a) (i) Write a Java program to perform matrix multiplication using
arrays.   (8)
   (ii) Write a java program to search for a number in the given array
using binary search.   (8)
Or
  (b) Give a detailed explanation of packages in Java(16).
13.  (a) What is reflection and how does it help to manipulate java code?  (16)
Or
  (b) Consider a class person with attributes firstname and lastname.
Write a java program to create and clone instances  of the Person
class. (16)
14.  (a) Write a program to create a calculator using swings with the four
basic arithmetic operations : +, –, *, /. (16)
Or
  (b) Draw the exception hierarchy in java and explain with examples
throwing and catching exceptions and the common exceptions.(16)
15.  (a) With suitable examples consider the number of restrictions to
consider when working with java generics. (16)
Or
  (b) Write short notes on what threads are and the thread states and
properties. (16)