que alguno de ellos os pueda funcionar.
conseguidor 2.0
18 dic 2013
Remedios caseros para el resfriado
que alguno de ellos os pueda funcionar.
16 may 2013
Exploit de hamburguesas gratis en McDonald's
Quieres comer unas cuantas hamburguesas gratis de McDonald's y vives en Cataluña o Andorra (o cerca)? Simplemente te tienes que registrar en http://www.mcdonaldscupons.cat/, donde por cada vez que te registres te dan un cupón que puedes entregar a cambio de una hamburguesa, aunque sea la hamburguesa de 1€ sin queso, es gratis. Sólo comentar que no hace falta ni que introduzcas un correo real, por ello podéis aprovechar este pequeño "exploit" para comer hamburguesas gratis todos los días.Ya sabéis mandamases de McDonald's, a menos que queráis que pasen estas cosas, con este tipo de promociones online (web, aplicación, etc.) deberíais contratar el desarrollo del producto a una empresa o desarrollador que ofrezca productos de calidad, quizá para la próxima podríais contactar conmigo ;-).
13 ene 2013
Preparación para Certificación SCJP 1Z0-851. Tema 4
Question 1
Given:
.class Alien {
. String invade(short ships) { return "a few"; }
. String invade(short... ships) { return "many"; }
.}
.class Defender {
. public static void main(String [] args) {
. System.out.println(new Alien().invade(7));
. }
.}
What is the result?
a. The output is not predictable.
b. a few
c. An exception is thrown at runtime.
d. Compilation fails.
e. many
Answer: D
Question 2
Given:
.class Polish {
. public static void main(String[] args) {
. int x = 4;
. StringBuffer sb = new StringBuffer("..fedcba");
. sb.delete(3,6);
. sb.insert(3, "az");
. if(sb.length() > 6) x = sb.indexOf("b");
. sb.delete((x-3), (x-2));
. System.out.println(sb);
.} }
What is the result?
Seleccione una respuesta.
a. ..fezba
b. An exception is thrown at runtime.
c. Compilation fails.
d. ..azba
e. .faza
f. .fazba
g. .fzba
Answer: D
Question 3
Given:
. class Eggs {
. int doX(Long x, Long y) { return 1; }
. int doX(long... x) { return 2; }
. int doX(Integer x, Integer y) { return 3; }
. int doX(Number n, Number m) { return 4; }
. public static void main(String[] args) {
. new Eggs().go();
. }
. void go() {
. short s = 7;
. System.out.print(doX(s,s) + " ");
. System.out.println(doX(7,7));
.} }
What is the result?
a. 2 1
b. 3 3
c. 1 1
d. 4 3
e. 3 1
f. 2 3
g. 4 1
Answer: D
Question 4
Given:
1. class Convert {
2. public static void main(String[] args) {
3. Long xL = new Long(456L);
4. long x1 = Long.valueOf("123");
5. Long x2 = Long.valueOf("123");
6. long x3 = xL.longValue();
7. Long x4 = xL.longValue();
8. Long x5 = Long.parseLong("456");
9. long x6 = Long.parseLong("123");
10. }
11. }
Which will compile using Java 5, but will NOT compile using Java 1.4? (Choose all that apply.)
a. Line 8
b. Line 4
c. Line 6
d. Line 9
e. Line 7
f. Line 5
Answer: B, E, A
Question 5
Given:
.import java.util.regex.*;
.class Regex2 {
. public static void main(String[] args) {
. Pattern p = Pattern.compile(args[0]);
. Matcher m = p.matcher(args[1]);
. boolean b = false;
. while(b = m.find()) {
. System.out.print(m.start() + m.group());
. }
. }
.}
And the command line:
java Regex2 "\d*" ab34ef
What is the result?
a. 12334567
b. 0123456
c. Compilation fails.
d. 01234456
e. 234
f. 2334
g. 334
Answer: D
Question 6
Given:
.class TKO {
. public static void main(String[] args) {
. String s = "-";
. Integer x = 343;
. long L343 = 343L;
. if(x.equals(L343)) s += ".e1 ";
. if(x.equals(343)) s += ".e2 ";
. Short s1 = (short)((new Short((short)343)) / (new Short((short)49)));
. if(s1 == 7) s += "=s ";
. if(s1 < new Integer(7+1)) s += "fly ";
. System.out.println(s);
. }
.}
Which of the following will be included in the output String s? (Choose all that apply.)
a. None of the above.
b. .e1
c. .e2
d. An exception is thrown at runtime.
e. fly
f. =s
g. Compilation fails.
Answer: C, E, F
Question 7
Given:
1. import java.text.*;
2. class DateOne {
3. public static void main(String[] args) {
4. Date d = new Date(1123631685981L);
5. DateFormat df = new DateFormat();
6. System.out.println(df.format(d));
7. }
8. }
And given that 1123631685981L is the number of milliseconds between Jan. 1, 1970, and sometime on Aug. 9, 2005, what is the result? (Note: the time of day in option A may vary.)
a. 8/9/05 5:54 PM
b. An exception is thrown at runtime.
c. 1123631685981L
d. Compilation fails due to a single error in the code.
e. Compilation fails due to multiple errors in the code.
Answer: E
Question 8
Which are true? (Choose all that apply.)
a. The DateFormat.getDate() is used to convert a String to a Date instance.
b. A single instance of NumberFormat can be used to create Number objects from Strings and to create formatted numbers from numbers.
c. Both Currency and NumberFormat objects must be constructed using static methods.
d. If a NumberFormat instance's Locale is to be different than the current Locale, it must be specified at creation time.
e. Both DateFormat and NumberFormat objects can be constructed to be Locale specific.
Answer: B, C, D, E
Question 9
Which will compile and run without exception? (Choose all that apply.)
a. System.out.printf("%d", 123.45);
b. System.out.printf("%d", 123);
c. System.out.format("%b", 123);
d. System.out.printf("%f", 123.45);
e. System.out.format("%s", new Long("123"));
f. System.out.printf("%f", 123);
g. System.out.format("%c", "x");
Answer: C, B, D, E
Question 10
Which about the three java.lang classes String, StringBuilder, and StringBuffer are true? (Choose all that apply.)
a. According to the API, StringBuffer will be faster than StringBuilder under most implementations.
b. The value of an instance of any of these three types can be modified through various methods in the API.
c. Objects of type StringBuffer are thread-safe.
d. All three classes have overloaded append() methods.
e. The "+" is an overloaded operator for all three classes.
f. All three classes have a length() method.
Answer: C, F
14 dic 2012
[Cerrado] Sorteo de Nexus 7 comprando en amazon.es durante estas Navidades
Si hacéis una compra dejadme un comentario, cuantos números os tocaría, yo lo compruebo y os asigno un número para el sorteo, así de fácil. Cuando la fecha llegue y tengamos un cierto número de participantes, está claro que si hay pocos replantearé el sorteo de otro modo. Si la convocatoria funciona no descarto mejorar el sorteo, y sobre todo repetirlo con otros gadgets.
Final: Se ha acabado la campaña navideña y viendo la poca repercusión y ya que sólo hemos tenido un participante que me envió un correo, doy por cancelado el sorteo, a David le haré un traspaso de la comisión que reciba de amazon a través de paypal. Si alguien más participó aun puede avisarme y le haré el mismo trato.
Para los que lleguéis tarde si os interesa podéis obtener descuentos para vuestras compras en amazon.es y participar en promociones en nuestrá página amiga #WhereToBuy
7 dic 2012
Preparación para Certificación SCJP 1Z0-851. Tema 3
Continuando con esta "saga" de posts sobre la preparación para realizar el examen de certificación de java SCJP 1Z0-851.
Question 1
Given:
1. class Scoop {
2. static int thrower() throws Exception { return 42; }
3. public static void main(String [] args) {
4. try {
5. int x = thrower();
6. } catch (Exception e) {
7. x++;
8. } finally {
9. System.out.println("x = " + ++x);
10. } } }
What is the result?
a. x = 42
b. x = 43
c. x = 44
d. Compilation fails.
e. The code runs with no output.
Answer: D
Question 2
Which are true? (Choose all that apply.)
a. It is appropriate to use assertions to validate arguments to methods marked public.
b. It is appropriate to catch and handle assertion errors.
c. It is NOT appropriate to use assertions to validate command-line arguments.
d. It is appropriate to use assertions to generate alerts when you reach code that should not be reachable.
e. It is NOT appropriate for assertions to change a program
Answer: C, D and E
Question 3
Given:
1. class Emu {
2. static String s = "-";
3. public static void main(String[] args) {
4. try {
5. throw new Exception();
6. } catch (Exception e) {
7. try {
8. try { throw new Exception();
9. } catch (Exception ex) { s += "ic "; }
10. throw new Exception(); }
11. catch (Exception x) { s += "mc "; }
12. finally { s += "mf "; }
13. } finally { s += "of "; }
14. System.out.println(s);
15. } }
What is the result?
Seleccione una respuesta.
a. -ic of
b. -mf of
c. -mc mf
d. -ic mf of
e. -ic mc mf of
f. -ic mc of mf
g. Compilation fails.
Answer: E
Question 4
Given:
1. class Mineral { }
2. class Gem extends Mineral { }
3. class Miner {
4. static int x = 7;
5. static String s = null;
6. public static void getWeight(Mineral m) {
7. int y = 0 / x;
8. System.out.print(s + " ");
9. }
10. public static void main(String[] args) {
11. Mineral[] ma = {new Mineral(), new Gem()};
12. for(Object o : ma)
13. getWeight((Mineral) o);
14. }
15. }
And the command-line invocation:
java Miner.java
What is the result?
Seleccione una respuesta.
a. null
b. null null
c. A ClassCastException is thrown.
d. A NullPointerException is thrown.
e. A NoClassDefFoundError is thrown.
f. An ArithmeticException is thrown.
g. An IllegalArgumentException is thrown.
h. An ArrayIndexOutOfBoundsException is thrown.
Answer: E
Question 5
Which are most typically thrown by an API developer or an application developer as opposed to being thrown by the JVM? (Choose all that apply.)
a. ClassCastException
b. IllegalStateException
c. NumberFormatException
d. IllegalArgumentException
e. ExceptionInInitializerError
Answer: B, C and D
6
Given two files:
1. class One {
2. public static void main(String[] args) {
3. int assert = 0;
4. }
5. }
1. class Two {
2. public static void main(String[] args) {
3. assert(false);
4. }
5. }
And the four command-line invocations:
javac -source 1.3 One.java
javac -source 1.4 One.java
javac -source 1.3 Two.java
javac -source 1.4 Two.java
What is the result? (Choose all that apply.)
a. Only one compilation will succeed.
b. Exactly two compilations will succeed.
c. Exactly three compilations will succeed.
d. All four compilations will succeed.
e. No compiler warnings will be produced.
f. At least one compiler warning will be produced.
Answer: B and F
Question 7
Given:
1. import java.io.*;
2. class Master {
3. String doFileStuff() throws FileNotFoundException { return "a"; }
4. }
5. class Slave extends Master {
6. public static void main(String[] args) {
7. String s = null;
8. try { s = new Slave().doFileStuff();
9. } catch ( Exception x) {
10. s = "b"; }
11. System.out.println(s);
12. }
13. // insert code here
14. }
Which, inserted independently at
// insert code here
, will compile, and produce the output b? (Choose all that apply.)
a. String doFileStuff() { return "b"; }
b. String doFileStuff() throws IOException { return "b"; }
c. String doFileStuff(int x) throws IOException { return "b"; }
d. String doFileStuff() throws FileNotFoundException { return "b"; }
e. String doFileStuff() throws NumberFormatException { return "b"; }
f. String doFileStuff() throws NumberFormatException, FileNotFoundException { return "b"; }
Answer: A, D, E, F
Question 8
Given:
1. class Input {
2. public static void main(String[] args) {
3. String s = "-";
4. try {
5. doMath(args[0]);
6. s += "t "; // line 6
7. }
8. finally { System.out.println(s += "f "); }
9. }
10. public static void doMath(String a) {
11. int y = 7 / Integer.parseInt(a);
12. }
13. }
And the command-line invocations:
java Input
java Input 0
Which are true? (Choose all that apply.)
a. Line 6 is executed exactly 0 times.
b. Line 6 is executed exactly 1 time.
c. Line 6 is executed exactly 2 times.
d. The finally block is executed exactly 0 times.
e. The finally block is executed exactly 1 time.
f. The finally block is executed exactly 2 times.
g. Both invocations produce the same exceptions.
h. Each invocation produces a different exception.
Answer: A, F and H
Question 9
Given:
1. class Plane {
2. static String s = "-";
3. public static void main(String[] args) {
4. new Plane().s1();
5. System.out.println(s);
6. }
7. void s1() {
8. try { s2(); }
9. catch (Exception e) { s += "c"; }
10. }
11. void s2() throws Exception {
12. s3(); s += "2";
13. s3(); s += "2b";
14. }
15. void s3() throws Exception {
16. throw new Exception();
17. } }
What is the result?
a. -
b. -c
c. -c2
d. -2c
e. -c22b
f. -2c2b
g. -2c2bc
h. Compilation fails.
Answer: B
Question 10
Given:
try { int x = Integer.parseInt("two"); }
Which could be used to create an appropriate catch block? (Choose all that apply.)
a. ClassCastException
b. IllegalStateException
c. NumberFormatException
d. IllegalArgumentException
e. ExceptionInInitializerError
f. ArrayIndexOutOfBoundsException
Answer: C and D
11
Given:
1. class Ping extends Utils {
2. public static void main(String [] args) {
3. Utils u = new Ping();
4. System.out.print(u.getInt(args[0]));
5. }
6. int getInt(String arg) {
7. return Integer.parseInt(arg);
8. }
9. }
10. class Utils {
11. int getInt(String x) throws Exception { return 7; }
12. }
And the following three possible changes:
C1. Declare that main() throws an Exception.
C2. Declare that Ping.getInt() throws an Exception.
C3. Wrap the invocation of getInt() in a try / catch block.
Which change(s) allow the code to compile? (Choose all that apply.)
Seleccione al menos una respuesta.
a. Just C1 is sufficient.
b. Just C2 is sufficient.
c. Just C3 is sufficient.
d. Both C1 and C2 are required.
e. Both C1 and C3 are required.
f. Both C2 and C3 are required.
g. All three changes are required.
Answer: A and C
Question 12
Given:
1. class Swill {
2. public static void main(String[] args) {
3. String s = "-";
4. switch(TimeZone.CST) {
5. case EST: s += "e";
6. case CST: s += "c";
7. case MST: s += "m";
8. default: s += "X";
9. case PST: s += "p";
10. }
11. System.out.println(s);
12. }
13. }
14. enum TimeZone {EST, CST, MST, PST }
What is the result?
Seleccione una respuesta.
a. -c
b. -X
c. -cm
d. -cmp
e. -cmXp
f. Compilation fails.
g. An exception is thrown at runtime.
Answer: E
20 nov 2012
Preparación para Certificación SCJP 1Z0-851. Tema 2
Question 1
Which statement(s) are true? (Choose all that apply.)
a. Has-a relationships always rely on inheritance.
b. Has-a relationships always rely on instance variables.
c. Has-a relationships always require at least two class types.
d. Has-a relationships always rely on polymorphism.
e. Has-a relationships are always tightly coupled.
Answer: B
Question 2
Given the following,
1. interface Base {
2. boolean m1 ();
3. byte m2(short s);
4. }
Which code fragments will compile? (Choose all that apply.)
a.
interface Base2 implements Base { }
b.
abstract class Class2 extends Base {
public boolean m1() { return true; } }
c.
abstract class Class2 implements Base { }
d.
abstract class Class2 implements Base {
public boolean m1() { return (true); } }
e.
class Class2 implements Base {
boolean m1() { return false; }
byte m2(short s) { return 42; } }
Answer: C and D
Question 3
Which declare a compilable abstract class? (Choose all that apply.)
a. public abstract class Canine { public Bark speak(); }
b. public abstract class Canine { public Bark speak() { return null; } }
c. public class Canine { public abstract Bark speak(); }
d. public class Canine abstract { public abstract Bark speak(); }
Answer: B
Question 4
Which is true? (Choose all that apply.)
a. "X extends Y" is correct if and only if X is a class and Y is an interface.
b. "X extends Y" is correct if and only if X is an interface and Y is a class.
c. "X extends Y" is correct if X and Y are either both classes or both interfaces.
d. "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.
Answer: C
Question 5
Which method names follow the JavaBeans standard? (Choose all that apply.)
a. addSize
b. getCust
c. deleteRep
d. isColorado
e. putDimensions
Answer: B and D
Question 6
Given:
1. enum Animals {
2. DOG("woof"), CAT("meow"), FISH("burble");
3. String sound;
4. Animals(String s) { sound = s; }
5. }
6. class TestEnum {
7. static Animals a;
8. public static void main(String [] args) {
9. System.out.println(a.DOG.sound + " " + a.FISH.sound);
10. }
11. }
What is the result?
a. woof burble
b. Multiple compilation errors
c. Compilation fails due to an error on line 2
d. Compilation fails due to an error on line 3
e. Compilation fails due to an error on line 4
f. Compilation fails due to an error on line 9
Answer: A
Question 7
Given:
1. enum A { A }
2. class E2 {
3. enum B { B }
4. void C() {
5. enum D { D }
6. }
7. }
Which statements are true? (Choose all that apply.)
a. The code compiles.
b. If only line 1 is removed the code compiles.
c. If only line 3 is removed the code compiles.
d. If only line 5 is removed the code compiles.
e. If lines 1 and 3 are removed the code compiles.
f. If lines 1, 3 and 5 are removed the code compiles.
Answer: D and F
Question 8
Given:
1. class Programmer {
2. Programmer debug() { return this; }
3. }
4. class SCJP extends Programmer {
5. // insert code here
6. }
Which, inserted at line 5, will compile? (Choose all that apply.)
a. Programmer debug() { return this; }
b. SCJP debug() { return this; }
c. Object debug() { return this; }
d. int debug() { return 1; }
e. int debug(int x) { return 1; }
f. Object debug(int x) { return this; }
Answer: A, B, E and F
Question 9
Given:
1. class Uber {
2. static int y = 2;
3. Uber(int x) { this(); y = y * 2; }
4. Uber() { y++; }
5. }
6. class Minor extends Uber {
7. Minor() { super( y ); y = y + 3; }
8. public static void main(String [] args) {
9. new Minor();
10. System.out.println( y );
11. } }
What is the result?
Seleccione una respuesta.
a. 6
b. 7
c. 8
d. 9
e. Compilation fails.
f. An exception is thrown.
Answer: D
Question 10
Which statement(s) are true? (Choose all that apply.)
a. Cohesion is the OO principle most closely associated with hiding implementation details.
b. Cohesion is the OO principle most closely associated with making sure that classes know about other classes only through their APIs.
c. Cohesion is the OO principle most closely associated with making sure that a class is designed with a single, well-focused purpose.
d. Cohesion is the OO principle most closely associated with allowing a single object to be seen as having many types.
Answer: C
Question 11
Given:
1. class Dog { }
2. class Beagle extends Dog { }
3.
4. class Kennel {
5. public static void main(String [] arfs) {
6. Beagle b1 = new Beagle();
7. Dog dog1 = new Dog();
8. Dog dog2 = b1;
9. // insert code here
10. }
11.}
Which, inserted at line 9, will compile? (Choose all that apply.)
a. Beagle b2 = (Beagle) dog1;
b. Beagle b3 = (Beagle) dog2;
c. Beagle b4 = dog2;
d. None of the above statements will compile
Answer: A and B
Question 12
Given the following,
1. class X { void do1() { } }
2. class Y extends X { void do2() { } }
3. 4. class Chrome {
5. public static void main(String [] args) {
6. X x1 = new X();
7. X x2 = new Y();
8. Y y1 = new Y();
9. // insert code here
10. } }
Which, inserted at line 9, will compile? (Choose all that apply.)
a. x2.do2();
b. (Y)x2.do2();
c. ((Y)x2).do2();
d. None of the above statements will compile.
Answer: C
Question 13
Given:
1. class Clidders {
2. public final void flipper() { System.out.println("Clidder"); }
3. }
4. public class Clidlets extends Clidders {
5. public void flipper() {
6. System.out.println("Flip a Clidlet");
7. super.flipper();
8. }
9. public static void main(String [] args) {
10. new Clidlets().flipper();
11. }
12.}
What is the result?
a. Flip a Clidlet
b. Flip a Clidder
c. Flip a Clidder
d. Flip a Clidlet
e. Flip a Clidlet
f. Flip a Clidder
g. Compilation fails.
Answer: G
Question 14
Given:
public abstract interface Frobnicate { public void twiddle(String s); }
Which is a correct class? (Choose all that apply.)
a.
public abstract class Frob implements Frobnicate {
public abstract void twiddle(String s) { }
}
b.
public abstract class Frob implements Frobnicate { }
c.
public class Frob extends Frobnicate {
public void twiddle(Integer i) { }
}
d.
public class Frob implements Frobnicate {
public void twiddle(Integer i) { }
}
e.
public class Frob implements Frobnicate {
public void twiddle(String i) { }
public void twiddle(Integer s) { }
}
Answer: B and E
Question 15
Given:
1. class Top {
2. public Top(String s) { System.out.print("B"); }
3. }
4. public class Bottom2 extends Top {
5. public Bottom2(String s) { System.out.print("D"); }
6. public static void main(String [] args) {
7. new Bottom2("C");
8. System.out.println(" ");
9. } }
What is the result?
Seleccione una respuesta.
a. BD
b. DB
c. BDC
d. DBC
e. Compilation fails.
Answer: E
Question 16
Select the two statements that best indicate a situation with low coupling. (Choose two.)
a. The attributes of the class are all private.
b. The class refers to a small number of other objects.
c. The object contains only a small number of variables.
d. The object is referred to using an anonymous variable, not directly.
e. The reference variable is declared for an interface type, not a class. The interface provides a small number of methods.
f. It is unlikely that changes made to one class will require any changes in another.
Answer: E and F
Question 17
Given:
1. class Clidder {
2. private final void flipper() { System.out.println("Clidder"); }
3. }
4. public class Clidlet extends Clidder {
5. public final void flipper() { System.out.println("Clidlet"); }
6. public static void main(String [] args) {
7. new Clidlet().flipper();
8. } }
What is the result?
Seleccione una respuesta.
a. Clidlet
b. Clidder
c. Clidder
Clidlet
d. Clidlet
Clidder
e. Compilation fails.
Answer: A
Question 18
Given:
1. class Plant {
2. String getName() { return "plant"; }
3. Plant getType() { return this; }
4. }
5. class Flower extends Plant {
6. // insert code here
7. }
8. class Tulip extends Flower { }
Which statement(s), inserted at line 6, will compile? (Choose all that apply.)
a. Flower getType() { return this; }
b. String getType() { return "this"; }
c. Plant getType() { return this; }
d. Tulip getType() { return new Tulip(); }
Answer: A, C and D
Question 19
Given:
public class MyOuter {
public static class MyInner { public static void foo() { } }
}
Which, if placed in a class other than MyOuter or MyInner, instantiates an instance of the
nested class?
a.
MyOuter.MyInner m = new MyOuter.MyInner();
b.
MyOuter.MyInner mi = new MyInner();
c.
MyOuter m = new MyOuter();
MyOuter.MyInner mi = m.new MyOuter.MyInner();
d.
MyInner mi = new MyOuter.MyInner();
Answer: A
Question 20
Given:
1. public class HorseTest {
2. public static void main(String[] args) {
3. class Horse {
4. public String name;
5. public Horse(String s) {
6. name = s;
7. }
8. }
9. Object obj = new Horse("Zippo");
10. Horse h = (Horse) obj;
11. System.out.println(h.name);
12. }
13. }
What is the result?
Seleccione una respuesta.
a. An exception occurs at runtime at line 10.
b. Zippo
c. Compilation fails because of an error on line 3.
d. Compilation fails because of an error on line 9.
e. Compilation fails because of an error on line 10.
f. Compilation fails because of an error on line 11.
Answer: B
Question 21
Given:
1. public class HorseTest {
2. public static void main(String[] args) {
3. class Horse {
4. public String name;
5. public Horse(String s) {
6. name = s;
7. }
8. }
9. Object obj = new Horse("Zippo");
10. System.out.println(obj.name);
11. }
12. }
What is the result?
Seleccione una respuesta.
a. An exception occurs at runtime at line 10.
b. Zippo
c. Compilation fails because of an error on line 3.
d. Compilation fails because of an error on line 9.
e. Compilation fails because of an error on line 10.
Answer: E
Question 22
Given:
1. public abstract class AbstractTest {
2. public int getNum() {
3. return 45;
4. }
5. public abstract class Bar {
6. public int getNum() {
7. return 38;
8. }
9. }
10. public static void main(String[] args) {
11. AbstractTest t = new AbstractTest() {
12. public int getNum() {
13. return 22;
14. }
15. };
16. AbstractTest.Bar f = t.new Bar() {
17. public int getNum() {
18. return 57;
19. }
20. };
21. System.out.println(f.getNum() + " " + t.getNum());
22. } }
What is the result?
Seleccione una respuesta.
a. 57 22
b. 45 38
c. 45 57
d. An exception occurs at runtime.
e. Compilation fails.
Answer: A
Question 23
Which are true about a static nested class? (Choose all that apply.)
Seleccione al menos una respuesta.
a. You must have a reference to an instance of the enclosing class in order to instantiate it.
b. It does not have access to non-static members of the enclosing class.
c. Its variables and methods must be static.
d. If the outer class is named MyOuter, and the nested class is named MyInner, it can be instantiated using new MyOuter.MyInner();.
e. It must extend the enclosing class.
Answer: B and D
Question 24
Given:
public interface Runnable { void run(); }
Which construct an anonymous inner class instance? (Choose all that apply.)
a.
Runnable r = new Runnable() { };
b.
Runnable r = new Runnable(public void run() { });
c.
Runnable r = new Runnable { public void run(){ } };
d.
Runnable r = new Runnable() {public void run{ } };
e.
System.out.println(new Runnable() {public void run() { } });
f.
System.out.println(new Runnable(public void run() { } ));
Answer: E
Question 25
Given:
1. class Boo {
2. Boo(String s) { }
3. Boo() { }
4. }
5. class Bar extends Boo {
6. Bar() { }
7. Bar(String s) {super(s);}
8. void zoo() {
9. // insert code here
10. }
11. }
Which create an anonymous inner class from within class Bar? (Choose all that apply.)
Seleccione al menos una respuesta.
a. Boo f = new Boo(24) { };
b. Boo f = new Bar() { };
c. Boo f = new Boo() {String s; };
d. Bar f = new Boo(String s) { };
e. Boo f = new Boo.Bar(String s) { };
Answer: B and C
Question 26
Given:
1. class Foo {
2. class Bar{ }
3. }
4. class Test {
5. public static void main(String[] args) {
6. Foo f = new Foo();
7. // Insert code here
8. }
9. }
Which, inserted at line 7, creates an instance of Bar? (Choose all that apply.)
a. Foo.Bar b = new Foo.Bar();
b. Foo.Bar b = f.new Bar();
c. Bar b = new f.Bar();
d. Bar b = f.new Bar();
e. Foo.Bar b = new f.Bar();
Answer: B
Question 27
Which are true about a method-local inner class? (Choose all that apply.)
a. It must be marked final.
b. It can be marked abstract.
c. It can be marked public.
d. It can be marked static.
e. It can access private members of the enclosing class.
Answer: B and E
Question 28
Which are true about an anonymous inner class? (Choose all that apply.)
a. It can extend exactly one class and implement exactly one interface.
b. It can extend exactly one class and can implement multiple interfaces.
c. It can extend exactly one class or implement exactly one interface.
d. It can implement multiple interfaces regardless of whether it also extends a class.
e. It can implement multiple interfaces if it does not extend a class.
Answer: C
Question 29
Given:
1. public class Foo {
2. Foo() {System.out.print("foo");}
3. class Bar{
4. Bar() {System.out.print("bar");}
5. public void go() {System.out.print("hi");}
6. }
7. public static void main(String[] args) {
8. Foo f = new Foo();
9. f.makeBar();
10. }
11. void makeBar() {
12. (new Bar() {}).go();
13. }
14. }
What is the result?
Seleccione una respuesta.
a. Compilation fails.
b. An error occurs at runtime.
c. foobarhi
d. barhi
e. hi
f. foohi
Answer: C
Question 30
Given:
1. public class TestObj {
2. public static void main(String[] args) {
3. Object o = new Object() {
4. public boolean equals(Object obj) {
5. return true;
6. }
7. }
8. System.out.println(o.equals("Fred"));
9. }
10. }
What is the result?
a. An exception occurs at runtime.
b. true
c. fred
d. Compilation fails because of an error on line 3.
e. Compilation fails because of an error on line 4.
f. Compilation fails because of an error on line 8.
g. Compilation fails because of an error on a line other than 3, 4, or 8.
Answer: G
Question 31
Given:
1. class Zing {
2. protected Hmpf h;
3. }
4. class Woop extends Zing { }
5. class Hmpf { }
Which is true? (Choose all that apply.)
a. Woop is-a Hmpf and has-a Zing.
b. Zing is-a Woop and has-a Hmpf.
c. Hmpf has-a Woop and Woop is-a Zing.
d. Woop has-a Hmpf and Woop is-a Zing.
e. Zing has-a Hmpf and Zing is-a Woop.
Answer: D
9 oct 2012
Preparación para Certificación SCJP 1Z0-851. Tema 1
Hace unos días que he empezado un cursillo para sacar una certificación de java 6, el antiguo CX-310-065, que ahora que Oracle ha decidido cambiar el código para estandarizar con sus formaciones pasa a ser el 1Z0-851.
Quiero compartir algo de material que voy a usar para la preparación del test, os dejo el test que he realizado sobre el tema 1, si buscáis estas mismas preguntas las podéis encontrar en otras webs.
1. Which is true? (Choose all that apply.)
A. The invocation of an object's finalize () method is always the last thing that happens before an object is garbage collected (GCed).
B. When a stack variable goes out of scope it is eligible for GC.
C. Some reference variables live on the stack, and some live on the heap.
D. Only objects that have no reference variables referring to them can be eligible for GC.
E. It 's possible to request the GC via methods in either java. Lang. Runtime or java.lang.System classes.
Answer:
C and E are correct. When an object has a reference variable, the reference variable lives inside the object, on the heap.
A is incorrect, because The order is different: First the object is collected. Then the object is finalized. B is incorrect-stack variables are not dealt with by the GC. D is incorrect because objects can live in "islands of isolation" and be GC eligible.
2. Which are valid declarations? (Choose all that apply.)
A. int $x;
B. int 123;
C. int _123;
D. int #dim;
E. int %percent;
F. int *divide;
G. int central_sales_region_Summer_2005_gross_sales;
Answer:
A, C, and G are legal identifiers.
B is incorrect because an identifier can't start with a digit. D, E, and F are incorrect because identifiers must start with $, _, or a letter.
3. Given:
1. class Maybe {
2. public static void main(String[] args) {
3. boolean b1 = true;
4. boolean b2 = false;
5. System.out.print(!false ^ false);
6. System.out.print(" " + (!b1 & (b2 = true)));
7. System.out.println(" " + (b2 ^ b1));
8. }
9. }
Which are true?
Seleccione al menos una respuesta.
a. Line 5 produces true.
b. Line 5 produces false.
c. Line 6 produces false.
d. Line 7 produces true.
e. Line 7 produces false.
f. Line 6 produces true.
Answer:
The exit is true false false. So A, C, E are true
4. class Fizz {
int x = 5;
public static void main(String args[]) {
final Fizz f1 = new Fizz();
Fizz f2 = new Fizz();
Fizz f3 = FizzSwitch(f1, f2);
System.out.println((f1 == f3) + " " + (f1.x == f3.x));
}
static Fizz FizzSwitch(Fizz x, Fizz y) {
final Fizz z = x;
z.x = 6;
return z;
}
}
Answer:
The outcome for the above code is
'true true'
The reason given in the book is:
"The references f1, z and f3 all refer to the same instance of Fizz. The final modifier assures that a reference variable cannot be referred to a different object but final doesnt keep the objects state from changing."
5. Given the following code:
public class OrtegorumFunction { public int computeDiscontinuous(int x) { int r = 1; r += X; if ((x > 4) && (x < 10)) { r += 2 * x; } else (x <= 4) { r += 3 * x; } else { r += 4 * x; } r += 5 * x; return r; } public static void main(String [] args) { OrtegorumFunction o = new OrtegorumFunction(); System.out.println("OF(11) is: " + o.computeDiscontinuous (11)); } }
What is the result?
a. OF(11) is: 45
b. OF(11) is: 56
c. OF(11) is: 89
d. OF(11) is: 111
e. Compilation fails.
f. An exception is thrown at runtime.
Answer:
E is correct. The if statement is illegal. The if-else-else must be changed to if-else if-else , which would result in OF (11) is: 111 .
6. Given:
.class Foozit {
. public static void main(String[] args) {
. Integer x = 0;
. Integer y = 0;
. for(Short z = 0; z < 5; z++)
. if((++x > 2) || (++y > 2))
. x++;
. System.out.println(x + " " + y);
. }
.}
What is the result?
Seleccione una respuesta.
a. 8 3
b. 8 1
c. 10 3
d. 8 2
e. 5 3
f. 10 2
g. 5 1
h. 5 2
Answer:
The good is D, we have to see that the second expression of the if only evaluates when the first is false.
7. class Titanic {
. public static void main(String[] args) {
. Boolean b1 = true;
. boolean b2 = false;
. boolean b3 = true;
. if((b1 & b2) | (b2 & b3) & b3)
. System.out.print("alpha ");
. if((b1 = false) | (b1 & b3) | (b1 | b2))
. System.out.print("beta ");
. }
.}
What is the result?
Seleccione una respuesta.
a. An exception is thrown at runtime.
b. No output is produced.
c. Compilation fails.
d. alpha beta
e. alpha
f. beta
Answer: B
8. Given:
1. class Comp2 {
2. public static void main(String[] args) {
3. float f1 = 2.3f;
4. float[][] f2 = {{42.0f}, {1.7f, 2.3f}, {2.6f, 2.7f}};
5. float[] f3 = {2.7f};
6. Long x = 42L;
7. // insert code here
8. System.out.println("true");
9. }
10. }
And the following five code fragments:
F1. if(f1 == f2)
F2. if(f1 == f2[2][1])
F3. if(x == f2[0][0])
F4. if(f1 == f2[1,1])
F5. if(f3 == f2[2])
What is true?
Seleccione una respuesta.
a. Three of them will compile, exactly three will be true.
b. Three of them will compile, only one will be true.
c. Three of them will compile, exactly two will be true.
d. Two of them will compile, two will be true.
e. Two of them will compile, only one will be true.
f. One of them will compile, only one will be true.
Answer: B
9. Given:
.class Sixties {
. public static void main(String[] args) {
. int x = 5; int y = 7;
. System.out.print(((y * 2) % x));
. System.out.print(" " + (y % x));
. }
.}
What is the result?
Seleccione una respuesta.
a. 2 1
b. 1 1
c. Compilation fails.
d. An exception is thrown at runtime.
e. 4 1
f. 1 2
g. 2 2
h. 4 2
Answer: H
10. Given:
.class Mixer {
. Mixer() { }
. Mixer(Mixer m) { m1 = m; }
. Mixer m1;
. public static void main(String[] args) {
. Mixer m2 = new Mixer();
. Mixer m3 = new Mixer(m2); m3.go();
. Mixer m4 = m3.m1; m4.go();
. Mixer m5 = m2.m1; m5.go();
. }
. void go() { System.out.print("hi "); }
.}
What is the result?
Seleccione una respuesta.
a. Compilation fails
b. hi
c. hi hi
d. hi hi hi
e. hi hi, followed by an exception
f. hi, followed by an exception
Answer: E
11. Given:
1. class Eco {
2. public static void main(String[] args) {
3. Eco e1 = new Eco();
4. Eco e2 = new Eco();
5. Eco e3 = new Eco();
6. e3.e = e2;
7. e1.e = e3;
8. e2 = null;
9. e3 = null;
10. e2.e = e1;
11. e1 = null;
12. }
13. Eco e;
14. }
At what point is only a single object eligible for GC?
Seleccione una respuesta.
a. After line 11 runs.
b. After line 10 runs.
c. After line 9 runs.
d. An exception is thrown at runtime.
e. After line 8 runs.
f. Compilation fails.
g. Never in this program.
Answer: D
12.
Given:
1. class Crivitch {
2. public static void main(String [] args) {
3. int x = 0;
4. // insert code here
5. do { } while (x++ < y);
6. System.out.println(x);
7. }
8. }
Which, inserted at line 4, produces the output 12?
Seleccione una respuesta.
a. int y = 12;
b. int y = x;
c. int y = 13;
d. int y = 10;
e. int y = 11;
f. None of the above will allow compilation to succeed.
Answer: E
13. Given:
.class Knowing {
. static final long tooth = 343L;
. static long doIt(long tooth) {
. System.out.print(++tooth + " ");
. return ++tooth;
. }
. public static void main(String[] args) {
. System.out.print(tooth + " ");
. final long tooth = 340L;
. new Knowing().doIt(tooth);
. System.out.println(tooth);
. }
.}
What is the result?
Seleccione una respuesta.
a. 343 340 340
b. 343 341 340
c. 343 341 343
d. Compilation fails.
e. 343 340 342
f. An exception is thrown at runtime.
g. 343 341 342
Answer: B
14. Given:
.class Feline {
. public static void main(String[] args) {
. Long x = 42L;
. Long y = 44L;
. System.out.print(" " + 7 + 2 + " ");
. System.out.print(foo() + x + 5 + " ");
. System.out.println(x + y + foo());
. }
. static String foo() { return "foo"; }
.}
What is the result?
Seleccione una respuesta.
a. 72 foo47 4244foo
b. 9 foo425 86foo
c. 9 foo47 86foo
d. 72 foo425 86foo
e. 72 foo47 86foo
f. Compilation fails.
g. 72 foo425 4244foo
h. 9 foo425 4244foo
i. 9 foo47 4244foo
Answer: D
15. Which are legal declarations? (Choose all that apply.)
Seleccione al menos una respuesta.
a. short [] y2 = [5];
b. short[5] x2;
c. short [] z [] [];
d. short z2 [5];
e. short [] y;
f. short x [];
Answer: C, E, F