Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

Thursday, 7 February 2013

SCJP Sun Certified Programmer for Java 6 Study Guide Exam(310-065) Class-8

Other (Nonaccess) Class Modifiers


You can modify a class declaration using the keyword final, abstract, or strictfp. These modifiers are in addition to whatever access control is on the class, so you could, for example, declare a class as both public and final. But you can't always mix nonaccess modifiers. You're free to use strictfp in combination with final, for example, but you must never, ever, ever mark a class as both final

Friday, 1 February 2013

SCJP Sun Certified Programmer for Java 6 Study Guide Exam(310-065) Class-7

Declare Classes (Exam Objective 1.1)


1.1 Develop code that declares classes (including abstract and all forms of nested classes), interfaces, and enums, and includes the appropriate use of package and import statements (including static imports).


When you write code in Java, you're writing classes or interfaces. Within those classes, as you know, are variables and methods (plus a few other things). How you declare your classes, methods, and variables dramatically affects your

Monday, 28 January 2013

SCJP Sun Certified Programmer for Java 6 Study Guide Exam(310-065) Class-6

Identifiers & JavaBeans (Objectives 1 & 2)


1) Develop code that declares, initializes, and uses primitives, arrays, enums, and objects as static, instance, and local variables. Also, use legal identifiers for variable names.

2) Develop code that declares both static and non-static methods, and—if appropriate— use method names that adhere to the JavaBeans naming standards. Also develop code that declares and uses a variable-length argument list.

Remember that when we list one or more Certification Objectives in the tutorial, as we just did, it means that the following section covers at least some part of that objective. Some objectives will be covered

Thursday, 24 January 2013

SCJP Sun Certified Programmer for Java 6 Study Guide Exam(310-065) Class-5

Declarations and Access Control


We assume that because you're planning on becoming certified, you already know the basics of Java. If you're completely new to the language, this chapter—and the rest of the tutorial—will be confusing; so be sure you know at least the basics of the language before diving into this tutorial. That said, we're starting with a brief, high-level refresher to put you back in the

Tuesday, 22 January 2013

SCJP Sun Certified Programmer for Java 6 Study Guide Exam(310-065) Class-4

Test-Taking Techniques


Without a plan of attack, candidates can become overwhelmed by the exam or become side-tracked and run out of time. For the most part, if you are comfortable with the material, the allotted time is more than enough to complete the exam. The trick is to keep the time from slipping away during

Saturday, 19 January 2013

SCJP Sun Certified Programmer for Java 6 Study Guide Exam(310-065) Class-3

Tips on Taking the Exam


There are 72 questions on the 310-065 (Java 6) exam. You will need to get at least 47 of them correct to pass—around 65%. You are given over three hours to complete the exam. This information is subject to change. Always check with Sun before taking the exam, at www.suned.sun.com.

You are allowed to answer questions in any order, and you can go

Thursday, 17 January 2013

SCJP Sun Certified Programmer for Java 6 Study Guide Exam(310-065) Class-2

Taking the Programmer's Exam


In a perfect world, you would be assessed for your true knowledge of a subject, not simply how you respond to a series of test questions. But life isn't perfect, and it just isn't practical to evaluate everyone's knowledge on a one-to-one basis.

For the majority of its certifications, Sun evaluates candidates using a computer based testing service operated by Sylvan Prometric. This

Wednesday, 16 January 2013

SCJP Sun Certified Programmer for Java 6 Study Guide Exam(310-065)

In This Tutorial


This Tutorial is organized to optimize your learning of the topics covered by the SCJP Java 6 exam. Whenever possible, we've organized the chapters to parallel the Sun objectives, but sometimes we'll mix up objectives or partially repeat them in order to present topics in an order better suited to learning

Friday, 9 March 2012

Sun Certified Java Programmer (SCJP) Questions

Question 1

The following code will give

1:    class Test

2:    {

3:         void show()

4:         {

5:             System.out.println("non-static method in Test");

6:         }

7:    }

8:    public class Q3 extends Test

9:    {

10:      static void show()

11:      {

12:          System.out.println("Overridden non-static method in Q3");

13:      }

14:

15:      public static void main(String[] args)

16:      {

17:          Q3 a = new Q3();

18:      }

19:   }

 

A) Compilation error at line 3.

B) Compilation error at line 10.

C) No compilation error, but runtime exception at line 3.

D) No compilation error, but runtime exception at line 10.

Answer : B

Explanation :

Sunday, 4 March 2012

Sun Certified Java Programmer (SCJP) Questions

Question 1

What will happen if you compile/run this code?

1: public class Q1 extends Thread

2: {

3:    public void run()

4:    {

5:       System.out.println("Before start method");

6:       this.stop();

7:       System.out.println("After stop method");

8:    }

9:

10:   public static void main(String[] args)

11:   {

12:      Q1 a = new Q1();

13:      a.start();

14:   }

15: }

 

A) Compilation error at line 7.

B) Runtime exception at line 7.

C) Prints "Before start method" and "After stop method".

D) Prints "Before start method" only.

Answer : D

Explanation :

Tuesday, 28 February 2012

Sun Certified Java Programmer (SCJP) Questions

Which is the most suitable Java collection class for storing various companies and their stock prices? It is required that the class should support synchronization inherently.


Choices:

  • A. Hashtable

  • B. HashMap

  • C. LinkedHashMap

  • D. HashSet

  • E. TreeMap


Correct choice:

  • A


Explanation:

Thursday, 23 February 2012

The Collections framework

List classes


A List is an ordered collection, which allows positional access and search.

The classes implementing List are ordered by index position. An ArrayList enables fast iteration and constant speed positional access. A Vector is similar to ArrayList, only slower because it is synchronized. LinkedList allows fast insertion and deletion at the beginning or end. It is commonly used for implementing stacks and queues. For instance:

Friday, 17 February 2012

The Collections framework

Collections and collections interfaces


Collections are objects used to group together and manipulate multiple data elements. They can dynamically grow and shrink, which is their advantage over arrays. Collections provide methods to add objects to a collection, remove objects from it, check if an object is

Monday, 13 February 2012

How many objects will be eligible for garbage collection after line 7?

public class TutorialGC
{

public static void main(String [] args)
{


Object a = new Integer(100);   // Line1
Object b = new Long(100);       // Line2
Object c = new String(“100″);  // Line3
a = null;                                        // Line4
a = c;                                             // Line5
c = b;                                             // Line6
b = a;                                             // Line7
// Rest of the code here


}


}

Choices:



  • A. 0

  • B. 1

  • C. 2

  • D. 3

  • E. Code does not compile


Correct choice:



  • B


Explanation:

Saturday, 11 February 2012

What will be the result of an attempt to compile and run the following program?

class Test
{

public static void main(String args[])
{


String s1 = "abc";
String s2 = "abc";
s1 += "xyz";
s2.concat("pqr");
s1.toUpperCase();
System.out.println(s1 + s2);


}


}

Choices:

  • A. "abcxyzabc"

  • B. "abcxyzabcpqr"

  • C. "ABCXYZabcpqr"

  • D. "ABCXYZabc"

  • E. Code does not compile


Correct choice:

  •  A


Explanation:

Monday, 6 February 2012

Wrapper classes

Wrapper classes correspond to the primitive data types in the Java language. These classes represent the primitive values as objects. All the wrapper classes except Character have two constructors -- one that takes the primitive value and another that takes the String representation of the value. For instance:

Integer i1 = new Integer(50);
Integer i2 = new Integer("50");


The Character class constructor takes a char type element as an

Wednesday, 1 February 2012

String and StringBuffer

Immutability of String objects


As you know, Strings are objects in Java code. These objects, however, are immutable. That is, their value, once assigned, can never be changed. For instance:

String msg = "Hello";
msg += " World";


Here the original String "Hello" is not changed. Instead, a new String is created with the value "Hello World" and assigned to the variable

Thursday, 26 January 2012

Fundamental classes in the java.lang package

Using the Math class


The Math class is final and all the methods defined in the Math class are static, which means you cannot inherit from the Math class and override these methods. Also, the Math class has a private constructor, so you cannot instantiate it.

The Math class has the following methods: ceil(), floor(), max(),

Saturday, 21 January 2012

Sun Certified Java Programmer (SCJP) Questions

Which of the following statements is not true about threads ?


Choices:



  • A. If the start() method is invoked twice on the same Thread object, an exception is thrown at runtime.

  • B. The order in which threads were started might differ from the order in which they actually run.

  • C. If the run() method is directly invoked on a Thread object, an

Saturday, 14 January 2012

Threads in Java – 2

Thread states


Threads can be in one of the following states:

New. After the thread is instantiated, the thread is in the New state until the start()method is invoked. In this state, the thread is not considered alive.

Runnable. A thread comes into the runnable state when the start() method is invoked on it. It can also enter the runnable state from the running state or blocked state. The thread is considered alive when it is in this state.

Running. A thread moves from the runnable state into the running state when the thread scheduler chooses it to be the currently running thread.

Alive, but not runnable. A thread can be alive but not in a runnable state for a variety