Java-201 Flashcards

1
Q

What is a type-safe?

A

It preserves a method arg to assign illegal values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Are enums case senstives?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can we get the reference of enums?

A

Volume level = Volume.LOW

Volume level = Volume.valueOf(“LOW”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How many ways we can create threads

A

Two ways
By implementing the runnable in interface
And by extension to the athread class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Does the time of execution of thread is guaranteed

A

Nope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How many executors are defined by concurrency package

A

Executor
Executor service
Scheduled executor service

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Does - is allowed in identifiers?

A

Nope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the regex pattern for space

A

\s+ (one or many)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are Streams?

A

They are wrapper for Collections and arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Does Streams don’t store its elements.

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Are Streams immutable ?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Are Streams reusable?

A

No, Once traversed , Need to create a new one

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Does Stream support indexes access its elements?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Can stream execute its operations concurrently?

A

Yes need not to write MT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Does Stream operations are lazy when possible?

A

Yes , when someone calls(Subscribe virtually)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Tell me the IF for Stream?

A

java.util.stream.Stream interface

17
Q

Is java.util.stream.Stream interface works with primitives?

18
Q

Which streams is to work with primitives?

A

IntStream, LongStream,DoubleStream,

19
Q

How many ways the streams are created?

A
Using stream()
List list = Arrays.asList(new String[]{"dsd","sdsd"});

Stream stream = words.stream();

Using Stream.of()

Stream stream = Stream.of(“hello”,”hola”, “hallo”, “ciao”);

String[] words = {“hello”, “hola”, “hallo”, “ciao”};
Stream stream = Stream.of(words);

20
Q

How can we create IntStream?

A

int[] nums = {1,2,3,4}

Stream.of(nums)

21
Q

If we do Stream.of(nums).count(), why it prints 1?

A

It the no of objects inside

22
Q

What is the difference it makes to call a public nested class with the hosted class object?

A

that way nested class will have its value existed to hosted class, else without hosted object it will have its own existence

23
Q

Does Arrays class also has stream functions?

A

YEs int nums[] = {1,2,34,4}

Arrays.stream(nums).count()
Or
Use the primitive version
IntStream.of(nums).count()

24
Q

How can we generate a stream with Supplier?

A

With the Stream.generate function

static Stream generate(Supplier s)

Stream s = Stream.generate(new Supplier() { 
    public Double get() { 
        return Math.random(); 
    } 
}).limit(5);

Stream s = Stream.generate(() -> Math.random()).limit(5);

Or just:

Stream s = Stream.generate(Math::random).limit(5);

25
What is java.util.stream package?
It contains classes for stream creation and manipulation
26
What is collector in Stream?
it provides a mutable reduction operator and store the intermediate results, and then leads to final transformation
27
Do we have Builder for Primitives ?
Yes IntStream, DoubleStream, LongStream.Builder like classes
28
Are the Builders Immutable?
YEs
29
What is the Collectors class in Stream?
It is an impl for Collector, which helps is providing various reduction operators
30
What is StreamSupport?
Low-level class for manipulating and creating Stream
31
What is the general sequence of a chain of operations in the stream?
collections > stream > filter(where caluse) > reduce(transform or narrowing again) > aggregate operations int sum = widgets.stram().filter(p -> p.getColor() == RED).mapToInt(p -> b.getWeight()).sum();
32
What is functional programming?
In which you do not work on an object , you work on applying a function to data. It does not support creating models
33
In what ways Stream differ from collections?
No Storage, functional in nature, laziness( can apply lazy filtering, mapping, duplicate kind of operations) , Possible Unbounded : allows short-circuiting operation in finite time like limit(), findFirst, consumable: can only iterate only once , a new stream has to be created to consume again
34
State ways in which a Stream can be consumed?
``` Collection: stream , parallelstream Array : Arrays.stream() Static method in Stream : Stream.of(Object[]), InteStream.range(int, int) & Stream.iterate(Object, UnaryOperator) File : BufferredReader.lines() File paths: Files class methids Random : Random.ints ``` BitSet.stream(), Pattern.splitAsStream(java.lang.CharSequence), and JarFile.stream().
35
Can enum be equated with == ?
Yes and correct way
36
What are the two Stream operations?
Intermediate & terminal operations
37
How is the Stream sequecne goes?
pipeline(Collection, array, a generator function, I/O channel) > internediate operations Stream.filer or Stream.map > terminal operations Stream.forEach or Stream.reduce
38
If we do have break is switch, what will happen?
It will go to the next case automatically