Backend (Spring Boot) Flashcards
What is DBeaver?
A free and open source universal database tool for developers and database administrators.
What is Maven (with command mvn)?
Maven is a build automation tool used primarily for Java projects. Unlike earlier tools like Apache Ant, it uses conventions for the build procedure, and only exceptions need to be written down. An XML file describes the software project being built, its dependencies on other external modules and components, the build order, directories, and required plug-ins.
What is the JVM (Java Virtual Machine)?
It is a specification that provides runtime environment in which java bytecode can be executed. A JVM is platform dependent because configuration of each OS differs.
What is the JRE (Java Runtime Environtment)?
It is the implementation of JVM. It physically exists. It contains a set of libraries and other files that JVM uses at runtime.
What is the JDK (Java Development Kit)?
It is a software development environment used for developing Java applications and applets. It includes the JRE, an interpreter/loader (Java), a compiler (Javac), an archiver (Jar), a documentation generator (Javadoc) and other tools needed in Java development.
What is Spring?
It is a framework that helps build web applications. It takes care of dependency injection, handles transactions, implements an MVC framework and provides foundation for the other Spring frameworks (including Spring Boot).
What is Spring Boot?
While you can do everything in Spring without Spring Boot, Spring Boot helps you get things done faster:
- Simplifies Spring dependencies, no more version collisions.
- Can be run straight from a command line without an application container.
- Build more with less code: no need for XML, auto-configuration
- Useful tools for running in production, database initialization, environment specific config files, collecting metrics.
Simply put: Spring Boot = (Spring Framework) + (Embedded HTTP servers e.g. Tomcat, Jetty) - (XML <bean> configuration or @Configuration)</bean>
What is a POM?
A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.
What are the development requirements for Spring?
- Java JDK: $ java -version and $ javac -version
- Maven: $ mvn -v
- Gradle: $ gradle -v
What is Spring Initializr?
Spring Initializr provides an extensible API to generate quickstart projects. It provides a simple web UI to configure the project to generate and endpoints that you can use via plain HTTP.
What is the mvnw file which comes in the Spring Initializr zip file?
A maven wrapper used to run some commands without having maven installed on the system.
$ mvn spring-boot:run
Compile and run an application using maven’s run goal.
What is the Super POM?
The Super POM is Maven’s default POM. All POMs extend the Super POM unless explicitly set, meaning the configuration specified in the Super POM is inherited by the POMs you created for your projects.
What is the use of parent POMs?
Maven also supports the notion of a parent POM. A parent POM enables you to define an inheritance style relationship between POMs. POM files at the bottom of the hierarchy declare that they inherit from a specific parent POM. The parent POM can then be used to share certain properties and details of configuration.
What is JPA?
Java Persistence API, the official API and ORM (Object Relational Mapping) for working with relational data in Java. It is only a specification and not a concrete implementation.
What are implementations of JPA?
- Hibernate with commercial support from Red Hat (72% marketshare)
- EclipseLink: reference implementation (13% marketshare)
- OpenJPA (2% marketshare)
What is the use of JPA?
One API will support many relational databases so that developers get database independence.
How to register a Java class to JPA persistence?
JPA classes are required to:
- Be identified as being a JPA entity class with @Entity.
- Have a default constructor.
- At least have one property defined as the primary key.
Example:
import javax.persistence.*; @Entity public class Author { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String firstName; private String lastName; public Author(String firstName, String lastName) { this. firstName = firstName; this. lastName = lastName; } }
Define relationships with JPA.
Must be defined on two JPA classes:
- @OnetoOne
- @ManyToOne
- @OneToMany
- @ManyToMany
Example: many-to-many relationship between authors and books with a single join table.
@ManyToMany(mappedBy = "authors") private Set books = new HashSet(); ... @ManyToMany @JoinTable(name = "author_book", joinColumns = @JoinColumn(name = "book_id"), inverseJoinColumns = @JoinColumn(name = "author_id")) private Set authors = new HashSet();
What are the equals() and hashcode() methods from java.lang.Object?
For comparing objects:
- equals(Object obj): indicates whether some other object passed as an argument is “equal to” the current instance. The default implementation provided by the JDK is based on memory location — two objects are equal if and only if they are stored in the same memory address.
- hashcode(): returns an integer representation of the object memory address. By default, this method returns a random integer that is unique for each instance, even between several executions of a program.
What is advised to Java developers as for the equals() and hashcode() methods for large projects?
The default implementation is not enough to satisfy business needs. As per the Java documentation, developers should override both methods in order to achieve a fully working equality mechanism regardless of the memory addresses — it’s not enough to just implement the equals() method.
What is the relation between equals() and hashcode()?
If two objects are equal according to the equals(Object) method, then calling the hashcode()method on each of the two objects must produce the same integer result.
What are Spring Data repositories?
A Spring Data repository has methods for retrieving domain objects. These methods delegate to a specialized Repository object such that alternative storage implementations may be interchanged.
What is the purpose of Spring Data repositories?
Allow to easily subsitute the persistence layer.
What is the difference between a directory and a package in a Java project?
If configured correctly, adding a folder inside src/ is the same as adding a package from File > New Package using an IDE.
How is defined the name of a package?
When you create a package/directory under src/ the package name starts from the first subdirectory after src/. So, src/com/sub/test will be package com.sub.test.
How to create a Spring Data repository?
In the app directory, create a repositories/ directory. To inject Spring Data into a particular model, create a public interface like the following:
(Note: IdType can be Long, Int…)
package ###.repositories import ####.model.MyModel import org.springframework.data.repository.CrudRepository public interface MyModelRepository extends CrudRepository < MyModel, IdType > { }