tag:blogger.com,1999:blog-4994607865659965542024-02-21T03:18:03.397+05:30Java is the future !Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.comBlogger129125tag:blogger.com,1999:blog-499460786565996554.post-57657961830543790882011-08-16T12:50:00.000+05:302011-08-16T12:50:15.055+05:30Quiz of the day | OCPJP - Aug 16, 2011
What will be the result of compiling and running the following code:
Options :
a) true
true
b) false
true
c) false
false
d) None of the above
Solution: Correct choice is option B.
Creating a new instance of the class File, you're not yet making an actual file, you're just creating a filename. So file.exists() return false.
createNewFile() method created an actual file. So file.exists() Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-68935758781301905792011-08-16T11:59:00.001+05:302011-08-16T12:00:40.059+05:30How to become a Java developer?
"I want to be a java developer, What are the all skills that I need to have. I have learned the core java in college but what now?"Does this sound a familiar question! You too may have a similar question in your mind. Don't worry, This article explains what are all the skills that you will need to be a Java web developer, and what are the skills that you are expected to have when you appear for Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com6tag:blogger.com,1999:blog-499460786565996554.post-22025611855281919002011-08-16T10:23:00.000+05:302011-08-16T10:23:35.806+05:30Quiz of the day | OCPJP - 16 Aug 2011
What is the output for the above code ?
Options :
a) Compile with error - Not allowed to override the return type of a method with a subtype of the original type.
b) class A - return C
c) class B - return D
d) Runtime ExceptionAnonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-57086028862875256032011-05-14T10:23:00.000+05:302011-05-14T10:23:24.674+05:30char a = '\u000A'. Why is this invalid?
Unicode escape characters of the form '\Uxxxx', where xxxx is a hexadecimal value, are processed very early in the translation process (see JLS 3.10.4 ). As a result, the special characters '0A' (line feed) and '0D' (carriage return) are interpreted literally as "end of line."
For example, the expression...
char A = '\u000A';...therefore becomes...
char A =;...which results in a Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-5926694150549109752011-05-14T06:41:00.000+05:302011-05-14T06:41:38.480+05:30Is it allowed to declare the main method private?
Former JVM versions (pre-1.4) allowed the main method to have any accessibility (private, etc). This incompatibility with Section 12.1.4 of the Java Language Specification has been fixed as of version 1.4. In order to invoke a main method from the command-line, it is now mandatory to declare the main method as follows:
public static void main (String[] args)If the main method has any access Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-67885481890550004062011-04-24T13:47:00.001+05:302011-04-24T13:52:52.166+05:30What are some potential trips/traps in the SCJP exam?
Two top-level public classes cannot be in the same source file.
main() cannot call an instance (non-static) method.
Methods can have the same name as the constructor(s).
Watch for thread initiation with classes that don't have a run() method.
Local classes cannot access non-final variables.
Case statements must have values within permissible range.
Watch for Math class being an option for Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-64035985117293500952011-04-24T13:27:00.002+05:302011-04-24T13:29:56.347+05:30What's up with integers not being equal to one another? The following code prints "true, true, false, true". Shouldn't it be "true, true, true, true"?
The key to understanding this is that the JVM uses a process called "boxing" (or "auto-boxing") when converting an int (like 127) to an Integer object. This involves calling the Integer.valueOf(127) method. The JavaDoc:java.lang.Integer#valueOf(int) says: "Returns a Integer instance representing the specified int value. If a new Integer instance is not required, this method should generally beAnonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-31181029509642096492011-04-24T11:48:00.002+05:302011-04-24T11:50:44.929+05:30How to convert a String array to ArrayList?1.
2.
3.
Note: In the solution no 1 Arrays.asList() is efficient because it doesn't need to copy the content of the array. This method returns a List that is a "view" onto the array - a wrapper that makes the array look like a list. When you change an element in the list, the element in the original array is also changed. Note that the list is fixed size - if you try to add elementsAnonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-35520843411411247122011-04-24T01:18:00.003+05:302011-04-24T01:18:55.191+05:30Difference between Class reference and Interface referenceInterface provides the base for the concrete classes. It defines the contract which must be full filled by the implementing classes. So it can be use full in case where you need polymorphism. for example if you have some classes and interface like:
Here if you want to do some generic work which is common for both the doctors (doCheckUp) you should use the interface like
In this case Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-69799594366799786072011-01-30T18:58:00.002+05:302011-01-30T19:00:36.386+05:30Top 10 errors java programmers make
Whether you program regularly in Java, and know it like the back of your hand, or whether you're new to the language or a casual programmer, you'll make mistakes. It's natural, it's human, and guess what? You'll more than likely make the same mistakes that others do, over and over again. Here's my top ten list of errors that we all seem to make at one time or another, how to spot them, andAnonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com2tag:blogger.com,1999:blog-499460786565996554.post-75671267025087426692010-12-05T13:20:00.002+05:302011-08-17T00:56:49.324+05:30Top 5 reasons that make SCJP Certification Exam tough1.You are not in reality of the exam preparation
Most of the time preparation for this certification exam is approached in the conventional style especially the way you did preparation back in school and college days. However the reality of this exam is that you are no longer in school or in college (some exceptions maybe there) you are in a full time job and you have to manage job Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com1tag:blogger.com,1999:blog-499460786565996554.post-13560589380596452252010-12-03T07:20:00.003+05:302010-12-03T07:32:56.044+05:30Quiz of the Day | December 3, 2010What will be the output when you compile and execute the following program?
Choose one answer.
a. Prints true
b. Prints false
c. Prints 9
d. Prints 2
e. Compiler error : Incorrect declaration of main method
f. None of these
Solution : Choice F is the correct answer.
The code does not compile because the && operator works only with Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-52837560872271522592010-11-22T06:29:00.004+05:302010-11-22T06:42:34.106+05:30How to obtain from where a Class is loaded
Source : "rgagnon.com"Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-33075337001172704082010-11-07T03:22:00.003+05:302010-12-03T07:29:11.832+05:30Quiz of the Day | November 7, 2010
What will happen when you attempt to compile and run the above code? (Assume that the code is compiled and run with assertions enabled.)
a. It will print odd and even numbers from 0 to 9 correctly (0 even and 1 odd).
b. It will print odd and even numbers from 0 to 9 incorrectly (0 odd and 1 even).
c. Compilation error at line 9.
d. Compilation error at line 10.
e. It Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-3274909470047966102010-11-06T13:02:00.003+05:302010-11-06T16:09:47.111+05:30Converting a 2d array of ints to char and string in JavaQuestion : How can i convert the ints in a 2d array into chars, and strings?
If i copy ints to a char array i just get the ascii code.For examplepublic int a[5][5]//some codepublic String b[5][5] = public int a[5][5]Answer : Quite frankly, the easiest approach would simply leave your array as-is... and convert int values toString's when you use them:
Integer.toString(a[5][5])Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-15128982943760515982010-11-06T01:20:00.006+05:302010-12-03T07:29:49.959+05:30Quiz of the Day | November 6, 2010What value is printed out by executing the above code?
a. 2.7
b. 1.7
c. 0.0
d. -1.0
Solution : Choice A is the correct answer.
In Java, all parameters are passed by value. In case of primitives, the copy of the variable is passed, while in case of object references, it's the copy of the reference that is passed.
When the argument is a primitive type, Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-84858723864739085292010-11-05T17:03:00.003+05:302010-11-22T06:45:13.004+05:30Quiz of the Day | November 5, 2010 [2]What will be printed on standard output if the following class is executed using the command "java Test 1 two 3" ?
a. 1
b. two
c. NumberFormatException
d. ArrayIndexOutOfBoundsException
e. Code does not compile
Solution : Choice C is the correct answer.
In Java, command line arguments are stored in the args array which is an argument to the main method. The Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-87301475785976767292010-11-05T16:54:00.005+05:302010-11-22T06:45:17.458+05:30Quiz of the Day | November 5, 2010What will be the result of compiling the following programs and executing it using the following command - java Child?
a. Prints 9
b. Compiler error at line 5
c. Compiler error at line 6
d. None of the above
Solution : Choice C is the correct answer.
You cannot access the protected variable in the Parent class from the Child class using the parent class reference. The Child Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-6281093779804245242010-11-04T01:54:00.003+05:302010-11-22T06:45:24.618+05:30Quiz of the Day | November 4, 2010Given the code below, which access modifiers (public, protected, or private) can legally be placed before the myMethod() method on line 3, if no other changes are made to the code? If line 3 is left as it is, which keywords can legally be placed before the myMethod method on line 8?
a. private or nothing (default) on line 3. Nothing (default) or protected or public on line 8.
b. public or Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-7412839192366858112010-11-03T10:04:00.005+05:302010-11-22T06:45:32.354+05:30Quiz of the Day | November 3, 2010
What will be the result of running the following code?
a.) The output: Value is - Hello
b.) The output: Value is - Hello world
c.) A compiler error
d.) No output
e.) An exception
Solution : Choice B is the correct answer.
Since the OR operator used here is not the short-circuit operator (which is "||"), both operands are evaluated even though the first operanditself is true which Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-84906056578703657242010-11-03T09:59:00.002+05:302010-11-22T06:45:39.596+05:30Quiz of the Day | November 2, 2010
What will happen when we try to compile the following code?
a. The compiler objects to line 3 comparing an Object with an array.
b. The compiler objects to line 5 casting an Object to an array of int primitives.
c. The compiler objects to line 11 comparing an Object to an array of Objects.
d. It compiles without error.
Solution : Choice D is the correct answer.
Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-87115491997431913692010-11-01T02:06:00.001+05:302010-11-22T06:45:44.957+05:30Quiz of the Day | November 1, 2010
Which of the following statements about the following code fragment are true?
a.) The code compiles successfully and displays "Test".
b.) Changing the code at line 13 to "public void print(int x)" will allow the code to compile correctly.
c.) The code fails to compile. The compiler complains about duplicate methods.
d.) Changing the return type on line 13 from 'void' to 'int' will allow the Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-62911692184065590142010-10-31T02:03:00.001+05:302010-11-22T06:45:50.148+05:30Quiz of the Day | Oct 31, 2010
How many objects will be eligible for garbage collection after the execution of line 9 in the following code?
a.) 8
b.) 14
c.) 15
d.) 16
Solution : This code creates 16 objects of type Double. Out of which, 15 Double objects are created by the iterations of the nested for loops at lines 6 and 7, and one more Double object is created at line 5. The very first iteration of the loop makes Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-30531141545313497122010-10-30T19:37:00.003+05:302010-11-22T06:45:55.954+05:30Quiz of the Day | Oct 30, 2010Which of the following statements are true about the relationships between the following classes?
a.) A Bar is a Baz
b.) A Foo has a Bar
c.) A Baz is a Foo
d.) A Foo is a Baz
e.) A Baz has a Bar
Solution : Choices B, C, and E are the correct answers. An instance of the Baz class is also an instance of the class Foo since the Baz class extends the Foo class. So choice C is correct.&Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0tag:blogger.com,1999:blog-499460786565996554.post-38834795676142087292010-10-29T18:11:00.006+05:302010-11-22T06:46:02.432+05:30Quiz of the Day | Oct 29, 2010Which of the following statements are true?
a. As soon as the reference count for an object reaches zero, it will be immediately garbage collected.
b. The finalize() method will not be invoked more than once by the JVM on the same object.
c. The finalize() method cannot be overloaded.
d. The garbage collection implementation is JVM-dependent.
e. If the finalize() method is overridden, a call to Anonymoushttp://www.blogger.com/profile/04990026893506195372noreply@blogger.com0