Section 1

Preview this deck

Why the declaration {String str = "some text"} is better than {String str = new String("some text")}

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

4 years ago

Date created

Mar 1, 2020

Cards (44)

Section 1

(44 cards)

Why the declaration {String str = "some text"} is better than {String str = new String("some text")}

Front

Because in case there is already a String object "some text" in the heap, the first declaration refers to that object (from the String Literal Pool), while the second creates a new object in the heap which ends up with 2 identical objects for the same string in the heap.

Back

Common methods of HashSet

Front

add(E e) remove(Object o) -------------------------- iterator() >> Iterator<E> contains(Object o) -------------------------- size() isEmpty()

Back

Show Java command line options

Front

java -X

Back

Java 10 features

Front

- Local-variable type inference

Back

Common methods of Iterator<E>

Front

hasNext() >> boolean next() >> E

Back

When to use a Set collection

Front

when uniqueness matters (this Collection doesn't allow duplicates)

Back

When to use a List collection

Front

when sequence matters (this Collection knows about index position)

Back

Is java heap space dictated by RAM or hard drive?

Front

By RAM

Back

HashMap initialisation

Front

HashMap<K, V> hm = new HashMap<K, V>();

Back

Looping constructs in Java

Front

- While - do-while - for

Back

Docking an exception

Front

When not being able to handle an exception, you declare throwing it, although you are not the one who does.

Back

Does remove (Object) of List remove all occurrences in it?

Front

No, only the first.

Back

Heap

Front

It is the memory area the JVM uses to save information of the objects in the run time.

Back

Does declaring an object create it?

Front

No

Back

ArrayList initialisation

Front

ArrayList<E> arr = new ArrayList<E>();

Back

LinkedList vs ArrayList

Front

- LinkedList quick in insertion and removal using Iterator. Slow at random access of data. - ArrayList quick in random access of data, but slow at random insertion and removal (not to the end of list).

Back

iterate over a map

Front

for(Map.Entry<K> entry : someMap.entrySet()){ K someK = entry.getValue(); ... }

Back

Array declaration (e.g. int)

Front

int[] someArray;

Back

Does code in final block runs, even when try/catch blocks contain return statement?

Front

Yes

Back

Is Map a Collection?

Front

no, it doesn't inherit the Collection interface, but it is still part of the "collection framework".

Back

When to use a Map

Front

when finding something by key matters

Back

HashSet initialisation

Front

HashSet<E> hs = new HashSet<E>();

Back

Reference equality vs object equality

Front

Reference equality: when one object in the heap but two references to it. Object equality: when two objects in the heap

Back

Are objects in a list held by value or reference?

Front

By reference

Back

Maven

Front

A build-automation tool (used primarily for Java projects)

Back

Inversion Of Control (IoC)

Front

Where the high level classes (business logic) dosn't depend on the low level classes.

Back

What is the Object.hashCode() method base on?

Front

It is based on the address of the object in the heap

Back

When to use queue

Front

When need to add or remove elements only from one of the ends of list.

Back

Common methods of HashMap

Front

put(K key, V value) remove(K key) -------------------------- keySet() >> set<K> values() >> Collection<V> get(K key) containsKey(K key) / containsValue(V value) -------------------------- size() isEmpty()

Back

Types of Nested Classes

Front

1. static nested classes 2. inner classes class outerClass { static class staticNestedClass { .... } class innerClass { .... } }

Back

Read input from command line

Front

Scanner scanner = new Scanner(System.in); String username = scanner.next(); int age = scanner.nextInt();

Back

Memory types in Java

Front

- Heap (or shared) memory: the runtime data area for class instances and arrays. (where the multiple threads share same data.) - Non-Heap memory: includes: --* Method memory: per-class structure (runtime constants and static fields) + code of methods. --* Other memory required for internal processing.

Back

Common methods of String object

Front

length() equals() charAt(int index)

Back

String Literal Pool

Front

It is a collection of references to string objects.

Back

Common methods of ArrayList

Front

add(E e) / add(int index, E e) remove(E e) / remove(int index) -------------------------- iterator() >> Iterator<E> get(int index) indexOf(E e) -------------------------- size() isEmpty()

Back

Array creation (e.g. int)

Front

int[] someArray = new int[4]; Or int[] someArray = {4, -2, 0, 15}

Back

Does order of catch blocks matter? Why?

Front

Yes, because exceptions are polymorphic, and you better catch subclasses then the supper classes.

Back

Default value of int

Front

Zero

Back

How are maven project configured?

Front

Using a Project Object Model (pom.xml file on the root directory of the project)

Back

Must we dock an exception if we don't catch it but only wrap it with a try (and final)?

Front

yes we must dock it.

Back

How to compare Strings?

Front

aString.equals( bString )

Back

Type inference

Front

The automatic detection of the data type of a variable or expression.

Back

Five ways iterate over a List

Front

1. For Loop 2. Advanced For Loop 3. Iterator 4. While Loop 5. Collections's stream() util (Java8)

Back

Can an array contain objects?

Front

yes

Back