The Criteria API is a predefined API used to define queries for entities. It is the alternative way of defining a JPQL query. These queries are type-safe, and portable and easy to modify by changing the syntax. Similar to JPQL it follows abstract schema (easy to edit schema) and embedded objects. The metadata API is mingled with criteria API to model persistent entity for criteria queries.
The major advantage of the criteria API is that errors can be detected earlier during compile time. String based JPQL queries and JPA criteria based queries are same in performance and efficiency.

History of criteria API

The criteria API is included into all versions of JPA therefore each step of criteria API is notified in the specifications of JPA.
  • In JPA 2.0, the criteria query API, standardization of queries are developed.
  • In JPA 2.1, Criteria update and delete (bulk update and delete) are included.

Criteria Query Structure

The Criteria API and the JPQL are closely related and are allowed to design using similar operators in their queries. It follows javax.persistence.criteria package to design a query. The query structure means the syntax criteria query.
The following simple criteria query returns all instances of the entity class in the data source.

EntityManager em = ...;
CriteriaBuilder cb = em.getCriteriaBuilder();

CriteriaQuery<Entity class> cq = cb.createQuery(Entity.class);
Root<Entity> from = cq.from(Entity.class);

cq.select(Entity);
TypedQuery<Entity> q = em.createQuery(cq);
List<Entity> allitems = q.getResultList();
The query demonstrates the basic steps to create a criteria.
  • EntityManager instance is used to create a CriteriaBuilder object.
  • CriteriaQuery instance is used to create a query object. This query object’s attributes will be modified with the details of the query.
  • CriteriaQuery.from method is called to set the query root.
  • CriteriaQuery.select is called to set the result list type.
  • TypedQuery<T> instance is used to prepare a query for execution and specifying the type of the query result.
  • getResultList method on the TypedQuery<T> object to execute a query. This query returns a collection of entities, the result is stored in a List.

The below video contains the building of a login system from the very basics using MERN technologies. For security purposes JWT will be used to validate the login of a user.



S.O.L.I.D is an acronym for the first five object-oriented design(OOD)** principles** by Robert C. Martin, popularly known as Uncle Bob.
These principles, when combined together, make it easy for a programmer to develop software that are easy to maintain and extend. They also make it easy for developers to avoid code smells, easily refactor code, and are also a part of the agile or adaptive software development.
  • S - Single-responsiblity principle
  • O - Open-closed principle
  • L - Liskov substitution principle
  • I - Interface segregation principle
  • D - Dependency Inversion Principle
A class should have one and only one reason to change, meaning that a class should have only one job.

Objects or entities should be open for extension, but closed for modification.

Let q(x) be a property provable about objects of x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T.

All this is stating is that every subclass/derived class should be substitutable for their base/parent class.

A client should never be forced to implement an interface that it doesn't use or clients shouldn't be forced to depend on methods they do not use.

Entities must depend on abstractions not on concretions. It states that the high level module must not depend on the low level module, but they should depend on abstractions.





Honestly, S.O.L.I.D might seem to be a handful at first, but with continuous usage and adherence to its guidelines, it becomes a part of you and your code which can easily be extended, modified, tested, and refactored without any problems.



Question 01

Create a function as a variable (function expression) that prints ‘Hello World’ to console and another function which accepts a variable. The argument passed to the second function should be executed as a function inside the body. Call the second function passing the first function as the argument. Check the output.


Question 02

 Declare a global variable named "vehicleName in the window object.

 Declare a method named printVehicleName to print out the vehicle name .

 Declare an object named Vehicle(using object literal notation) which have a variable called vehicleName and declare a function named getVehicleName and assign it with the printVehicleName  Execute the printVehicleName function and the getVehicleName functions to see the results.

Correct the getVehicleName to print out the global variable vehicleName using the this keyword.

Question 03

Create a separate function using JavaScript closure which accepts the tax percentage and returns a function which accepts the amount and returns the amount after adding tax percentage. Try adding tax percentage to

‘this’ object and check if it works.

Question 04

Write a function to call GitHub API (https://api.github.com/users) and get users and return the users to the caller



ANSWERS FOR THE ABOVE QUESTIONS ARE GIVEN BELOW













JavaScript is one of the 3 languages all web developers must learn:

   1. HTML to define the content of web pages
   2. CSS to specify the layout of web pages
   3. JavaScript to program the behavior of web pages

Web pages are not the only place where JavaScript is used. Many desktop and server programs use JavaScript. Node.js is the best known. Some databases, like MongoDB and CouchDB, also use JavaScript as their programming language.