Questions tagged [ocpjp]

OCPJP (Oracle Certified Professional, Java Programmer), formerly Sun Certified Java Programmer (SCJP), is a certification for programmers experienced using the Java programming language. Achieving this certification provides clear evidence that a programmer understands the basic syntax and structure of the Java programming language.

http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=320&p_org_id=28&lang=US

80 questions
3
votes
2 answers

Can Stream's SKIP method making an infinite stream finite?

"The limit() and skip() methods make a Stream smaller. They could make a finite stream smaller, or they could make a finite stream out of an infinite stream. The method signatures are shown here: Stream limit(int maxSize) Stream skip(int…
subject-q
  • 91
  • 3
  • 19
3
votes
1 answer

Java generic type parameter not within its bound

Preparing for OCPJP 6 exam (that's why I'm using Java 1.6 compiler) I've noticed something unclear to me about Java Generics. Consider the following code: class A { public V useMe1(A a) { // OK return…
igrek51
  • 177
  • 1
  • 9
3
votes
2 answers

Anonymous innerclass declared in an interface: what is the outerclass?

Consider the following: public class OuterClass { private String attribute = "outer"; class InnerClass { private String attribute = "inner"; public doSomething() { System.out.println(this.attribute); …
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
2
votes
4 answers

Instantiating a Generic Class of Type

I'm studying for the SCJP/OCPJP and I came across a sample question that seams strange to me. The sample code instantiated two generic collections: List list = new ArrayList(); List list2 = new ArrayList
jeremyjjbrown
  • 7,772
  • 5
  • 43
  • 55
2
votes
4 answers

Solving upcasting/downcasting problems

Does anyone have any workable strategy for solving casting/upcasting questions? I understand when upcasting and downcasting is allowed but when the questions tend to have multiple objects involved i tend to get confused pretty quickly. For example,…
ziggy
  • 15,677
  • 67
  • 194
  • 287
2
votes
3 answers

Java Generics - Why is this method call considered an unchecked conversion

The following code examples compiles but with a compiler warning class Animal{} class Dog extends Animal{} class Cat extends Animal{} class SubArrayList extends ArrayList{} class ZiggyTest2{ public static void main(String[] args){ …
ziggy
  • 15,677
  • 67
  • 194
  • 287
2
votes
1 answer

If write(0x01234567) is called on an instance of output stream, what will be written to the destination of the stream?

Hi,I have a question If write(0x01234567) is called on an instance of output stream, what will be written to the destination of the stream? a. The bytes 0x01, 0x23, 0x34, 0x45, and 0x67, in that order. b. The bytes 0x67, 0x45, 0x34, 0x23, and 0x01,…
2
votes
2 answers

On non-existent merge() method mentioned in an OCPJP 8 exam topic in Stream - IZ0-809 exam

The last exam objective under "Java Streams" section in 1Z0-809 exam (Java 8 exam) reads: Use of merge() and flatMap() methods of the Streams There is no merge() method in Stream interface! There is a merge(Object, Object, BiFunction) method in…
Hari Kiran
  • 23
  • 5
2
votes
3 answers

why compilation fails for that example

I was working on SCJP6 dumps when I found this confusing exercise: Given classes defined in two different files: package packageA; public class Message { String getText() { return “text”; } } And: package packageB; public class XMLMessage…
Tarik
  • 4,961
  • 3
  • 36
  • 67
2
votes
3 answers

String getChars() method confusion

I am reading from K&B about Strings. For some extra know how, i was reading tutorial from Oracle. I am copying the source code from Oracle. public class StringDemo { public static void main(String[] args) { String palindrome = "Dot…
benz
  • 4,561
  • 7
  • 37
  • 68
2
votes
2 answers

Oracle Java 7 Certification: The private and protected access modifiers can be used with which entities?

I am experimenting the questions from Oracle for the Java 7 Associate certification. The application for the windows is created by Oracle Press (probably). They've sent it to me with the Book. Currently, I have one question which application says…
X-HuMan
  • 1,488
  • 1
  • 17
  • 37
2
votes
3 answers

Java: Possible to add 1 non-Comparable object to a TreeSet?

Here's my code: public static void main(String[] args){ TreeSet d = new TreeSet(); d.add(new Dog()); System.out.println(d.size()); } class Dog{ } As you can see, the Dog class is not a Comparable object and I sure did not…
mpmp
  • 2,409
  • 4
  • 33
  • 46
2
votes
2 answers

Should tricky questions exist on the OCPJP exam?

When I practice to take the OCJP exam, I see that the questions that I'm suppose to practice on are often trick questions which try to fool my into answering wrong. The example is from the Bathes / Sierra book and a typical trick question is: Now I…
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
2
votes
2 answers

Comparator issue in ocpjp sample questions

I am currently preparing for Java SE 7 Programmer exam and I tried to solve the sample questions on the Oracle site. I got stuck at this one: import java.util.*; public class Primes2 { public static void main(String[] args) { …
user998692
  • 5,172
  • 7
  • 40
  • 63
2
votes
1 answer

Treeset subsets

Hi I am having trouble understanding why the output is 'ex [6, 7, b, d] [6, 7, b]' for this piece of code. Please can someone advise how the subset is working with the numbers and letters? thanks import java.util.*; public class Corner { …
M_x_r
  • 596
  • 4
  • 11
  • 26