Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Wednesday, September 30, 2009

J2EE Class -1

Dear friends,

From today I would also like to focus on J2EE concepts.

What all you need to learn:

Besides your brain and a pencil, you also need Java, Tomcat 5, and a
computer.You do not need any Integrated Development Environment like Eclipse, etc. I strongly recommend you, not to use anything but a basic editor until you complete the J2EE tutorial.

GETTING THE SOFTWARE

* If you don’t already Java SE v1.5 or greater, you’ll need it.

* If you don’t already have Tomcat 5, go get it from:http://tomcat.apache.org/

* Select "Tomcat v5.5" in the Downloads menu on the left side of the home page.

* Scroll down to the "Binary Distributions" section and download the version of your
choice. If you do not know, then select the "Core" distribution; it is all you need.

* Save the installation file in a temporary directory.

* Install Tomcat.

--> For Windows, that means double-clicking the install.exe file and following the
installer wizard instructions.

--> For the others, unpack the install file into the place on your hard drive
where you want Tomcat to be.

* To make it easier to follow the book instructions, name the Tomcat home directory
"tomcat".

* Set environment variables for JAVA_HOME and TOMCAT_HOME.

Test Tomcat by launching the tomcat/bin/startup script (which is startup.sh) for
Linux/Unix/OS X. Point your browser to:
http://localhost:8080/ and you’ll see the Tomcat welcome page.

Tuesday, September 29, 2009

The To String method

The toString() Method Override toString() when we want to read something meaningful about the objects of our class. Code can call toString() on our object when it wants to read useful details about our object.

To be more clear, Now when we pass an object reference to the System.out.println() method, and for example, the object's toString() method is called as follows,

public class ClassA {
public static void main (String [] args) {
ClassA classA = new ClassA();
System.out.println(classA);
}
}


then, Running the ClassA class gives us the following output,

% Java ClassA
ClassA@10b62c9


The above output is what we get when we don't override the toString() method of class Object. It gives us the class name (at least that's meaningful) followed by the @ symbol, followed by the unsigned hexadecimal representation of the object's hashcode.

Trying to read this output might motivate us to override the toString() method in our classes, for example,

public class ClassA {
public static void main (String[] args) {
ClassB classB = new ClassB("Test the toString method", new Date());
System.out.println(classB);
}
}
class ClassB {
Date data1;
String data2;
ClassB(String data2, Date data1) {
this.data1 = data1;
this.data2 = data2;
}
public String toString() {
return ("The main aim of this program is to " + data2 +
". This program was written on " + data1);
}

}

The output of this would be a bit more readable:

% Java ClassA
The main aim of this program is to Test the toString method. This program was written on Tue Sep 29 10:26:59 IST 2009


For your Information, Some people refer the toString() method as the "spill-your-guts method," since the most common implementations of toString() simply tell us the object's state.

Thursday, September 24, 2009

Wednesday, September 23, 2009

ABOUT ME

Simple minded learner.

Contact emails:
chandrasekar_cse@yahoo.co.in
s.its.chandru@gmail.com

BLOG's OBJECTIVE

The main Objective Of the Blog is to share everything that I want to share with my readers.The Blog is a repository Of Facts, Health, and most importantly it focuses on Java. Java is a technology which always has something new to offer, no matter how many websites are launched to share it. So, through this blog, I would like to share my Java Experience and supported aptly by Java Quizzes, this is a Repository Of Knowledge which Helps everyone in need in some way or other.

Tuesday, September 22, 2009

Java Quiz -17

Hi friends,

Today I would like to post few more questions to test your capability.
Dont worry guys, I will give you the answer too! Try to answer it yourself without referring to the answers to test yourself.

Q: 1 Given a valid DateFormat object named df, and
1. Date data1 = new Date(0L);
2. String data2 = "September 22, 2009";
3. // insert code here
What updates data1's value with the date represented by data2?

A. 3. data1 = df.parse(data2);
B. 3. data1 = df.getDate(data2);
C. 3. try {
4. data1 = df.parse(data2);
5. } catch(ParseException e) { };
D. 3. try {
4. data1 = df.getDate(data2);
5. } catch(ParseException e) { };

Answer: C

Q: 2 Given:
1. public class ClassA {
2. private StringBuilder testStringBuilder = new StringBuuilder();
3. public void logTest(String data1, String data2) {
4. testStringBuilder.append(data1);
5. testStringBuilder.append(data2);
6. }
7. }
The programmer must guarantee that a single ClassA object works properly for a multi-threaded system. How must this code be changed to be thread-safe?

A. Synchronize the logTest method
B. No change is necessary, the current ClassA code is already thread-safe.
C. replace StringBuilder with just a String object and use the string concatenation (+=) within the logTest method
D. replace StringBuilder with StringBuffer

Answer: A

Q: 3 Given:
1 . import java.io.*;
2. public class ClassA implements Serializable {
3. private ClassB tree = new ClassB();
4. public static void main(String [] args) {
5. ClassA classA = new ClassA();
6. try {
7. FileOutputStream fileOutputStream = new FileOutputStream("ClassA.ser");
8. ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
9. objectOutputStream.writeObject(classA);
10.objectOutputStream.close();
11. } catch (Exception ex) { ex.printStackTrace(); }
12. } }
13.
14. class ClassB { }
What is the result?

A. An exception is thrown at runtime.
B. Compilation fails.
C. An instance of ClassA is serialized.
D. An instance of ClassA and an instance of ClassB are both serialized.

Answer: A

Q: 4 Assuming that the serializeClassC() and the deserializeClassC() methods
will correctly use Java serialization and given:
1. import java.io.*;
2. class ClassA {ClassA() { System.out.print("1"); } }
3. class ClassB extends ClassA implements Serializable {
4. ClassB() { System.out.print("2"); } }
5. public class ClassC extends ClassB { int size = 42;
6. public static void main(String [] args) {
7. ClassC b = new ClassC();
8. b.serializeClassC(b); // assume correct serialization
9. b = b.deserializeClassC(b); // assume correct
10. System.out.println(" restored " + b.size + " "); }
11. // more ClassC methods
12. }
What is the result?

A. Compilation fails.
B. 1 restored 42
C. 12 restored 42
D. 121 restored 42
E. 1212 restored 42
F. An exception is thrown at runtime.

Answer: D

Q: 5 Given this method in a class:
1. public String toString() {
2. StringBuffer testStringBuffer = new StringBuffer();
3. testStringBuffer.append('<');
4. testStringBuffer.append(this.name);
5. testStringBuffer.append('>');
6. return testStringBuffer.toString();
7. }
Which statement is true?

A. This code will perform well and converting the code to use StringBuilder will not enhance the performance.
B. This code will perform poorly. For better performance, the code should be rewritten:
return "<" + this.name + ">";
C. The programmer can replace StringBuffer with StringBuilder with no other changes.
D. This code is NOT thread-safe.

Answer: C

Q: 6 Given:
1. double data = 314159.26;
2. NumberFormat nf = NumberFormat.getInstance(Locale.ITALIAN);
3. String b;
4. //insert code here
Which code, inserted at line 4, sets the value of b to 314.159,26?

A. b = nf.parse( data );
B. b = nf.format( data );
C. b = nf.equals( data );
D. b = nf.parseObject( data );

Answer: B

Q: 7 Given:
System.out.format("Pi is approximately %d.", Math.PI);
What is the result?

A. Pi is approximately 3.141593.
B. Pi is approximately 3.
C. Compilation fails.
D. An exception is thrown at runtime.

Answer: D

Q: 8 Given:
1. public class ClassA implements Comparable {
2. private int data1, data2;
3. public ClassA(int data3, int data4) { data1 = data3; data2 = data4; }
4. public int getTestdata1() { return data1; }
5. public int getTestdata2() { return data2; }
6. public String toString() {
7. return "<" + data1 + "," + data2 + ">";
8. }
9. // insert code here
10. }
Which method will complete this class?

A. public int compareTo(Object object1){/*more code here*/}
B. public int compareTo(ClassA classA){/*more code here*/}
C. public int compare(ClassA classA1,ClassA classA2){/*more code here*/}
D. public int compare(Object object1,Object object2){/*more code here*/}

Answer: B

Q: 9 Given:
1. public class ClassA {
2. private String data1;
3. public ClassA(String data1) {
4. this.data1 = data1;
5. }
6. public boolean equals(Object o) {
7. if ( ! o instanceof ClassA ) return false;
8. ClassA p = (ClassA) o;
9. return p.data1.equals(this.data1);
10. }
11. }
Which statement is true?

A. A HashSet could contain multiple ClassA objects with the same data1.
B. Compilation fails because the hashCode method is not overridden.
C. All ClassA objects will have the same hash code because the hashCode method is not overridden.

Answer: A

Q: 10 Given:
13. public static void search(List listObject) {
14. listObject.clear();
15. listObject.add("data2");
16. listObject.add("data1");
17. listObject.add("data3");
18. System.out.println(Collections.binarySearch(listObject, "data1"));
19. }
What is the result of calling search with a valid List implementation?

A. 0
B. 1
C. 2
D. data1
E. data2
F. data3
G. The result cannot be defined.

Answer: G

Hope you found this useful! Kindly give me your comments regarding the same.Many more Quizzes are to be posted! Kindly make use of them as much as possible!

Monday, September 14, 2009

Java Quiz -16

Hi friends,

Today I would like to post few more questions to test your capability.
Dont worry guys, I will give you the answer too! Try to answer it yourself without referring to the answers to test yourself.

Q: 1 Given a method that must ensure that its parameter is not null:
1. public void test(Object data) {
2. // check for null data
...
10. System.out.println(data.getClass());
11. }
What, inserted at line 2, is the appropriate way to handle a null data?

A. assert data == null;
B. assert data != null, "data is null";
C. if (data == null) {
throw new AssertionException("data is null");
}
D. if (data == null) {
throw new IllegalArgumentException("data is null");
}

Answer: D

Q: 2 Given:
1. package javaQuiz;
2. public class ClassA {
3. public InnerClassB classb = new InnerClassB();
4. class InnerClassB {
5. public int data1;
6. public int data2;
7. }
8. }
Which statement is true about the class of an object that can reference the variable data1?

A. classb can be any class.
B. No class has access to data1.
C. The class must belong to the javaQuiz package.
D. The class must be a subclass of the class ClassA.

Answer: C

Q: 3 Which four statements are true? (Choose four.)

A. Has-a relationships can be implemented using instance variables.
B. Is-a relationships can be implemented using the extends keyword.
C. Has-a relationships should never be encapsulated.
D. An array or a collection can be used to implement a one-to-many has-a relationship.
E. The relationship between Movie and Actress is an example of an is-a relationship.
F. Is-a relationships can be implemented using the implements keyword.
G. Has-a relationships should be implemented using inheritance.

Answer: A, B, D, F

Q: 4 Given:
0. public class ClassA {
1.
2. private String data1;
3. private Integer data2;
4. public String data3;
5.
6. public void test(String data1,
7. String data3,
8. Integer data2) {
9. this.data1 = data1;
10. this.data3 = data3;
11. this.data2 = data2;
12. }
13. }
Which statement is true?

A. The code demonstrates polymorphism.
B. The class is fully encapsulated.
C. The data3 variable breaks encapsulation.
D. The data1 and data2 variables break polymorphism.
E. The test method breaks encapsulation.

Answer: C

Q: 5 Given:
0. abstract class ClassA {
1. abstract void test1();
2. void test2() { }
3. }
4. class ClassB extends ClassA {
5. void test1() { }
6. void test2() { }
7. }
8. class ClassC extends ClassB { void test3() { } }
and:
ClassA classA = new ClassB();
ClassC classB = new ClassC();
ClassA classC = new ClassC();
What are four valid examples of polymorphic method calls? (Choose four.)

A. classA.test2();
B. classC.test2();
C. classC.test3();
D. classC.test1();
E. classB.test3();
F. classA.test1();

Answer: A, B, D, F

Q: 6 Given:
1. interface ClassA { public void test(); }
...
10. class ClassB {}
...
20. class ClassC extends ClassB {
21. ClassD classD;
22. }
...
30. class ClassE extends ClassC implements ClassA{
31. public void test() {}
32. }
...
40. class ClassF implements ClassA{
41. public void test() {}
42. }
Which three are true? (Choose three.)

A. ClassF is-a ClassB
B. ClassF is-a ClassA
C. ClassC is-a ClassB
D. ClassC is-a ClassA
E. ClassF has-a ClassB
F. ClassE has-a ClassD
G. ClassE has-a ClassA

Answer: B, C, F

Q: 7 Given:
1. public class ClassA {
2. protected int test(int data) { return 0; }
3. }
4. class ClassB extends ClassA {
5. // insert code here
6. }
Which five methods, inserted independently at line 5, will compile? (Choose five.)

A. public int test(int data1) { return 0; }
B. private int test(int data1) { return 0; }
C. private int test(long data1) { return 0; }
D. protected long test(int data1) { return 0; }
E. protected int test(long data1) { return 0; }
F. protected long test(long data1) { return 0; }
G. protected long test(int data1, int data2) { return 0; }

Answer: A, C, E, F, G

Q: 8 Given:
1. public class ClassA {
2. protected static int test(int data1, int data2) { return data1 * data2;}
3. }
and:
10. public class ClassB extends ClassA{
11. public static int test(int data1, int data2) {
12. int data3 = super.test(data1, data2);
13. return data3;
14. }
15. }
and:
20. ClassB classB = new ClassB ();
21. System.out.println(classB.test(3,4));
22. System.out.println(ClassB.test(2,2));
What is the result?

A. 12
4
B. The code runs with no output.
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 11.
E. Compilation fails because of an error in line 12.
F. Compilation fails because of an error in line 21.

Answer: E

Q: 9 Given:
1. class ClassA {
2. java.util.ArrayList data1;
3. public final void testData(String data2) {
4. data1.add(data2);
5. }
6. }
7. public class ClassB extends ClassA {
8. public void testData(String data2) {
9. System.out.println("Cannot add Data1");
10. }
11. public static void main(String[] args) {
12. ClassA classA = new ClassB();
13. classA.testData("Data2");
14. }
15. }
What is the result?

A. The code runs with no output.
B. A NullPointerException is thrown in Line 4.
C. Compilation fails.
D. Cannot add Data1

Answer: C

Q: 10 Which three statements are true? (Choose three.)

A. A final method in class ClassA can be abstract if and only if ClassA is abstract.
B. A protected method in class ClassA can be overridden by any subclass of ClassA.
C. A private static method can be called only within other static methods in class ClassA.
D. A non-static public final method in class ClassA can be overridden in any subclass of ClassA.
E. A public static method in class ClassA can be called by a subclass of ClassA without explicitly referencing the class ClassA.
F. A method with the same signature as a private final method in class ClassA can be implemented in a subclass of ClassA.
G. A protected method in class ClassA can be overridden by a subclass only if the subclass is in the same package as ClassA.

Answer: B, E, F

Hope you found this useful! Kindly give me your comments regarding the same.Many more Quizzes are yet to be posted! Kindly make use of them as much as possible!

Friday, September 11, 2009

Testing and Concepts

Hi friends,

Today I would like to present few points related to Testing and some new Concepts related to Java.I assure you that it will be very informative for the readers.

Round : Testing

1.What is Black Box testing and white box testing?

Black Box Testing:
Also known as functional testing. A software testing technique whereby the internal workings of the item being tested are not known by the tester.

White Box Testing:
Also known as glass box, structural, clear box and open box testing. A software testing technique whereby explicit knowledge of the internal workings of the item being tested are used to select the test data. Unlike black box testing, white box testing uses specific knowledge of programming code to examine outputs.

2.What is the name of the testing supposed to be written by the developers?
White Box Testing.

3.Give the name of 2 performance of testing tools?
Apache Jmeter,curl loader.

4.Give the name of 2 automated testing tools?
QTP and Winrunner,Rational Robot.

5.Difference between stress testing and load testing?
Stress Testing : To test how the application is responding while we enter maximum length of strings into the application.
Load Testing : To test the application respond(response time) by increasing the number of users.



Round:Concepts

1.Namespace
As a rule, names in a namespace cannot have more than one meaning, that is, two or more things cannot share the same name.

2.Lazy loading
Lazy loading, also known as dynamic function loading , is a mode that allows a developer to specify what components of a program should not be loaded into storage by default when a program is started. Ordinarily, the system loader automatically loads the initial program and all of its dependent components at the same time. In lazy loading, dependents are only loaded as they are specifically requested. Lazy loading can be used to improve the performance of a program if most of the dependent components are never actually used.

3.Two Phase Commit
The two-phase commit strategy is designed to ensure that either all the databases are updated or none of them, so that the databases remain synchronized.

4.Server affinity
Server affinity refers to the characteristics of each load distribution facility that take these constraints into account. The load distribution facility recognizes that multiple servers can be acceptable targets for a request. However, it also recognizes that each request can be directed to a particular server where it is handled better or faster.

Server affinity can be weak or strong.

In weak server affinity, the system attempts to enforce the desired affinity for the majority of requests, but does not always guarantee that this affinity will be respected.
In strong server affinity, the system guarantees that affinity is always respected and generates an error when it cannot direct a request to the appropriate server.

5.Soft Deletion.
There also has to be a special handling of the delete operation. Not every client has enough space for every database item. Sometimes we want to remove an item from just one client, but not from the others.
Introduce a flag to an existing table which indicates that a row has been deleted (this is called a soft/logical delete) instead of actually deleting the row (a hard delete).

Hope this topic was useful to you, Please Post your comments!

Thursday, September 10, 2009

About Product,Companies and Databases

Hi friends,

Today I would like to present few points related to Product,Companies and Databases which would be helpful for the readers.

Round:About Product and Companies

1.How is the company that tells the “System applications and products for data processing”better known as?
SAP

2.Five colleagues working for patni computers ,resigned their job and started a company with an investment of 10000.Today this company is a house hold name. Which company we are talking about?
Infosys

3.Mark Shuttleworth is a South African entrepreneur who was the second self funded space tourist. Which software product is he responsible for?

Ubuntu

4.Which product is advertised “Hello coming in june”.This product is now a rage and set the benchmark in its category.
Ipod


5.Microsoft is accused by Apple to have copies of Apple's windows or gui concept. From which company/organization did Apple copy it from?
Xerox


Round:Databases

1.What is surrogate key?
A surrogate key in a is a unique identifier for either an entity in the modeled world or an object in the database. The surrogate key is not derived from application data.
A surrogate should have the following
the value is unique system-wide, hence never reused;
the value is system generated;
the value is not manipulable by the user or application;
the value contains no semantic meaning;
the value is not visible to the user or application;


2.What is the difference between union and unionall?
Union will filter duplicate values but union all will not filter duplicate values.


3.Every non-key attribute if fully functionally dependent on primary key.Which normal form it is?
2nd Normal form.


4.What is the difference between primary key and unique key?
The column holding the primary key constraint cannot accept null values.whereas column holding the unique constraint can accept null values .

5.What is the difference between DELETE TABLE and TRUNCATE TABLE?
TRUNCATE is a DDL command and cannot be rolled back. All of the memory space is released back to the server.
DELETE is a DML command and can be rolled back.

Hope this topic was useful to you, Please Post your comments!

Wednesday, September 9, 2009

People and Java code debugging

Hi friends,

Today I would like to present few concepts in People related to Open Source and Java code debugging which would be helpful for the readers.

Without wasting further time, Here We Go!
Round :People

1.Who created Java?
James Gosling(born May 19, 1955 near Calgary, Alberta, Canada).

2.Who invented C++?
Bjarne Stroutstrup.

3.Who is the well known founder of Oracle?
Lawrence Joseph Larry Ellison.

4.Who is the well known founder of Apple?
Steven Paul Jobs.

5.He is from Moolaipozhi village near Tirunelvelli.Went on to start an IT company which is among top ten Indian IT services firms.
Who is this man and which company he create?

Shiv Nadar - HCL

Round : Java code debugging

1.public class Test {
public static void main(String[] args) throws Exception{
BigInteger fiveThousand = new BigInteger("5000");
BigInteger fiftyThousand = new BigInteger("50000");
BigInteger fiveHundredThousand = new BigInteger("500000");
BigInteger Total =BigInteger.ZERO;
System.out.println(Total);
Total.add(fiveThousand);
Total.add(fiftyThousand);
Total.add(fiveHundredThousand);
System.out.println(Total);
}
}
Output:0


2.package com.planetsoft;
public class Me{
public static void main(String[] args){
System.out.println(Me.class.getName().replaceAll(“.”,”\”)+”.class”);
}
output://///////////////.class


3..public boolean isOdd(int i){
return i%2==1;
}
Output: if we give odd numbers with negative it will return false . For eg: Lets take the value of i=-3 , after computing i%2 the value will be -1 and it will check -1==1 ,hence both not equals it will return false.


4..Write a one line method that takes a list and returns a list , eliminating duplicates and preserving the order of the original list?
Let duplicatedList be a Array list variable with duplicate values.whereas
LinkedHashSet list = new inkedHashSet(duplicatedList);



5. Write a one line method that takes comma a demilited strings and return a string[],each comma may be followed by zero or more spaces which must be ignored by the method.
It can be achieved using the regular expression.Here is the example using String,Similar way we can do that for string array.
String s = ", There , , a , is a , , , null , object ,";
s=s.replaceAll("%*, *","" );
System.out.println(s);



1.public class TestList {
public static void main(String[] args) throws Exception{
final long micros_perDay = 24*60*60*1000*1000;
final long macros_perDay = 24*60*60*1000;
System.out.println(micros_perDay/macros_perDay);
}
} output:5


2.public class AnimalFarm {
public static void main(String[] args) throws IOException{
final String pig = "length: 10";
final String pig1 = "length :"+pig.length();
System.out.println("animals are equal"+pig==pig1);

}
}
output:false


3.public class SetMagic {
public static void main(String[] args) throws IOException{
int[] vals = {10,012,14,016};
Set magic = new HashSet();
for(int i=0;i magic.add(vals[i]);
}System.out.println(magic.size());
}
}

output:2

4.public class Increment {
public static void main(String[] args){
int j=0;
for(int i=0;i<100;i++){
j=j++;
}
System.out.println(j);
}
}

output:0

5.Provide a definition for i so that the loop turns into a infinite loop.
while(i!=i){
system.out.println(“please stop”);
}
output: we can declare i
double i=Double.Nan;

Hope this topic was useful to you, Please Post your comments!

Monday, September 7, 2009

Java Quiz -15

Hi friends,

Today I would like to present few concepts in Open Source and Java API's in today's Quiz which would be helpful for the readers.

Without wasting further time, Here We Go!

Round : Open Source Round

1.Who started the open source movement?
Richard Stallman

2.What does”free as freedom, free as in beer” means in the context of Open Source?
“free as freedom” phrase describes that the users can modify the functionality of the open source.
“free as in beer” phrase describes that the users can get the liscence free of cost.


3.Give the name three Open Source softwares?
UNIX,LINUX,Perl

4.Give the name of three open source databases?
Hsql,MySql,PostgreSQL


5.What is the name of open source webserver which is most widely used webserver in the world?
Apache,Jakarta Tomcat,Tornado

Round : Java API's Round

1. How do you achieve custom serialization?
We can achieve this by overriding the writeObject() and readObject() methods in ObjectOutputStream and ObjectInputStream.

2. I have an int column in the database that is null.
I do a rs.getInt() on that column and get a 0.
How do u find out whether the column has a value of 0 or its null?

Using the rs.wasNull() will return a boolean.

3.I have a list of String objects.
I want to create string array from the list not an object array.
How do u achieve this?

ArrayList a1 = new ArrayList();
a1.add("1");
a1.add("2");
a1.add("3");
String st1[] = new String[a.size()];
for(int i=0; i st1[i]=a1.get(i);
}

Hope you found this useful! Kindly give me your comments regarding the same.Many more Quizzes are yet to be posted! Kindly make use of them as much as possible!

Friday, September 4, 2009

Round :Basic Computer Science

Hi friends,

Its been sometime since we shared some information regarding the concepts(For those who missed out, We had been doing Few Java Quizzes! Check It out Here 
http://helptotheneeded.blogspot.com/search/label/Java%20Quiz)


Today I would like to present few concepts in basic Computer Science which would be helpful for the readers

Without wasting further time, Here We Go!

1.Give names of two sorting algorithms
  Bubble sort,Insertion sort,Shell sort,Merge sort,Heap sort,Quick sort,Radix sort,Bucket sort,Distribution sort,Shuffle sort.

2.What is the name of the style of programming where the function calls itself?
  Recursion

3.Name any two searching algorithms
  Breadth-First search,Depth limited search,Kruskal's algorithms,Prim's algorithms,Grover's algorithms,Dijikistra's algorithms.

4.What is Pointer?
  A pointer is a variable which contains the address in memory of another variable.

5.Give two names of typical data structure:
  Stack,Queue,Linked list,Doubly Linked List.

6.What is priority queue?
  An element's priority is the time that element was inserted.

7.What is a binary tree?
  A binary tree is a in which each node has at most two .
  -The left of a node contains only nodes with keys less than the node's key. -The right subtree of a node contains only nodes with keys greater than node's key.Both the left and right subtrees must also be binary search trees. 

8.What is a self Referential structure?
  It is a important characteristic of the data structures used to implement lists , is that they contain, as a member, a reference variable of the same type as the class itself. For this reason, these data structures are frequently called self-referential or recursive data structures .

9.What is/are difference(s) between tree and graph?
  -Tree has no loop but graph has loops. 
  -Tree always has direction but graph do not have direction.

10.What is the complexity of the Big O notation in the following pseudo code:
 n=100;
 for(i=O;i  do something;
 }
  The complexity of the Big O notation is o(n)..

Thursday, September 3, 2009

Java Acronyms

Hi friends,

Its been sometime since we shared some information regarding the concepts(For those who missed out, We had been doing Few Java Quizzes! Check It out Here 
http://helptotheneeded.blogspot.com/search/label/Java%20Quiz)


Today I would like to present few acronyms which would be helpful for the readers

Without wasting further time, Here We Go!

Round :Acronyms 


1.BPM – Business Process Management
-a field of management focused on aligning organizations with the wants and needs of clients.

2.JAXB- Java Architecture for XML Binding
-XML and Java technology are recognized as ideal building blocks for developing Web services and applications that access Web services. A new Java API called Java Architecture for XML Binding (JAXB) can make it easier to access XML documents from applications written in the Java programming language.

3.SOA-Service Oriented Architecture
-a computer systems architectural style for creating and using business processes, packaged as services

4.ORM-Object Relational Mapping
  -a software-programming issue in linking object-oriented code with relational databases .

5.XP – Extreme Programming
  -is a software engineering methodology which is intended to  
  improve software quality and responsiveness to changing 
  customer requirements.

6.3NF-Third Normal Form
  -In order to be in a third normal form,a relation must fulfill  
  the requirements to be in second normal form .Additionally all  
  attributes that are not dependent upon the primary key must be  
  eliminated.

7.MD5 – Message Digest Algorithm 5.
-In cryptography, MD5 (Message-Digest algorithm 5) is a widely used cryptographic hash function with a 128-bit hash value.

8.XSLT – Extensible Stylesheet Language Transformation.
  - a style sheet language for XML documents.

9.SAAS – Software As a Service.
-The sharing of end-user licenses and on-demand use may also reduce investment in server hardware or the shift of server use to SaaS suppliers of applications file services.

10.AOP – Aspect Oriented Programming

is a programming paradigm that increases modularity by allowing the separation of cross-cutting concerns, forming a basis for aspect-oriented software development.

Hope this topic was useful to you, Please Post your comments!

Wednesday, September 2, 2009

Java Quiz -14

Hi friends, 

Today I would like to post few more questions to test your capability. 
Dont worry guys, I will give you the answer too! Try to answer it yourself without referring to the answers to test yourself.

Q: 1 Given:

1. public class ClassA {
2. private int data1;
3. public void test1() {
4. int tips = data1;
5. data1 = tips + 1;
6. }
7. public void test2() {
8. for(int data2 = 0; data2 < 5; data2++) {
9. new Thread() {
10. public void test2() {
11. test1();
12. System.out.print(data1 + ", ");
13. } }.start();
14. } }
Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ?

A. move the line 12 print statement into the test1() method
B. change line 7 to public synchronized void test2() {
C. change the variable declaration on line 2 to private volatile int data1;
D. wrap the code inside the test1() method with a synchronized( this ) block
E. wrap the for loop code inside the test2() method with a synchronized block synchronized(this) { // for loop
code here }

Answer: A, D

Q: 2 Given:
classA1 and classA2 are public references available to many other threads. classA1 refers to a Thread and classA2 is an
Object. The thread classA1 is currently executing classA2.wait().
From another thread, what provides the most reliable way to ensure that classA1 will stop executing wait()?

A. classA1.notifyAll();
B. classA1.notify();
C. classA2.notify();
D. Object.notify();
E. Thread.notify();
F. classA2.notifyAll();

Answer: F

Q: 3 Given:
1. static void test() throws RuntimeException {
2. try {
3. System.out.print("test ");
4. throw new RuntimeException();
5. }
6. catch (Exception ex) { System.out.print("exception1 "); }
7. }
8. public static void main(String[] args) {
9. try { test(); }
10. catch (RuntimeException ex) { System.out.print("exception2 "); }
11. System.out.print("data ");
12. }
What is the result?

A. test data
B. A Throwable is thrown by main at exception2.
C. test exception2 data
D. test exception data
E. Compilation fails.

Answer: D

Q: 4 Given:
1. Float pi = new Float(10.14f);
2. if (pi > 10) {
3. System.out.print("pi is bigger than 10. ");
4. }
5. else {
6. System.out.print("pi is not bigger than 10. ");
7. }
8. finally {
9. System.out.println("Answer it yourself.");
10. }
What is the result?

A. An exception occurs at runtime.
B. pi is bigger than 10.
C. Compilation fails.
D. pi is bigger than 10. Answer it yourself.
E. pi is not bigger than 10. Answer it yourself.

Answer: C

Q: 5 Given:
1. public static Iterator test(List listdata) {
2. Collections.test(listdata);
3. return listdata.iterator();
4. }
5. public static void main(String[] args) {
6. List listdata = new ArrayList();
7. listdata.add("1"); listdata.add("2"); listdata.add("3");
8. for (Object objdata: test(listdata))
9. System.out.print(objdata + ", ");
10. }
What is the result?

A. Compilation fails.
B. 1, 2, 3,
C. 3, 2, 1,
D. The code runs with no output.
E. An exception is thrown at runtime.

Answer: A

Q: 6 Given:
1. class ClassA {
2. public void process() { System.out.print("ClassA,"); }
3. class ClassB extends ClassA {
4. public void process() throws IOException {
5. super.process();
6. System.out.print("ClassB,");
7. throw new IOException();
8. }
9. public static void main(String[] args) {
10. try { new ClassB().process(); }
11. catch (IOException e) { System.out.println("Exception"); }
What is the result?

A. Exception
B. ClassA,ClassB,Exception
C. Compilation fails because of an error in line 10.
D. Compilation fails because of an error in line 4.
E. ClassA NullPointerException is thrown at runtime.

Answer: D

Q: 7 Given:
1. try {
2. // some code here
3. } catch (NullPointerException e1) {
4. System.out.print("exception1");
5. } catch (RuntimeException e2) {
6. System.out.print("exception2");
7. } finally {
8. System.out.print("exception3");
9. }
What is the result if exception1 NullPointerException occurs on line 34?

A. exception3
B. exception1
C. exception1exception2
D. exception1exception3
E. exception2exception3
F. exception1exception2exception3

Answer: D

Q: 8 Given:
1. public static Collection get() {
2. Collection sorted = new LinkedList();
3. sorted.add("data2"); sorted.add("data3"); sorted.add("data1");
4. return sorted;
5. }
6. public static void main(String[] args) {
7. for (Object obj: get()) {
8. System.out.print(obj + ", ");
9. }
10. }
What is the result?

A. data1, data2, data3,
B. data2, data3, data1,
C. An exception is thrown at runtime.
D. Compilation fails.
E. The code runs with no output.

Answer: B

Q: 9 Given:
1. int z = 5;
2.
3. public void stuff1(int x) {
4. assert (x > 0);
5. switch(x) {
6. case 2: x = 3;
7. default: assert false; } }
8.
9. private void stuff2(int y) { assert (y < 0); }
10.
11. private void stuff3() { assert (stuff4()); }
12.
13. private boolean stuff4() { z = 6; return false; }
Which statement is true?

A. Only the assert statement on line 9 is used appropriately.
B. All of the assert statements are used appropriately.
C. The assert statements on lines 7 and 9 are used appropriately.
D. The assert statements on lines 4 and 7 are used appropriately.
E. The assert statements on lines 7 and 11 are used appropriately.
F. The assert statements on lines 7, 9, and 11 are used appropriately.
G. The assert statements on lines 4, 7, and 9 are used appropriately.

Answer: C

Q: 10 Given:
1. public class Test {
2. public static void main(String [] args) {
3. int data1 = 5;
4. boolean data2 = true;
5. boolean data3 = false;
6.
7. if ((data1 == 4) && !data3 )
8. System.out.print("test1 ");
9. System.out.print("test2 ");
10. if ((data3 = true) && data2 )
11. System.out.print("test3 ");
12. }
13. }
What is the result?

A. test2
B. test3
C. test1 test2
D. test2 test3
E. test1 test2 test3
F. An exception is thrown at runtime.
G. Compilation fails.

Answer: D

Hope you found this useful! Kindly give me your comments regarding the same.Many more Quizzes are yet to be posted! Kindly make use of them as much as possible! 

Tuesday, September 1, 2009

Java Quiz -13

Hi friends, 

Today I would like to post few more questions to test your capability. 
Dont worry guys, I will give you the answer too! Try to answer it yourself without referring to the answers to test yourself.

Q: 1 Given:

1. void waitTest() {
2. Object obj = new Object();
3. synchronized (Thread.currentThread()) {
4. obj.wait();
5. obj.notify();
6. }
7. }
Which statement is true?

A. This code may throw an InterruptedException.
B. This code may throw an IllegalStateException.
C. This code may throw a TimeoutException after ten minutes.
D. This code will not compile unless "obj.wait()" is replaced with "((Thread) obj).wait()".
E. Reversing the order of obj.wait() and obj.notify() may cause this method to complete normally.

F. A call to notify() or notifyAll() from another thread may cause this method to complete normally.

Answer: B

Q: 2 Given:
1. public class TestClassA implements Runnable {
2. public static void main (String[] args) throws Exception {
3. Thread t = new Thread(new TestClassA());
4. t.start();
5. System.out.print("Started");
6. t.join();
7. System.out.print("Complete");
8. }
9. public void run() {
10. for (int test = 0; test < 4; test++) {
11. System.out.print(test);
12. }
13. }
14. }
What can be a result?

A. An exception is thrown at runtime.
B. The code executes and prints "Started0123Complete".
C. The code executes and prints "StartedComplete".
D. Compilation fails.
E. The code executes and prints "StartedComplete0123".


Answer:B

Q: 3 Which ClassB code fragments will execute the method doData() in a separate
thread? (Choose two.)
A. new Thread() {
public void run() { doData(); }
};
B. new Thread() {
public void start() { doData(); }
};
C. new Thread() {
public void start() { doData(); }
}.run();
D. new Thread() {
public void run() { doData(); }
}.start();
E. new Thread(new Runnable() {
public void run() { doData(); }
}).run();
F. new Thread(new Runnable() {
public void run() { doData(); }
}).start();


Answer: D, F

Q: 4 Given:
1. interface A { public int getData(); }
2. class ClassB implements A {
3. public int getData() { return 1; }
4. }
5. class ClassC extends B {
6. // insert code here
7. }
Which ClassC code fragments, inserted individually at line 4, make use of polymorphism? (Choose three.)
A. public void add( ClassC c) { c.getData(); }
B. public void add( ClassB b) { b.getData(); }
C. public void add(A a) { a.getData(); }
D. public void add(A a, ClassB b) { a.getData(); }
E. public void add( ClassC c1, ClassC c2) { c1.getData(); }


Answer: B, C, D

Q: 5 Given:
1. public class ClassA {
2.
3. private String design;
4. private Integer data;
5. public String test;
6.
7. public void setClassdata(String design,
8. String test,
9. Integer data) {
10. this.design = design;
11. this.test = test;
12. this.data = data;
13. }
14. }
Which statement is true?
A. The class is fully encapsulated.
B. The code demonstrates polymorphism.
C. The test variable breaks encapsulation.
D. The design and data variables break polymorphism.
E. The setClassdata method breaks encapsulation.


Answer: C

Q: 6 Given:
1. package test;
2.
3. class ClassA {
4. public String data = "Java Quiz";
5. }
What can directly access and change the value of the variable data?
A. any class
B. only the ClassA class
C. any class in the test package
D. any class that extends ClassA


Answer: C

Q: 7 Given:
1. class ClassA { public String quiz() { return "answers"; } }
2. class ClassB extends ClassA {
3. public String quiz() { return "Test Answers"; }
4. }
5. class ClassC extends ClassA {
6. public String quiz() { return "Test Data"; }
7. }
...
11. ClassA ClassA = new ClassB();
12. ClassC ClassC = (ClassC)ClassA;
13. System.out.println(ClassC.quiz());
What is the result?
A. answers
B. Test Answers
C. Test Data
D. Compilation fails.
E. An exception is thrown at runtime.


Answer: E

Q: 8 Which three statements are true?
A. A final method in class ClassA can be abstract if and only if ClassA is abstract.
B. A protected method in class ClassA can be overridden by any subclass of ClassA.
C. A private static method can be called only within other static methods in class ClassA.
D. A non-static public final method in class ClassA can be overridden in any subclass of ClassA.
E. A public static method in class ClassA can be called by a subclass of ClassA without explicitly referencing the class ClassA.
F. A method with the same signature as a private final method in class ClassA can be implemented in a subclass of ClassA.
G. A protected method in class ClassA can be overridden by a subclass of A only if the subclass is in the same package as ClassA.


Answer: B, E, F

Q: 9 Which two statements are true about has-a and is-a relationships? 
A. Inheritance represents a has-a relationship.
B. Inheritance represents an is-a relationship.
C. Instance variables can be used when creating a has-a relationship.
D. Interfaces must be used when creating a has-a relationship.


Answer: B, C

Q: 10 Given:
11. Runnable r = new Runnable() {
12. public void testData() {
13. System.out.print("Test Quiz Data");
14. }
15. };
16. Thread t = new Thread(r) {
17. public void testData() {
18. System.out.print("Answer it yourself");
19. }
20. };
21. t.start();
What is the result?
A. Test Quiz Data
B. Answer it yourself
C. Compilation fails.
D. The code runs with no output.
E. An exception is thrown at runtime.


Answer: B

Hope you found this useful! Kindly give me your comments regarding the same.Many more Quizzes are yet to be posted! Kindly make use of them as much as possible!