Basics Flashcards

1
Q

How to determine length/size for objects?

A
size() is a method specified in java.util.Collection, which is then inherited by every data structure in the standard library. 
length is a field on any array (arrays are objects, you just don't see the class normally)
length() is a method on java.lang.String
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

diff between sleep and wait

A

wait() is used for thread synchronization.

It can be called on any object, as it’s defined right on java.lang.Object, but it can only be called from a synchronized block. It releases the lock on the object so that another thread can jump in and acquire a lock.

Wait is used for inter-thread communication while sleep is used to introduce pause on execution.

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

How can you group objects by a certain value in java

A

Lambdas
Map> postsPerType = posts.stream()
.collect(groupingBy(BlogPost::getType));

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

ACID in databases

A

Atomic
Consistent(it must conform to existing constraints in the database)
Isolated ( it must not affect other transactions) and durable (it must get written to persistent storage).

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

What is a database transaction

A

Any logical unit of work. Multiple operations may be needed to perform a transaction

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

What is REST

A

REST stands forRepresentationalStateTransfer. (It is sometimes spelled “ReST”.) It relies on a stateless, client-server, cacheable communications protocol – and in virtually all cases, the HTTP protocol is used.

REST isan architecture stylefor designing networked applications. The idea is that, rather than using complex mechanisms such as CORBA, RPC or SOAP to connect between machines, simple HTTP is used to make calls between machines.

  • In many ways, the World Wide Web itself, based on HTTP, can be viewed as a REST-based architecture.
    RESTful applications use HTTP requests to post data (create and/or update), read data (e.g., make queries), and delete data. Thus, REST uses HTTP for all four CRUD (Create/Read/Update/Delete) operations.

REST is a lightweight alternative to mechanisms like RPC (Remote Procedure Calls) and Web Services (SOAP, WSDL, et al.). Later, we will see how much more simple REST is.

  • Despite being simple, REST is fully-featured; there’s basically nothing you can do in Web Services that can’t be done with a RESTful architecture.
    REST is not a “standard”.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what does \s represent?

A

\s - matches single whitespace character. \s+ - matches sequence of one or more whitespace characters

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

Indexing in DB

A

Indexing in Databases
Indexing is a way to optimize performance of a database by minimizing the number of disk accesses required when a query is processed.
An index or database index is a data structure which is used to quickly locate and access the data in a database table.
Indexes are created using some database columns.
The first column is the Search key that contains a copy of the primary key or candidate key of the table. These values are stored in sorted order so that the corresponding data can be accessed quickly (Note that the data may or may not be stored in sorted order).
The second column is the Data Reference which contains a set of pointers holding the address of the disk block where that particular key value can be found.
There are two kinds of indices:

Ordered indices: Indices are based on a sorted ordering of the values.
Hash indices: Indices are based on the values being distributed uniformly across a range of buckets. The buckets to which a value is assigned is determined by function called a hash function.
There is no comparison between both the techniques, it depends on the database application on which it is being applied.
Access Types: e.g. value based search, range access, etc.
Access Time: Time to find particular data element or set of elements.
Insertion Time: Time taken to find the appropriate space and insert a new data.
Deletion Time: Time taken to find an item and delete it as well as update the index structure.
Space Overhead: Additional space required by the index

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

What is Domain Driven Design?

A

DDD focuses on three core principles:

Focus on the core domain and domain logic.
Base complex designs on models of the domain.
Constantly collaborate with domain experts, in order to improve the application model and resolve any emerging domain-related issues.

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

What is a memory leak?

A

A Memory Leak is a situation when there are objects present in the heap that are no longer used, but the garbage collector is unable to remove them from memory and, thus they are unnecessarily maintained.

memory leak analysis — it’s more a debugging practice than something we would like to keep in the production code. Calling System.gc() and seeing heap space still being high might be an indication of a memory leak.

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

Causes of memory leak

A

Some causes:

  1. Usage of a lot of static variables. these end up existing during the entire duration of the application and therefore consume resources
  2. close resources properly(use finally , or try with resources)
  3. Improper equals and hashcode implementation. If we use a custom object as a key in hashmap without proper equals and hashcode then the memory utilized may rise
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are thread pools

A

A thread pool reuses previously created threads to execute current tasks and offers a solution to the problem of thread cycle overhead and resource thrashing. Since the thread is already existing when the request arrives, the delay introduced by thread creation is eliminated, making the application more responsive.

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

What are futures in Java

A

Future class represents a future result of an asynchronous computation – a result that will eventually appear in the Future after the processing is complete.

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

What is throttling

A

It is a way to restrict the rate at which api’s can process requests per sec/ minute or ….. Spring boot has a throttling library. Java has a bucket4J library

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

Convert List of integers to int[] in java

A

result.stream().mapToInt(Integer:: intValue).toArray();

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

Java Generics

A

specifying a type so at compile time bugs can be detected

List  = new ArrayList()
if we didnt specify string then we would have to cast
17
Q

Java Immutable class

A

Immutable class means that once an object is created, we cannot change its content. In Java, all the wrapper classes (like Integer, Boolean, Byte, Short) and String class is immutable. We can create our own immutable class as well.

Following are the requirements:

The class must be declared as final (So that child classes can’t be created)
Data members in the class must be declared as private (So that direct access is not allowed)
Data members in the class must be declared as final (So that we can’t change the value of it after object creation)
A parametrized constructor should initialize all the fields performing a deep copy (So that data members can’t be modified with object reference)
Deep Copy of objects should be performed in the getter methods (To return a copy rather than returning the actual object reference)
No setters (To not have the option to change the value of the instance variable)