Sunteți pe pagina 1din 22

JVM vs JDK vs JRE

● JVM - masina virtuala care executa codul Java. Ruleaza pe partea de sus a OS.
Transforma byte code in cod masina
● JDK - java developer kit, este necesar pentru dezvoltare deoarece contine JRE +
instrumentele de dezvoltare (compilatorul java - javac, este inclus numai in JDK)
● JRE - mediul de executie al codului Java. JVM este inclus in JRE. Nu contine
compiler, debugger etc.

Mostenire multipla
● Java nu suporta mostenirea multipla din cauza “problemei diamantului” care apare in
alte limbaje cum ar fi C++. B si C extinde A, D extinde B si C
● Totusi mostenirea multipla este posibila in Java prin Interfete.

Metoda main()
● Public static void main(String[] args)
● Este punctul de intrare al oricarei aplicatii Java.
● Public si static => pentru a fi accesata de Java fara initializare.
● String[] args => array de String prin care putem pasa argumente la runtime

Overloading vs overriding
● Overloading => metoda cu semnatura diferita ( argumente diferite )
● Overriding => metoda cu aceeasi semnatura, specifica mostenirii, clasa copil
suprascrie metoda din clasa parinte.
● Putem avea mai multe metode main dar una singura e main()

Multiple clase Java publice


● Nu putem avea mai mult de o clasa publica intr-un singur fisier sursa Java.

Pachete Java
● Modalitatea de organizare a claselor Java
● Pachetul java.lang e importat default.

Modificatori de acces
● O clasa Java poate avea doar public sau default
Final keyword
● La clase inseamna ca acea clasa nu poate fi mostenita - (clasa String e final).
● La metode inseamna k nu poate fi suprascrisa.
● La variabile inseamna k le pot fi atribuite valori o singura data => constante.
● Intefetele => static si final by default

Static keyword
● La nivel de clasa => o face globala => toate obiectele vor sharui aceeasi variabila
● La metode => o metoda statica poate accesa doar variabile statice ale clasei.

Finally si Finalize
● Blocul finally se foloseste intr`un bloc try,catch => se executa intotdeauna*
● finalize() => metoda ce poate fi suprascrisa pentru a notifica Garbage Collectorul
cand sa isi faca treaba

Try-with-resources
● Feature al Java 7 care face management auto al resurselor => inchide resursele
imediat dupa executarea blocului try, catch

Blocuri statice
● Sunt executate cand clasa este incarcata in memorie de Class Loader =>
initializeaza variabilele statice ale clasei.

Interfete
● Mod de abstractizare in java prin care se stabileste un contract
● Nu putem instantia o interfata => nu are constructori si nici metode implementate
● Orice atribut e public, final si static
● Metodele sunt publice si abstracte
● Nu poate extinde o clasa
● Interfetele nu pot implementa alte interfete dar le pot extinde.
● Din Java 8 interfetele pot avea implementari default ale metodelor.
● Interfetele marker => interfete fara metode sau body => Serializable si Cloneable
Clase abstracte
● O clasa care contine implementarea default a unor metode.
● Poate avea metode abstracte si concrete
● Nu poate fi instantiata

Interface vs Abstract class


● Fields: public static final <=> static/non-static, final/non-final, public/private/protected
● Methods: public abstract void + default + static + NOT FINAL <=> final
● Constructors: NO <=> YES

Interface doesn't have:


● Constructors
● Campuri non-statice si non-final
● Metode si campuri private sau protected
● Metode finale

Clasele wrapper
● Reprezentarea in obiecte a primitivelor
● Sunt imutabile si finale
● Autoboxing => primitiva in obiect, int -> Integer;
- se face automat de Java atunci cand se paseaza ca parametru un primitiv si metoda
asteapta un obiect
- cand adaugi un primitiv intr-o lista de obiecte
● Unboxing => obiect in primitiv; la fel ca la autoboxing dar invers
● Primitivele nu pot fi null dar clasele wrapper pot fi

Enum
● Tip care contine ca fielduri constante
● Poate implementa interfete
● Constructorii sunt privati, nu pot fi instantiate cu new

Anotatii
● Metadata despre program; putem crea o anotare noua cu public @interface
AnotareNoua;
● Ex. @Override, @Deprecated => anunta compilerul ca metoda este deprecata
Composition
● Se refera la relatia has-a; Person has a Job attribute
● Se foloseste composition in favoarea mostenirii:

Comparable si Comparator
● Comparable - interfata pentru sortarea colectiilor; are compareTo(T obj), returneaza
int(negativ, 0, pozitiv); Nu putem testa decat dupa un singur parametru
● Comparator - interfata; are compare(Object o1, Object o2), returneaza int

Clase Inner
● Clasa non-statica in alta clasa
● Clasele inner pot accesa membrii si metodele clasei outer
● Clasa inner fara nume => anonima

Super keyword
● Poate fi folosit pentru accesarea metodei clasei parinte
● Pentru invocarea constructorului din clasa parinte

This keyword
● Se refera la obiectul curent, se foloseste pentru distinctia de variabilele locale care
au acelasi nume; pentru invocarea altui constructor dintr-un alt constructor.

Break, continue
● Break - termina executarea unei bucle while, for, do-while; poate fi folosit in switch
pentru a iesi din case;
● Continue - trece peste iteratia curenta dintr-un while, for si do-while.

Serializare
● Convertirea unui obiect Java in Stream pentru a fi trimis mai departe. Se face prin
implementarea interfetei Serializable.
Pass by value vs Pass by reference
● Java este pass by value
● When an object is passed by value, this means that a copy of the object is
passed. Thus, even if changes are made to that object, it doesn’t affect the
original value. When an object is passed by reference, this means that the actual
object is not passed, rather a reference of the object is passed. Thus, any
changes made by the external method, are also reflected in all places.

String
● == verifica si daca obiectele sunt egale; folosim equals();
● Este thread safe, imutabil si final
● Cand facem concat, substrig se creaza un nou String => pentru asta se folosese
clasele StringBuffer si StringBuilder.
● StringBuffer este sincronizat => threadSafe

Ways of creating a thread


● There are three ways:
○ A class may extend the Thread class.
○ A class may implement the Runnable interface.
○ An application can use the Executor framework, in order to create a thread pool.
The Runnable interface is preferred, as it does not require an object to inherit the Thread
class. In case your application design requires multiple inheritance, only interfaces
can help you. Also, the thread pool is very efficient and can be implemented and
used very easily.

Collections Framework
● Contine Collection, Set, List si Map
● Java Collection Framework este un set de clase si interfete care contine structuri de
date.
● Iterator => interfata pentru a itera prin colectii. Se foloseste atunci cand vrem sa
iteram si sa stergem ceva dintr-o colectie.
● termenul ordonat înseamnă că ordinea elementelor este stabilita în funcţie de index.

List vs Set
● List - poate contine duplicate, este ordonata;
● Set - nu poate contine duplicate, neordonata,;
Map vs Set
● Map - chei unice cu orice valori;
● Set - doar valori unice;

Array vs ArrayList
● Array - marime statica, poate contine primitive
● ArrayList - marime dinamica, NU poate contine primitive

LinkedList vs ArrayList
● LinkedList - nesincronizate, insert sau add mai rapid
● ArrayList - nesincronizate, get(index) mai rapid

HashSet vs TreeSet
● HashSet - NU pastreaza elementele in ordinea introdusa, poate contine obiecte
null
● TreeSet - pastreaza elementele in ordinea introdusa, NU poate contine obiecte
null

HashMap vs HashTable
● HashMap => foloseste hashCode si equals pentru a pune si recupera elemente;
implementeaza interfata Map;
○ Permite kei si valori null si nu permite duplicate
○ Nu este sincronizat
● Hashtable => implementeaza Map;
○ Nu permite kei sau valori null si nu permite duplicate
○ Este sincronizat

Arrays
- they are a single block of memory(this is why we need to specify the size at creating)
- every element occupies the same amount of space in memory
- if we know the index of an element the time to retrieve the element will be the same, no
matter where is it in the array
- memory efficient when we know the index
ArrayList
- is backed by an Array
- not synchronized
- great for iteration
- add is slow if the array is not large enough
- insert/remove not at the end is slow because...well...shifting
- shifting is made by copying the array in the bg
- default capacity is 10

Vectors
- ArrayList thread-safe(synchronized). It was added before ArrayList

LinkedList
- doubly-linked list implementation of List and Deque
- not synchronized
- operation at head/tail => fast

Map
- is using a hash function to hash the key to an int value. The value is stored at the
hashed key value -> this is the index into the array
- Bucket sort: the values in bucket X must be greater than the values in bucket X-1 and
less that ... X+1
- Hashmap can have null values and a null key, not synchronized.
- LinkedHashMap -> has an list implementation, retains the order of the insertion, not
synchronized.
- HashTable -> you can't have null key or values, synchronized.
- keySet -> all keys in a map are a set
- values() -> all values in a map are a collection
- HashMap uses hashing, TreeMap uses ordering
- Create, modify or delete of objects in map => map.compute(key, (behaviour) (key,
value) -> value.doSomething())
- Map doesn't implement the Iterable interface => we need to specify what we want: the
keys, the values or the key value pair {k,v}
-> the keys = Set without order
-> the values = collection without order
-> the pair = Set (EntrySet)
Generalization is made with interfaces and implementations.

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (!(object instanceof Class)) {
return false;
}
Class class = (Class) object;
return class.value == object.value;
}

Set
- NO duplicates
- not ordered & no index
- TreeSet => ordered, does not call equals, it uses compare

Collection Ordonata Acces (K,V) Duplicate Null Thread Safe


Rand
om

ArrayList DA DA NU DA DA NU

Vector DA DA NU DA DA DA

HashMap NU DA DA NU DA NU

HashTable NU DA DA NU NU DA

TreeMap DA DA DA NU NU NU

LinkedList DA NU NU DA DA NU

HashSet NU NU NU NU DA NU

TreeSet DA NU NU NU NU NU
Exceptii
● Throw - arunca o exceptie la runtime, se foloseste in interiorul metodei, se separa
prin pipe “|”
● Throws - semnaleaza ca metoda poate genera exceptia, se foloseste in semnatura
metodei, se separa prin virgula;

Cheched vs Unchecked
● Checked = compilare → trebuie sa fie tratate fie cu try catch fie throws; nu sunt
cauzate de program
■ ClassNotFoundException
■ IOException, FileNotFoundException,EOFException
■ SQLException, ParseException
■ NoSuchField/NoSuchMethod Exception

● Unchecked = runtime → nu trebuie sa fie tratate neaparat; sunt cauzate de


programator
■ NullPointerException
■ ArrayIndexOutOfBounds, IndexOutOfBounds Exception
■ ArithmeticException, NumberFormarException
■ ClassCastException

Exceptii custom
● Prin extinderea clasei Exception

Exceptii aruncate de main()


● Cand main() arunca exceptie, java runtime opreste procesul si printeaza stack traceu
in consola

Bloc catch gol


● Este posibil dar nerecomandat
Spring Core

Spring
● framework care te ajuta cu infrastructura aplicatiei; se foloseste ioc/di(monitor
exemplu)
● Modulele: Spring core, mvc, aop (aspect oriented programming), security, testing,
web services
● Spring container - instantiere, distrugere, creare bean-uri - life cycle; se foloseste app
context
● Manage-uieste doar bean-urile, nu si alte obiecte.
● Schema Spring WS
○ Clientul trimite un req servlet dispatcher-ului. Acesta il intercepteaza si il trimite unui
handler si primeste o mapare (locatia controller-ului) de la handler. Mai departe se
duce la locatia controller-ului care i-a fost sugerata. Controller-ul trimite un req catre
bd si primeste datele de acolo. Trimite un model catre SD, iar acesta trimite Model
Object catre View Resolver si acesta trimite inapoi view-ul catre SD. Mai departe se
trimite inapoi la client view-ul.

● Servlet Dispatcher - server care gestioneaza request-urile, ele sunt mapate la


controllere (semafor)

Bean
● Obiectele create de Spring Container;
○ se pot crea fie prin xml
○ Java Based Configuration (@Bean + @Configuration)
○ Adnotari
● Scope-uri - singleton, prototype si pentru MVC - session, request, global-session
○ Singleton - o singura instanta per App Context (e default)
○ Prototype - oricate instante per AC
○ Session - o instanta per HTTP session
○ Request - o instanta per HTTP request
○ Global-session - o instanta pe global HTTP session

● @Autowired - injecteaza automat un bean; poate fi byType, byName, byConstructor


sau No;
● @Component - modalitate generica de a reprezenta componente spring; si de a
seta o clasa => Bean
● @Controller - modalitate generica de a reprezenta rolul unei clase de controller
(Spring MVC apps);
● @Repository - componenta joaca rolul unui repository de a manipula date; se
foloseste cu cu clasele de DAO
● @Service - componenta de Service, logica de bussiness
● Anotatii pentru a seta init si destroy pentru bean - @PostConstruct inainte de
metoda init respectiv @PreDestroy inainte de metoda destroy din clase;
● @RequestMapping => mapeaza catre un url

1. Why Spring?
● It`s lightweight because it uses POJO model and highly modular
● Spring POJO model makes testing easy
● Makes life easy by allowing devs to focus on business logic while it takes care of the
low level "plumbing"

2. Spring Modules:
● Core container: Beans, Core, Context, SpEL
● AOP, Aspects, Messaging
● Data Access/Integration: JDBC, ORM(Hibernate), JMS, Transactions
● Web: WebSocket, Servlet, Web
● Test

3. IOC Container
● Find Beans
● Wire dependencies
● Manage lifecycle of the Beans

4. Application Context
● Bean Factory++
○ Spring AOP features
○ Internationalization capabilities
○ WebApplicationContext for web apps etc

● @ComponentScan - search packages where beans are defined (S.B.


@SpringBootApplication initiate automatically a ComponentScan in what package is
in)
● @Controller - Spring MVC controller
● @Component - Spring should manage the bean
● @Repository - methods on a database
● @Service - Business Service Facde
● @Autowired - Spring should find the bean and inject it
5. Setter Injection vs Constructor Injection
● When is made without setter or constructor we use reflection:
@Autowired
TodoService todoService; => although this is in the category of setter injection
● Constructor Injection constructs an immutable bean

6. Lifecycle of beans:
● Instantiere
● Populare campuri
● Setarea numelui beanului
● Setarea bean Factory
● Pre-initializare si initializare
● Post-initializare
● Distrugere - destroy() method

MISC
● CRUD
○ POST - creeaza o resursa; nu este idempotenta;
○ GET - citeste resursele; nu modifica starea serverului; este idempotenta - mai multe
cereri vor crea acelasi raspuns
○ PUT - actualizeaza sau poate si creea; idempotenta;
○ DELETE - sterge; idempotenta;

● Un serviciu Web este o aplicatie Web de tip client-server, în care un server furnizor
de servicii (numit si "Service Endpoint") este accesibil unor aplicatii client (care nu
sunt de tip browser) pe baza adresei URL a serviciului. Serviciul Web si clientii sãi
pot rula pe platforme diferite si pot fi scrise în limbaje diferite, deoarece se comunicã
prin protocoale standard HTTP, XML, SOAP, JSON, s.a.
○ Servicii de tip REST ( RESTful Web Services), în care cererile de la client se exprimã
prin comenzi HTTP (GET, PUT, POST,DELETE), iar rãspunsurile sunt primite ca
documente XML sau JSON;
○ Servicii de tip SOAP (Simple Object Access Protocol), în care cererile si rãspunsurile
au forma unor mesaje SOAP (documente XML cu un anumit format) transmise tot
peste HTTP. In astfel de servicii furnizorul expune si o descriere a interfetei API sub
forma unui document WSDL (Web Service Description Language), care este tot XML
si poate fi prelucrat de client. Un client trebuie sã cunoascã metodele oferite de cãtre
“Service Endpoint”, pe care le poate afla din descrierea WSDL.
The key parts of the singleton pattern are
1. A private static variable to store the single instance called the singleton. This variable
is usually final to keep developers from accidentally changing it.
2. A public static method for callers to get a reference to the instance.
3. A private constructor so no callers can instantiate the object directly.

Here’s a list of things to do to create an immutable


class:

1. Mark the class final so that it cannot be extended.


2. Mark its variables private and final.
3. If the constructor takes any mutable objects as arguments, make new copies of those
objects in the constructor.
4. Do NOT provide any setter methods!
5. If any of the getter methods return a mutable object reference, make a copy of the
actual object, and return a reference to the copy.

Proxy example => Collection.unmodifiableMap(map)

Consumer -> functional interface that takes one argument and returns nothing =>
consumes the argument
- ex: s -> System.out.println(s)
Predicate -> functional interface that that takes one argument and returns a boolean
- ex: s -> s.startWith("a")
UnaryOperator (subinterface of Function) -> functional interface that takes one argument
and returns an object of the same type
- ex: s -> s.toUpperCase("a")

What is a Functional Interface? What is SAM Interface?


A Functional Interface is an interface, which contains one and only one abstract method.
Is is possible to define our own Functional Interface? What is
@FunctionalInterface? What are the rules to define a
Functional Interface?
Yes, it is possible to define our own Functional Interfaces. We use Java SE 8’s
@FunctionalInterface annotation to mark an interface as Functional Interface.

We need to follow these rules to define a Functional Interface:

● Define an interface with one and only one abstract method.


● We cannot define more than one abstract method.
● Use @FunctionalInterface annotation in interface definition.
● We can define any number of other methods like Default methods, Static methods.
● If we override java.lang.Object class’s method as an abstract method, which does not
count as an abstract method.

What is the benefit of Composition over Inheritance?


One of the best practices of Java programming is to “favor composition over inheritance”.
Some of the possible reasons are:
● Any change in the superclass might affect subclass even though we might not be
using the superclass methods. For example, if we have a method test() in the
subclass and suddenly somebody introduces a method test() in the superclass, we
will get compilation errors in the subclass. The composition will never face this issue
because we are using only what methods we need.
● Inheritance exposes all the superclass methods and variables to the client and if we
have no control in designing superclass, it can lead to security holes. Composition
allows us to provide restricted access to the methods and hence more secure.
● We can get runtime binding in composition where inheritance binds the classes at
compile time. So composition provides flexibility in the invocation of methods.

What is Java Reflection API? Why it’s so important to have?


● Java Reflection API provides the ability to inspect and modify the runtime behavior of
java application.
● We can inspect a java class, interface, enum and get their methods and field details.
● Reflection API is an advanced topic and we should avoid it in normal programming.
Reflection API usage can break the design pattern such as Singleton pattern by
invoking the private constructor i.e violating the rules of access modifiers.
● Even though we don’t use Reflection API in normal programming, it’s very important
to have. We can’t have any frameworks such as Spring, Hibernate or servers such as
Tomcat, JBoss without Reflection API. They invoke the appropriate methods and
instantiate classes through reflection API and use it a lot for other processing.
What is inner class in java?
We can define a class inside a class and they are called nested classes. Any non-static
nested class is known as inner class. Inner classes are associated with the object of
the class and they can access all the variables and methods of the outer class. Since
inner classes are associated with the instance, we can’t have any static variables in
them.

What is anonymous inner class?


A local inner class without name is known as anonymous inner class. An anonymous class
is defined and instantiated in a single statement. Anonymous inner class always
extend a class or implement an interface.
Since an anonymous class has no name, it is not possible to define a constructor for an
anonymous class. Anonymous inner classes are accessible only at the point where it
is defined.

What is difference between Checked and Unchecked


Exception in Java?

1. Checked Exceptions should be handled in the code using try-catch block or else
method should use throws keyword to let the caller know about the checked
exceptions that might be thrown from the method. Unchecked Exceptions are not
required to be handled in the program or to mention them in throws clause of the
method.
2. Exception is the super class of all checked exceptions whereas RuntimeException is
the super class of all unchecked exceptions. Note that RuntimeException is the child
class of Exception.
3. Checked exceptions are error scenarios that requires to be handled in the code, or
else you will get compile time error. For example, if you use FileReader to read a file,
it throws FileNotFoundException and we must catch it in the try-catch block or throw
it again to the caller method. Unchecked exceptions are mostly caused by poor
programming, for example NullPointerException when invoking a method on an
object reference without making sure that it’s not null. For example, I can write a
method to remove all the vowels from the string. It’s the caller responsibility to make
sure not to pass null string. I might change the method to handle these scenarios but
ideally the caller should take care of this.
What is difference between throw and throws keyword in
Java?

● throws keyword is used with method signature to declare the exceptions that the
method might throw whereas throw keyword is used to disrupt the flow of program
and handing over the exception object to runtime to handle it.

Why String is immutable or final in Java?

There are several benefits of String because it’s immutable and final.

● String Pool is possible because String is immutable in java.


● It increases security because any hacker can’t change its value and it’s used for
storing sensitive information such as database username, password etc.
● Since String is immutable, it’s safe to use in multi-threading and we don’t need any
synchronization.

Is it possible to provide method implementations in Java


Interfaces? If possible, how do we provide them?

In Java 7 or earlier, It is not possible to provide method implementations in Interfaces. Java


8 on-wards, it is possible.

In Java SE 8, We can provide method implementations in Interfaces by using the following


two new concepts:

● Default Methods
● Static Methods
What is a Default Method? Why do we need Default methods
in Java 8 Interfaces?

A Default Method is a method which is implemented in an interface with “default” keyword.


It’s new featured introduced in Java SE 8.

We need Default Methods because of the following reasons:

● It allow us to provide method’s implementation in Interfaces.


● To add new Functionality to Interface without breaking the Classes which implement
that Interface.
● To provide elegant Backwards Compatibility Feature.
● To ease of extend the existing Functionality.
● To ease of Maintain the existing Functionality.

What is a Static Method? Why do we need Static methods in


Java 8 Interfaces?

A Static Method is an Utility method or Helper method, which is associated to a class (or
interface). It is not associated to any object.

We need Static Methods because of the following reasons:

● We can keep Helper or Utility methods specific to an interface in the same interface
rather than in a separate Utility class.
● We do not need separate Utility Classes like Collections, Arrays etc to keep Utility
methods.
● Clear separation of Responsibilities. That is we do not need one Utility class to keep
all Utility methods of Collection API like Collections etc.
● Easy to extend the API.
● Easy to Maintain the API.
What is Hibernate Framework?

Object-relational mapping or ORM is the programming technique to map application


domain model objects to the relational database tables. Hibernate is java based
ORM tool that provides framework for mapping application domain objects to the
relational database tables and vice versa.

Hibernate provides reference implementation of Java Persistence API, that makes it a great
choice as ORM tool with benefits of loose coupling. We can use Hibernate
persistence API for CRUD operations. Hibernate framework provide option to map
plain old java objects to traditional database tables with the use of JPA annotations
as well as XML based configuration.

What are the important benefits of using Hibernate Framework?

Some of the important benefits of using hibernate framework are:

1. Hibernate eliminates all the boiler-plate code that comes with JDBC and takes care
of managing resources, so we can focus on business logic.
2. Hibernate framework provides support for XML as well as JPA annotations, that
makes our code implementation independent.
3. Hibernate provides a powerful query language (HQL) that is similar to SQL. However,
HQL is fully object-oriented and understands concepts like inheritance, polymorphism
and association.
4. Hibernate is an open source project from Red Hat Community and used worldwide.
This makes it a better choice than others because learning curve is small and there
are tons of online documentations and help is easily available in forums.
5. Hibernate is easy to integrate with other Java EE frameworks, it’s so popular that
Spring Framework provides built-in support for integrating hibernate with Spring
applications.
6. Hibernate supports lazy initialization using proxy objects and perform actual
database queries only when it’s required.
7. Hibernate cache helps us in getting better performance.
8. For database vendor specific feature, hibernate is suitable because we can also
execute native sql queries.
What is Lambda Expression?

Lambda Expression is an anonymous function which accepts a set of input parameters and
returns results.

Lambda Expression is a block of code without any name, with or without parameters and
with or without results. This block of code is executed on demand.

What is a REST service?


Rest stands for REpresentational State Transfer and it’s an architectural style for
developing web apps.
REST is a stateless client-server architecture where web services are resources that
can be identified by their URI’s.
REST doesn’t have a protocol defined but the main used one is over HTTP/S.
Compared to SOAP we don’t have a contract defined, it’s lightweight and we can use
XML, JSON, text or any data type for request and response.

What are advantages of REST web services?

Some of the advantages of REST web services are:

● Learning curve is easy since it works on HTTP protocol


● Supports multiple technologies for data transfer such as text, xml, json, image etc.
● No contract defined between server and client, so loosely coupled implementation.
● REST is a lightweight protocol
● REST methods can be tested easily over browser.

What are disadvantages of REST web services?

Some of the disadvantages of REST are:

● Since there is no contract defined between service and client, it has to be


communicated through other means such as documentation or emails.
● Since it works on HTTP, there can’t be asynchronous calls.
● Sessions can’t be maintained.

What is a Resource in Restful web services?


Resource is the fundamental concept of Restful architecture. A resource is an object
with a type, relationship with other resources and methods that operate on it. Resources are
identified with their URI, HTTP methods they support and request/response data type and
format of data.
Synchronous:

If an API call is synchronous, it means that code execution will block (or wait) for the
API call to return before continuing. This means that until a response is returned by the API,
your application will not execute any further, which could be perceived by the user as latency
or performance lag in your app. Making an API call synchronously can be beneficial,
however, if there if code in your app that will only execute properly once the API response is
received.

Asynchronous:

Asynchronous calls do not block (or wait) for the API call to return from the server.
Execution continues on in your program, and when the call returns from the server, a
"callback" function is executed.

S-ar putea să vă placă și