Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

The purpose of each of the HTTP request types when used with a

RESTful web service is as follows:

1. GET: Retrieves data from the server (should only retrieve data and
should have no other effect).
2. POST: Sends data to the server for a new entity. It is often used
when uploading a file or submitting a completed web form.
3. PUT: Similar to POST, but used to replace an existing entity.
4. PATCH: Similar to PUT, but used to update only certain fields
within an existing entity.
5. DELETE: Removes data from the server.
6. TRACE: Provides a means to test what a machine along the
network path receives when a request is made. As such, it simply returns
what was sent.
7. OPTIONS: Allows a client to request information about the request
methods supported by a service. The relevant response header is Allow
and it simply lists the supported methods. (It can also be used to request
information about the request methods supported for the server where the
service resides by using a * wildcard in the URI.)
8. HEAD: Same as the GET method for a resource, but returns only
the response headers (i.e., with no entity-body).
9. CONNECT: Primarily used to establish a network connection to a
resource (usually via some proxy that can be requested to forward an
HTTP request as TCP and maintain the connection). Once established, the
response sends a 200 status code and a “Connection Established”
message.
10. A stateless communications protocol treats each request as an
independent transaction. It therefore does not require the server to retain
any session, identity, or status information spanning multiple requests from
the same source. Similarly, the requestor can not rely on any such
information being retained by the responder.
11. In contrast, a stateful communications protocol is one in which the
responder maintains “state” information (session data, identity, status, etc.)
across multiple requests from the same source.
12. HTTP is a stateless protocol. HTTP does not require server to
retain information or status about each user for the duration of multiple
requests.
13. Some web servers implement states using different methods (using
cookies, custom headers, hidden form fields etc.). However, in the very
core of every web application everything relies on HTTP which is still a
stateless protocol that is based on simple request/response paradigm.
Both are methods used in HTTP requests. Generally it is said that GET
is to download data and PUT is to upload data. But we can do both
downloading as well as uploading either by GET/POST.

GET:

1. If we are sending parameters in a GET request to the server, then


those parameters will be visible in the URL, because in GET, parameters
are append to the URL. So there’s a lack of security while uploading to the
server.
2. We can only send a limited amount of data in a GET request,
because the URL has its max limit and we can not append a long data
string to the URL.

POST:

1. If we are using POST then we are sending parameters in the body


section of a request. If we send data after using encryption in the body of
an http request, it’s quite a bit more secure.
2. We can send a lot more data using POST.
Note: GET is faster in the case of just getting data using a static API call
in cases where we don’t have to pass any parameters.
Basic Java Interview Question and Answers
1. What is Java?
 Java is an object programming language that was
designed to be portable across multiple platforms and operating
systems.
 Developed by Sun Microsystems, Java is modeled after
the C++ programming language and includes special features that
make it ideal for programs on the Internet.

2. What is Hot Java?


 Hot Java was the first Web browser that could download
and play (execute) Java applets.
 Hot Java, created by Sun, is simply a browser, much like
the Netscape Navigator or Microsoft's Internet Exploere.
 Although Hot Java was the first browser to support Java
applets, many browsers now support or will soon support applets.
 Starting with Netscape Navigator 2.0 for example, you
can play Java applets for many platforms (Windows 95, the Mac
and so on.).
 Another distinguishing feature of Hot Java is that unlike
most browsers which are written in C/C++.
 Hot Java browser is written with the Java programming
language.

3. What is static in Java?


 Static means one per class, not one for each object no
matter how many instance of a class might exist. This means that
you can use them without creating an instance of a class.
 Static methods are implicitly final, because overriding is
done based on the type of the object and static methods are
attached to a class, not an object.
 A static method in a superclass can be shadowed by
another static method in a sub class, as long as the original
method was not declared final.
 However, you can't override a static method with a non
static method. In other words, you can't change a static method
into an instance method of a subclass.

4. What is a Java Virtual Machine?


 A Java Virtual Machine is a runtime environment required
for execution of a Java application.
 Each Java application runs inside a runtime instance of
some concrete implementation of abstract specifications of JVM.
 It is JVM which is crux of platform independent nature of
the language
5. Why Java does not support multiple inheritances?
Java design team stroke to make Java as
 Simple, object oriented and familiar
 Robust and secure
 Architecture neutral and portable
 High performance
 Interpreted, threaded and dynamic
 The reasons for omitting Multiple Inheritance from the
Java Language mostly stem from the simple, object oriented and
familiar goal.
 DISCUSS
6. How many types of inheritances does Java support?
Yes, Ok but, basically there are two types of Inheritances are
there, they are
 Single Inheritance
 Multiple Inheritances
And some other Inheritances are there those are
 Multi level
 Hierarchical
 Hybrid and
 Java supports only Single Inheritance only.
 DISCUSS
7. Why java does not support pointers?
Because pointers are unsafe, Java uses reference types to hide
pointer and programmers feel easier to deal with reference types
without pointers.
 DISCUSS
8. What is a platform?
 A platform is the hardware or software environment in which a
program runs.
 Most platforms can be described as a combination of the
operating system and hardware, like Windows 2000/XP, Linux, Solaris
and MacOs.

46. When is a method said to be overloaded and when is a


method said to be overridden?
Overloading deals with multiple methods in the same class with
the same name but different method signatures.
Overriding deals with two methods, one in the parent class and
the other one in the child class and has the same name and
signatures.
 DISCUSS
47. How is final different from finally and finalize()?
 Final - constant declaration.
 The finally block always executes when the try block
exits, except System.exit(0) call.
 finalize() is a method of Object class which will be
executed by the JVM just before garbage collecting object to give
a final chance for resource releasing activity.
 DISCUSS
48. What is Byte Code?
All Java programs are compiled into class files that contain
bytecodes. These byte codes can be run in any platform and
hence java is said to be platform independent.
 DISCUSS
49. What is the difference between error and an exception?
Exception means When a method encounters an abnormal
condition (an exception condition) that it can’t handle itself, it
may throw an exception.
ssError mens system doesn’t handle.For example:Overflow,Out of
memory.
 DISCUSS
50. What if the main method is declared as private?
When a method is declared as private, the program compiles
properly but it will give runtime error Main method not “public„.

56. What is the difference between java and c++?


 Java is a true object - oriented language while c++ is
basically c with object-oriented extension.
 C++ supports multiple inheritence but Java provides
interfaces in case of multiple inheritence.
 Java does not support operator overloading.
 Java does not have template classes as in c++.
 java does not use pointers.
55. What is the difference between static and non-static
variables?
A static variable is associated with the class as a whole rather
than with specific instances of a class.
Non-static variables take on unique values with each object instance.
46. When is a method said to be overloaded and when is a
method said to be overridden?
Overloading deals with multiple methods in the same class with
the same name but different method signatures.
Overriding deals with two methods, one in the parent class and the
other one in the child class and has the same name and signatures.

49. What is the difference between error and an exception?


Exception means When a method encounters an abnormal
condition (an exception condition) that it can’t handle itself, it may
throw an exception.
ssError mens system doesn’t handle.For example:Overflow,Out of
memory.

41. What is the difference between method overriding and


overloading?
Overriding is a method with the same name and arguments as in
a parent, whereas overloading is the same method name but
different arguments.
 DISCUSS
42. What do you mean by polymorphism?
Polymorphism means the ability to take more than one form. fro
example, an operation may exhibit behaviour in different
instances. The behaviour depends upon the types of data used in
the operatiom.
 DISCUSS
43 What is the difference between an abstract class and an
interface?
Abstract class Interface - Have executable methods and abstract
methods.Can only subclass one abstract class
Interface - Have no implementation code. All methods are
abstract.A class can implement any number of interfaces.
 DISCUSS
44. What is the purpose of finalization?
The purpose of finalization is to give an unreachable object the
opportunity to perform any cleanup processing before the object
is garbage collected.
 DISCUSS
45. What is the difference between a break statement and a
continue statement?
Break statement results in the termination of the statement to
which it applies (switch, for, do, or while).
A Continue statement is used to end the current loop iteration and
return control to the loop statement.
35. What is the difference between a while statement and a do
while statement?
A while statement checks at the beginning of a loop to see
whether the next loop iteration should occur. A do while
statement checks at the end of a loop to see whether the next
iteration of a loop should occur. The do whilestatement will always
execute the body of a loop at least once.
28 What is the difference between an interface and an
abstract class?
An abstract class may contain code in method bodies, which is not
allowed in an interface. With abstract classes, you have to inherit
your class from it and Java does not allow multiple inheritance.
On the other hand, you can implement multiple interfaces in your
class.
16. What is an array?
Array is a group of related data items that share a common
name.For instance, we can define an array name salary to
represent a set of salaries of a group of employees.
Examples : salary[10]
9. What is serialization?
Serialization is the process of converting a objects into a stream
of bytes.
10. What are different types of access modifiers?
Access specifiers are keywords that determine the type of access
to the member a class.

 Public
 Protected
 Private
 Default
10. What is the difference between public, static and void?
 public :The keyword public is an access modifier that tells the C#
compiler that the Main method is accessible by anyone.
 static :The keyword static declares that the Main method is a
global one and can be called without creating an instance of the
class. The compiler stores the address of the method as the entry
point and uses this information to begin execution before any
objects are created.
 void : The keyword void is a type modifier that states that the
Main method does not return any value.

16. What is the difference between Object and Instance?


An instance of a user-defined type is called an object. We can
instantiate many objects from one class.
An object is an instance of a class.
 DISCUSS
17. Define destructors?
A destructor is called for a class object when that object passes
out of scope or is explicitly deleted.A destructors as the name
implies is used to destroy the objects that have been created
by a constructors.Like a constructor , the destructor is a
member function whose name is the same as the class name
but is precided by a tilde.
 DISCUSS
18. What is the use of enumerated data type?
An enumerated data type is another user defined type which
provides a way for attaching names to numbers thereby
increasing comprehensibility of the code. The enum keyword
automatically enumerates a list of words by assigning them
values 0,1,2, and so on.
 DISCUSS
19. Define Constructors?
A constructor is a member function with the same name as its
class. The constructor is invoked whenever an object of its
associated class is created.It is called constructor because it
constructs the values of data members of the class.
 DISCUSS
20. What is encapsulation?
The wrapping up of data and functions into a single unit (called
class) is known as encapsulation. Encapsulation containing and
hiding information about an object, such as internal data
structures and code.

OOPs in Java: Encapsulation,


Inheritance, Polymorphism, Abstraction
BY CHAITANYA SINGH | FILED UNDER: OOPS CONCEPT

In the last article we discussed OOPs Concepts. If you have not yet
checked it out, I would highly recommend you to read it so that you have
a basic overview of all the Object Oriented Programming Concepts. In
this guide, we will discuss four important features of OOPs with the help
of real life examples.

Object Oriented Approach : An Introduction


Java is an object oriented language because it provides the features to
implement an object oriented model. These features
includes Abstraction, encapsulation, inheritance and polymorphism.

OOPS is about developing an application around its data, i.e. objects


which provides the access to their properties and the possible operations
in their own way.
Abstraction
One of the most fundamental concept of OOPs is Abstraction.
Abstraction is a process where you show only “relevant” data and “hide”
unnecessary details of an object from the user. For example, when you
login to your Amazon account online, you enter your user_id and
password and press login, what happens when you press login, how the
input data sent to amazon server, how it gets verified is all abstracted
away from the you.

Another example of abstraction: A car in itself is a well-defined object,


which is composed of several other smaller objects like a gearing
system, steering mechanism, engine, which are again have their own
subsystems. But for humans car is a one single object, which can be
managed by the help of its subsystems, even if their inner details are
unknown.

Encapsulation
This post provides the theoretical explanation of Encapsulation with real-
life examples. For detailed explanation on this topic with java programs
refer encapsulation in java with example.

Encapsulation is:

 Binding the data with the code that manipulates it.


 It keeps the data and the code safe from external interference

Looking at the example of a power steering mechanism of a car. Power


steering of a car is a complex system, which internally have lots of
components tightly coupled together, they work synchronously to turn
the car in the desired direction. It even controls the power delivered by
the engine to the steering wheel. But to the external world there is only
one interface is available and rest of the complexity is hidden. Moreover,
the steering unit in itself is complete and independent. It does not affect
the functioning of any other mechanism.

Similarly, same concept of encapsulation can be applied to code.


Encapsulated code should have following characteristics:
 Everyone knows how to access it.
 Can be easily used regardless of implementation details.
 There shouldn’t any side effects of the code, to the rest of the
application.

The idea of encapsulation is to keep classes separated and prevent


them from having tightly coupled with each other.

A example of encapsulation is the class of java.util.Hashtable. User only


knows that he can store data in the form of key/value pair in a Hashtable
and that he can retrieve that data in the various ways. But the actual
implementation like, how and where this data is actually stored, is hidden
from the user. User can simply use Hashtable wherever he wants to
store Key/Value pairs without bothering about its implementation.

Inheritance
This post provides the theoretical explanation of inheritance with real-life
examples. For detailed explanation on this topic with java programs
refer inheritance with examples and types of inheritance in java.

 Inheritance is the mechanism by which an object acquires the


some/all properties of another object.
 It supports the concept of hierarchical classification.

For example: Car is a four wheeler vehicle so assume that we have a


class FourWheeler and a sub class of it named Car. Here Car acquires
the properties of a class FourWheeler. Other classifications could be a jeep,
tempo, van etc. FourWheeler defines a class of vehicles that have four
wheels, and specific range of engine power, load carrying capacity etc.
Car (termed as a sub-class) acquires these properties from
FourWheeler, and has some specific properties, which are different from
other classifications of FourWheeler, such as luxury, comfort, shape,
size, usage etc.

A car can have further classification such as an open car, small car, big
car etc, which will acquire the properties from both Four Wheeler and
Car, but will still have some specific properties. This way the level of
hierarchy can be extended to any level.
Java Swing and Awt classes represent best examples for inheritance.

Polymorphism
This post provides the theoretical explanation of polymorphism with real-
life examples. For detailed explanation on this topic with java programs
refer polymorphism in java and runtime & compile time polymorphism.

 Polymorphism means to process objects differently based on their


data type.
 In other words it means, one method with multiple implementation,
for a certain class of action. And which implementation to be used
is decided at runtime depending upon the situation (i.e., data type
of the object)
 This can be implemented by designing a generic interface, which
provides generic methods for a certain class of action and there
can be multiple classes, which provides the implementation of
these generic methods.

Lets us look at same example of a car. A car have a gear transmission


system. It has four front gears and one backward gear. When the engine
is accelerated then depending upon which gear is engaged different
amount power and movement is delivered to the car. The action is same
applying gear but based on the type of gear the action behaves
differently or you can say that it shows many forms (polymorphism
means many forms)

Polymorphism could be static and dynamic both. Method Overloading is


static polymorphism while, Method overriding is dynamic polymorphism.

 Overloading in simple words means more than one method having


the same method name that behaves differently based on the
arguments passed while calling the method. This called static
because, which method to be invoked is decided at the time of
compilation
 Overriding means a derived class is implementing a method of its
super class. The call to overriden method is resolved at runtime,
thus called runtime polymorphism
Exception handling in java with examples
BY CHAITANYA SINGH | FILED UNDER: EXCEPTION HANDLING

Exception handling is one of the most important feature of java


programming that allows us to handle the runtime errors caused by
exceptions. In this guide, we will learn what is an exception, types of it,
exception classes and how to handle exceptions in java with examples.

What is an exception?
An Exception is an unwanted event that interrupts the normal flow of the
program. When an exception occurs program execution gets terminated.
In such cases we get a system generated error message. The good
thing about exceptions is that they can be handled in Java. By handling
the exceptions we can provide a meaningful message to the user about
the issue rather than a system generated message, which may not be
understandable to a user.

Why an exception occurs?


There can be several reasons that can cause a program to throw
exception. For example: Opening a non-existing file in your program,
Network connection problem, bad input data provided by user etc.

Exception Handling
If an exception occurs, which has not been handled by programmer then
program execution gets terminated and a system generated error
message is shown to the user. For example look at the system
generated exception below:
An exception generated by the system is given below

Exception in thread "main" java.lang.ArithmeticException: / by zero at


ExceptionDemo.main(ExceptionDemo.java:5)
ExceptionDemo : The class name
main : The method name
ExceptionDemo.java : The filename
java:5 : Line number
This message is not user friendly so a user will not be able to understand
what went wrong. In order to let them know the reason in simple
language, we handle exceptions. We handle such conditions and then
prints a user friendly warning message to user, which lets them correct
the error as most of the time exception occurs due to bad data provided
by user.

Advantage of exception handling


Exception handling ensures that the flow of the program doesn’t break
when an exception occurs. For example, if a program has bunch of
statements and an exception occurs mid way after executing certain
statements then the statements after the exception will not execute and
the program will terminate abruptly.
By handling we make sure that all the statements execute and the flow
of program doesn’t break.

Difference between error and exception


Errors indicate that something severe enough has gone wrong, the
application should crash rather than try to handle the error.

Exceptions are events that occurs in the code. A programmer can


handle such conditions and take necessary corrective actions. Few
examples:
NullPointerException – When you try to use a reference that points to
null.
ArithmeticException – When bad data is provided by user, for example,
when you try to divide a number by zero this exception occurs because
dividing a number by zero is undefined.
ArrayIndexOutOfBoundsException – When you try to access the
elements of an array out of its bounds, for example array size is 5 (which
means it has five elements) and you are trying to access the 10th
element.

You might also like