mock-4 verified
mock-4 verified
@JsonField(type=JsonField.Type.STRING, name="name")
private String _name;
@JsonField(type=JsonField.Type.INT)
private int x;
@JsonField(type=JsonField.Type.INT)
private int y;
}
What is the correct definition of the JsonField annotation that makes the Point class c
ompile?
A)
@Target (ElementType.FIELD)
@interface JsonField {
String name() default "";
enum Type {
INT, STRING, BOOLEAN
};
Type type();
B)
@interface JsonField {
String name ();
enum Type {
INT, STRING, BOOLEAN
};
Type type();
}
C)
@Retention(RetentionPolicy.RUNTIME)
@Target (ElementType.METHOD)
@interface JsonField {
String name() default "";
enum Type {
INT, STRING, BOOLEAN
};
Type type();
Option
A
Option
B
Option
C
Which module is required for any application using Swing or AWT?
java.prefs
java.deskto
p
Java.se
java.rmi
Java.loggin
g
Given:
public class Test {
class L extends Exception { }
class M extends L { }
class N extends RuntimeException { }
public void p() throws L { throw new M(); }
public void q() throws N { throw new N(); }
public static void main(String{] args) {
try {
Test t = new Test();
t.p();
t.q():
} /*line 1*/ {
System.out.println("Exception caught");
}
}
}
Add catch (N | L | M e
).
Add catch (L |N e).
Add catch (L |M N e).
Add catch (L e).
Add catch (M |L e).
Given:
Which two can be considered good practices for serializing Java objects? (Choose two
.)
?Given :
class Separators {
public static String separator = "/";
public static String pathSeparator = ":";
}
To secure this code ,you want to make sure that the client code cannot modify the fi
elds .
enum Separators {
separator,
pathSeparator
}
class Separators {
private static String separator ="/";
private static String pathSeparator
= ":";
}
abstract class Separators {
public static String separator = "/";
public static String pathSeparator =
":";
}
class Separators {
private static String separator ="/";
private static String pathSeparator
= ":";
}
interface Separators {
String separator = "/";
String pathSeparator = ":",
}
Given :
int i = 10;
do {
for (int j = i / 2; j > 0; j--) {
System.out.print(j + " ");
}
i -= 2;
} while (i > 0);
5432143213212
11
54321
5
Nothing
Given:
public class DNASynth {
int aCount;
int tCount;
int cCount;
int gCount;
Which two methods facilitate valid ways to read instance fields? (Choose two.)
getGCount
getACount
getTCount
getTotalCou
nt
getCCount
Given:
public interface TestInterface {
default void samplingProbeProcedure () {
probeProcedure () ;
System.out.println ("Collect Sample");
System.out.println ("Leave Asteroid");
System.out.println ("Dock with Main Craft");
}
default void explosionProbeProcedure () {
probeProcedure () ;
System.out.println ("Explode");
}
}
Option A
Option
D
Option C
Option B
A, because it sends exactly the value of user provided by the calling cod
e
B, because enquoting values provided by the calling code prevents SQL i
njection.
B, because all values provided by the calling code should be enquoted.
A, because it is unnecessary to enclose identifiers in quotes.
A and B are functionally equivalent.
Given :
The Sportscar class is a superclass that has more functionality than the Automo
bile class.
The Sportscar class is a subclass of Automobile and inherits its methods.
The Sportscar subclass cannot override setTurbo method from the superclass A
utomobile.
The Sportscar class inherits the setTurbo method from the superclass Automobil
e.
Given:
char[] characters = new char[100];
try (FileReader reader = new FileReader("path to file")) {
// line 1
System.out.println(String.valueOf(characters));
} catch(IOException e) {
e.printStackTrace();
}
You want to read data through the reader object.
Which statement inserted on line 1 will accomplish this?
System.in.read(character
s);
reader.readline();
reader.read(characters);
characters.read(0,29);
Your organization provides a cloud server to your customer to run their Java trini
changes for the next release and you see this change in one of the config files:
old: JAVA_OPTS-"SJAVA_OPTS -Xms8g -Xmx8g"
new: JAVA OPTS-"SJAVA OPTS -Xms8g -Xix8g -noverify"
Which is correct?
You reject the change because Xmasg Xmxla uses too much system memory,
You accept the change because hoverity is a standard option that has been suppaJ
ava 1.0.
module citizen {
exports com.name to greeting;
}
And
module greeting {
}
•
All members of com.name are accessible only to the citizen and greeting modules.
All members in the com.name package are accessible only to the greeting module.
public members in the com. name package are accessible only to the greeting mo
dule.
Inserting "requires citizen;" at greeting's module-Info.java, enables com.name me
mbers accessible to the greeting module.
?Givem :
public class A {
int a = 0;
int b = 0;
int c = 0;
Given :
package A ;
class Test {
String name;
public Test (String name) {
this. name = name;
}
public String tostring()
return name;
}
}
and
package B;
import A.Test;
public class Main {
public static void main (String [ ] args) {
Test test = new Test ("Student");
System.out.printin (test);
}
}
nothing
It fails to compil
e.
name
Student
null
Given:
public class Test {
}
}
}
}
Given :
}
StringBuilder foo(StringBuilder s)
{
sb2=sb2.append(s+ "oh" );
return sb2;
}
}
What is true ?
hey hi hey oh
yo hi
A compile time error occu
rs
yo hi hey oh
hey oh yo hi
Runnable r = () -> {
try {
Thread.sleep(150);
} catch (InterruptedException e) {
System.out.println(e);
}
c.set(3, "four");
System.out.print(c + " ");
};
1 2 [1, 2, 3, 4] 3 4
1 2 [1, 2, 3, 4] 3 four
1 2 [1, 2, 3, four] 3 4
1 2 [1, 2, 3, four] 3 fo
ur
Given:
List<String> longList = List.of(“Hello”,”World”,”Beat”);
List<String> shortList = new ArrayList<>();
Which code fragment will not forms a short list of words containing the letter “e”?
A. longList.stream()
.filter(w-> w.indexOf('e') != -1)
.parallel()
.forEach(w-> shortList.add(w));
B. longList.parallelStream()
.filter(w-> w.indexOf('e') != -1)
.forEach(w-> shortList.add(w));
C. shortList = longList.stream()
.filter(w-> w.indexOf('e') != -1)
.parallel()
.collect(Collectors.toList());
D. longList.stream()
.filter(w-> w.indexOf('e') != -1)
.parallel()
.collect(shortList);
Option
A
Option
B
Option
D
Option
C
?Given :
public class StrBldr {
static StringBuilder sbl = new StringBuilder("yo ");
StringBuilder sb2=new StringBuilder("hi ");
StringBuilder foo(StringBuilder s)
{
System.out.print (s + " oh " + sb2);
return new StringBuilder("ey");
}
public static void main(String[] args) {
sbl = sbl.append(new StrBldr().foo(new StringBuilder("hey")));
System.out.println(sbl);
}
}
What is the result ?
?Given :
Given :
import java.util.*;
public class Foo {
public List<Number> Foo (Set<CharSequence> m) { . . . }
}
and
import java.util.*;
public class Bar extends Foo {
//line 1
}
Which two statements can be added at line 1 in Bar to override compile it? (Choose t
wo.)
Given:
public static void main(String[] args) {
final List <String> fruits =
List.of("Orange", "Apple", "Lemon", "Raspberry");
final List<String> types =
List.of("Juice", "Pie", "Ice", "Tart");
final vatream = IntStream.range(0, Math.min(fruits.size(), types.size()))
.mapToObj((i)->fruits.get(i) +" " +types.get(i));
stream. forEach(System.out::printIn);
}
double d=i;
Double c=(Double)i;
Double b=Double.valueof(i);
static {
for (var i = 0; i < keys.size(); i++) {
map.put(keys.get(i), values[i]);
}
}
System.out.printIn(Alphabet. getFirstLetter());
Given :
String
List<Characte
r>
char
List<String>
var y = null;
var var = "hello";
var a;
var names = new ArrayList<
>();
var _ = 100;
}
}
}
A)An exception is thrown at run time.
B)Auto:Sedan
Medical: Scanner
C)The compilation fails due to an error on line 2.
D)The compilation fails due to an error on line 1.
E)The compilation fails due to an error on line 3.
Option
B
Option
E
Option
A
Option
C
Option
D
Given TripleThis.java:
6. import java.util.function.*;
7. public class TripleThis {
8. public static void main(String[] args) {
9. Function tripler = x -> { return (Integer) x * 3; };
10. TripleThis.printValue(tripler, 4);
11. }
12. public static <T> void printValue(Function f, T num) {
13. System.out.println(f.apply(num));
14. }
15. }
Given:
class Animal {}
class Dog extends Animal {}
class Petdog extends Dog {}
//and
1. class House<A extends Animal> {}
2. public House<? super Dog> build (A a) {
3. // insert code here
4.}
5. }
Which two statements inserted independently on line 3 will make this code compile?
out.writeObject(bl);
out.flush();
out.close();
} catch (Exception e) {
System.out.println("Unable to Serialize");
}
}
Given :
public class Main {
public static void main(String[] args) {
List<player> players = List.of (new Player ("Scott", 115), new Player ("John", 70), ne
w Player ("Jelly", 105));
double average = // line 1
System.out.println("The average is: " + average);
}
}
class Player {
public String name;
public int score;
public Player (String name, int score) {
this.name = name;
this.score = score;
}
}
our application uses one modular jar (a.jar), which, in turn, uses one non-modular jar
(b.jar). Which of the following commands will cause jdeps to include the non-modular
jar in its analysis?
Select 1 best option:
Given :
public interface A {
public Iterable a ();
}
public interface B extends A {
public Collection a ();
}
public interface C extends A {
public Path a ();
}
public interface D extends B, C {
}
A company has an existing Java app that includes two Java 8 jar files, sales-3.10. jar
and clients10.2.jar.
The jar file ,sales -8, 10, jar reference packages in clients -10.2 jar,
but clients-10.2 jar does not reference packages in sales -8.10, jar.
They have decided to modularize clients-10.2.jar.
Which module-info. Java file would work for the new library version clients-10.3 jar?
module com.company.clients{
exports com.company.clients;
}
module com.company.clients{
exports com.company.clients.Cli
ent;
}
module com.company.clients{
requires com.company.clients;
}
module com.company.clients{
uses com.company.clients;
}
Given :
public class Test {
private int sum;
9
An exception to be thrown at runt
ime
6
3
Given:
public class Person {
private String name;
public void setName(String name) {
String title = "Dr. ";
name = title+name;
}
public String toString () {
return name;
}
}
and
Given :
Automobile.java
public abstract class Automobile { //line 1
abstract void wheels ();
}
Car.iava
public class Car extends Automobile {
/ / line 2
// line 3
void wheels (int i) {
System.out.print (4);
}
public static void main (String[] args) {
Automobile ob = new Car (); // line
ob.wheels () ;
}
}
Given :
Locale l = new Locale("en", "US");
LocalDate today = LocalDate.of(2018, 12, 17);
String mDate = today.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM));
System.out.println(mDate);
String sDate = today.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT));
System.out.println(sDate);
The runtime can process machine language sources as well as executables from di
fferent
language compilers
At runtime, classes are loaded as needed, and new code modules can be loaded o
n demand.
The runtime can process machine language sources as well as executables from di
fferent
language compilers
The Java compiler preprocesses classes to run on specific target platforms.
Given :
String
List<Characte
r>
char
List<String>
41 def 42
def 42
An exception is thrown at runti
me.
null
var i = 1;
var result = IntStream.generate (() -> { return i; })
.limit (100). sum();
System.out.println(result);
Which statement prints the same value of result?