Wednesday, 24 May 2017

Overview of HTTP Request Methods

HTTP defines methods (sometimes referred to as verbs) to indicate the desired action to be performed on the identified resource. What this resource represents, whether pre-existing data or data that is generated dynamically, depends on the implementation of the server. Often, the resource corresponds to a file or the output of an executable residing on the server.

The HTTP/1.0 specification section  defined the GET, POST and HEAD methods and the HTTP/1.1 specification section  added 5 new methods: OPTIONS, PUT, DELETE, TRACE and CONNECT. By being specified in these documents their semantics are well known and can be depended upon. Any client can use any method and the server can be configured to support any combination of methods. If a method is unknown to an intermediate it will be treated as an unsafe and non-idempotent method

Requests a representation of the specified resource. Requests using GET should only retrieve data and should have no other effect.
Asks for the response identical to the one that would correspond to a GET request, but without the response body. This is useful for retrieving meta-information written in response headers, without having to transport the entire content.
Requests that the server accept the entity enclosed in the request as a new subordinate of the web resource identified by the URI. The data POSTed might be, as examples, an annotation for existing resources; a message for a bulletin board, newsgroup, mailing list, or comment thread; a block of data that is the result of submitting a web form to a data-handling process; or an item to add to a database
Requests that the enclosed entity be stored under the supplied URI. If the URI refers to an already existing resource, it is modified; if the URI does not point to an existing resource, then the server can create the resource with that URI.
Deletes the specified resource.
Echoes back the received request so that a client can see what (if any) changes or additions have been made by intermediate servers.
Returns the HTTP methods that the server supports for specified URL. This can be used to check the functionality of a web server by requesting '*' instead of a specific resource.
Converts the request connection to a transparent TCP/IP tunnel, usually to facilitate SSL-encrypted communication (HTTPS) through an unencrypted HTTP proxy.[14][15]
Is used to apply partial modifications to a resource.
HTTP servers are required to implement at least the GET and HEAD methods and, whenever possible, also the OPTIONS method.

Safe methods
Implementers should be aware that the software represents the user in their interactions over the Internet, and should be careful to allow the user to be aware of any actions they might take which may have an unexpected significance to themselves or others.
In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe". This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested.
Naturally, it is not possible to ensure that the server does not generate side-effects as a result of performing a GET request; in fact, some dynamic resources consider that a feature. The important distinction here is that the user did not request the side-effects, so therefore cannot be held accountable for them.

Idempotent methods
Methods can also have the property of "idempotence" in that (aside from error or expiration issues) the side-effects of N > 0 identical requests is the same as for a single request. The methods GET, HEAD, PUT and DELETE share this property. Also, the methods OPTIONS and TRACE SHOULD NOT have side effects, and so are inherently idempotent.
However, it is possible that a sequence of several requests is non- idempotent, even if all of the methods executed in that sequence are idempotent. (A sequence is idempotent if a single execution of the entire sequence always yields a result that is not changed by a reexecution of all, or part, of that sequence.) For example, a sequence is non-idempotent if its result depends on a value that is later modified in the same sequence.
A sequence that never has side effects is idempotent, by definition (provided that no concurrent operations are being executed on the same set of resources).

Persistent connections
In HTTP/0.9 and 1.0, the connection is closed after a single request/response pair. In HTTP/1.1 a keep-alive-mechanism was introduced, where a connection could be reused for more than one request. Such persistent connections reduce request latency perceptibly, because the client does not need to re-negotiate the TCP connection after the first request has been sent. Another positive side effect is that in general the connection becomes faster with time due to TCP's slow-start-mechanism.
Version 1.1 of the protocol also made bandwidth optimization improvements to HTTP/1.0. For example, HTTP/1.1 introduced chunked transfer encoding to allow content on persistent connections to be streamed rather than buffered. HTTP pipelining further reduces lag time, allowing clients to send multiple requests before waiting for each response. Another improvement to the protocol was byte serving, where a server transmits just the portion of a resource explicitly requested by a client.

Enjoy Learning.

HTTP Status Codes & Messages

This is a list of HTTP status messages that might be returned when a browser requests a service from a web server.
100 Continue
The server has received the request headers, and the client should proceed to send the request body
101 Switching Protocols
The requester has asked the server to switch protocols
103 Checkpoint
Used in the resumable requests proposal to resume aborted PUT or POST requests
200 OK
The request is OK (this is the standard response for successful HTTP requests)
201 Created
The request has been fulfilled, and a new resource is created 
202 Accepted
The request has been accepted for processing, but the processing has not been completed
203 Non-Authoritative Information
The request has been successfully processed, but is returning information that may be from another source
204 No Content
The request has been successfully processed, but is not returning any content
205 Reset Content
The request has been successfully processed, but is not returning any content, and requires that the requester reset the document view
206 Partial Content
The server is delivering only part of the resource due to a range header sent by the client
300 Multiple Choices
A link list. The user can select a link and go to that location. Maximum five addresses  
301 Moved Permanently
The requested page has moved to a new URL 
302 Found
The requested page has moved temporarily to a new URL 
303 See Other
The requested page can be found under a different URL
304 Not Modified
Indicates the requested page has not been modified since last requested
306 Switch Proxy
No longer used
307 Temporary Redirect
The requested page has moved temporarily to a new URL
308 Resume Incomplete
Used in the resumable requests proposal to resume aborted PUT or POST requests
4xx:Client Error
400 Bad Request
The request cannot be fulfilled due to bad syntax
401 Unauthorized
The request was a legal request, but the server is refusing to respond to it. For use when authentication is possible but has failed or not yet been provided
402 Payment Required
Reserved for future use
403 Forbidden
The request was a legal request, but the server is refusing to respond to it
404 Not Found
The requested page could not be found but may be available again in the future
405 Method Not Allowed
A request was made of a page using a request method not supported by that page
406 Not Acceptable
The server can only generate a response that is not accepted by the client
407 Proxy Authentication Required
The client must first authenticate itself with the proxy
408 Request Timeout
The server timed out waiting for the request
409 Conflict
The request could not be completed because of a conflict in the request
410 Gone
The requested page is no longer available
411 Length Required
The "Content-Length" is not defined. The server will not accept the request without it 
412 Precondition Failed
The precondition given in the request evaluated to false by the server
413 Request Entity Too Large
The server will not accept the request, because the request entity is too large
414 Request-URI Too Long
The server will not accept the request, because the URL is too long. Occurs when you convert a POST request to a GET request with a long query information 
415 Unsupported Media Type
The server will not accept the request, because the media type is not supported 
416 Requested Range Not Satisfiable
The client has asked for a portion of the file, but the server cannot supply that portion
417 Expectation Failed
The server cannot meet the requirements of the Expect request-header field
5xx:Server Error
500 Internal Server Error
A generic error message, given when no more specific message is suitable
501 Not Implemented
The server either does not recognize the request method, or it lacks the ability to fulfill the request
502 Bad Gateway
The server was acting as a gateway or proxy and received an invalid response from the upstream server
503 Service Unavailable
The server is currently unavailable (overloaded or down)
504 Gateway Timeout
The server was acting as a gateway or proxy and did not receive a timely response from the upstream server
505 HTTP Version Not Supported
The server does not support the HTTP protocol version used in the request
511 Network Authentication Required
The client needs to authenticate to gain network access
Enjoy Learning.

UNIX Useful Commands

Files and Directories:

These commands allow you to create directories and handle files.
Display File Contents
Changes Directory to dirname
change file group
Changing Permissions
Copy source file into destination
Determine file type
Find files
Search files for regular expressions.
Display first few lines of a file
Create softlink on oldname
Display information about file type.
Create a new directory dirname
Display data in paginated form.
Move (Rename) a oldname to newname.
Print current working directory.
Remove (Delete) filename
Delete an existing directory provided it is empty.
Prints last few lines in a file.
Update access and modification time of a file.

Manipulating data:

The contents of files can be compared and altered with the following commands.
Pattern scanning and processing language
Compare the contents of two files
Compare sorted data
Cut out selected fields of each line of a file
Differential file comparator
Expand tabs to spaces
Join files on some common field
Data manipulation language
Stream text editor
Sort file data
Split file into smaller files
Translate characters
Report repeated lines in a file
Count words, lines, and characters
Opens vi text editor
Opens vim text editor
Simple text formatter
Check text for spelling error
Check text for spelling error
Check text for spelling error
GNU project Emacs
ex, edit
Line editor
GNU project Emacs
GNU project Emacs

Compressed Files:

Files may be compressed to save space. Compressed files can be created and examined:
Compress files
Uncompress gzipped files
GNU alternative compression method
Uncompress files
List, test and extract compressed files in a ZIP archive
Cat a compressed file
Compare compressed files
Compare compressed files
File perusal filter for crt viewing of compressed text

Getting Information:

Various Unix manuals and documentation are available on-line. The following Shell commands give information:
Locate commands by keyword lookup
Displays command information pages online
Displays manual pages online
Search the whatis database for complete words.
GNOME help viewer

Network Communication:

These following commands are used to send and receive files from a local UNIX hosts to the remote host around the world.
File transfer program
Remote file copy
Remote login to a UNIX host
Remote shell
Trivial file transfer program
Make terminal connection to another host
Secure shell terminal or command connection
Secure shell remote file copy
secure shell file transfer program
Some of these commands may be restricted at your computer for security reasons.

Misc Commands:

These commands list or alter information about the system:
Change your finger information
Change the group ownership of a file
Change owner
Print the date
Automatically find terminal type
Print amount of disk usage
Echo arguments to the standard options
Quit the system
Print information about logged-in users
Create a user group
Show group memberships
Show quota and file usage
Report I/O statistics
Send a signal to a process
Show last logins of users
log off UNIX
List user names or login ID
Show network status
Change user password
Change your login password
Display value of a shell variable
Display the status of current processes
Print process status statistics
quota -v
Display disk usage and limits
Reset terminal mode
Keep script of terminal session
Save the output of a command or process
Set environment variables
Set terminal options
Time a command
Display all system processes
Set terminal mode
Print current terminal name
Show the permissions that are given to view files by default
Display name of the current system
Get the system up time
Create a user account
Print names of logged in users
Report virtual memory statistics
Show what logged in users are doing
List logged in users
Enjoy Learning.

Java program to create singleton class

Java Singleton design pattern is one of the design patterns that manages the instantiation of an object
This design pattern suggests that only one instance of a Singleton object is created by the JVM.
This pattern is useful when exactly one object is needed to coordinate actions across the system.

For example, you can use it to create a connection pool. It’s not good to create a new connection every time a program needs to write something to a database; instead, a connection
or a set of connections that are already a pool can be instantiated using the Singleton pattern.

Example Class that follows Singleton Pattern.

public class SingletonExample {  
   private static SingletonExample INSTANCE = new SingletonExample ();  
   //Marking default constructor private;  
   //to avoid direct instantiation.  
   private SingletonExample () {  
   //Get instance for class SingletonExample  
   public static SingletonExample getInstance() {  
    return INSTANCE;  

In above code snippet, we have declared a static object reference to SingletonExample class called INSTANCE and is returned every time getInstance() is called.

  • In in a multi-threaded environment ,sometimes when two or more threads enter the method getInstance() at the same time before Singleton instance is not created, will result into simultaneous creation of two objects.

Such problems can be avoided by defining getInstance() method synchronized.

public static synchronized SingletonExample getInstance() { }  

Enjoy Learning.

Important SDET(Software Development Engineer Testing) Interview Question

                  Important SDET(Software Development Engineer Testing) Interview Question

  1. Explain life cycle of a bug
  2. What is regression testing? How is it different from functional testing?
  3. Difference between whitebox and black box testing
  4. What is A/B testing?
  5. What is smoke testing? Difference with Sanity testing?
  6. How can we perform credit card authorization testing?
  7. How do we test a multi channel application? Especially when the integration points are not in place with downstream systems?
  8. What is end to end testing?
  9. How can we test a webservice?
  10. How can we form a request in Jmeter, hit a service and read the response?
  11. Difference between unit, integration and QA testing
  12. What is included in a test plan?
  13. what is boundary analysis with an example
  14. What is negative testing? Create 5 negative  test cases for email validation
  15. What is backend testing?
  16. How do you perform XML validation?
  17. What are the basic elements you put down while reporting a bug?
  18. Create 5 test cases for placing an order in an ecommerce website using PayPal as payment type
  19. Write 5 P1 test cases for shopping cart on an ecom website.
  20. Write 5 P1 testcases for a user profile page on an ecom website.
  21. Write 5 P1 test cases for a Ship confirmation email sent from an ecom website to a customer
  1. What are the different types of apps ?
  2. What is the difference between Native and Hybrid app
  3. How can app be installed on IOS devices?
  4. What are the app formats for IOS and Android
  5. What is the difference between Desktop and mobile testing
  6. How to install local IOS and Android builds to device
  7. Mention what are the common bugs found while mobile testing
  8. What is the approach to test different screen size
  9. What is the approach to test different device/OS version
DB (Exact queries are not needed in answers. A high level approach will do)
  1. In an EMPLOYEE table having EMPLOYEE ID and DEPT ID, find department with max employees
  2. CASE..WHEN..THEN statement in SQL
  3. Write a query to find salary of an employee using join between EMPLOYEE and SALARY tables
  4. Difference between innerjoin and outerjoin
  5. PL/SQL – high level
  6. Explain trigger and its difference between a PL/SQL
  7. Nosql vs RDBMS, with an example
  8. Is it possible to have primary key and foreign key in mongo db
  9. How to find data in a mongodb collection
  10. Find state with max stores in a STORES table (with the columns - store id, storename, city, state, zip)
  11. How to ensure that child records are deleted when parent with foreign key constraint is deleted
  12. Difference between truncating and deleting a table
  13. Query to find number of records in a table
  14. Possible to have more than one column as primary key?
  15. Difference between WHERE and HAVING clauses
  16. What is difference between count(1) and count(*).
  17. Find number of non-null records in a column
  18. Find number of null records in a column

UNIX (exact syntaxes are not required. Keywords would be enough)
  1. Unix commands for :
    1. changing directories
    2. listing files
    3. finding keywords in a file
    4. changing file permissions
    5. tailing
    6. Create a shell script to display a menu to a user
    7. Get current directory
    8. Find keyword in a file
    9. List files starting with the word Sears in a directory
    10. Find wordcount in a file
    11. Schedule a shell script to run every 30 seconds
    12. How to connect to a unix server from another unix server
    13. Difference between ftp and scp
    14. How to find a string from a set of files?
    15. How to find files which are modified 15 mins before?
    16. How to list all running processes in a server and stop it?
    17. Finding file names which start with the letter A in a directory
  1. How to convert json to a hashmap
  2. Explain how to implement multi-threading
  3. Explain race condition and how to avoid it
  4. Diff between string, string buffer and string builder
  5. Difference between hashmap, hashtable, concurrent hashmap and treemap
  6. Possible to have duplicate key in a hashmap? Explain
  7. Execute a query and get the results of the query into a hashmap with column names as the keys and column values as the values
  8. Explain class casting
  9. Explain polymorphism and encapsulaiton
  10. Sort an arraylist
  11. Sort a map with integer as keys and string as values based on length of its values
  12. Difference between abstract class and interface
  13. Difference between final, finalize and finally
  14. What happens when a line of code in finally block has an exception?
  15. What is an iterator? Where can it be used?
  16. What is a Set? How is it different from arraylist?
  17. Mail contents of a file using java
  18. How is hashmap different from an array list?
  19. Difference between hashmap and treemap?
  20. How would you read a file and write to a new file?
  21. Explain try-catch logic?
  22. What is Finally block? You are executing a try block, with no exceptions. Will it go to finally?
  23. Why do we need getters and setters?
  24. How to iterate through a hashmap
  25. How to find common elements between 2 array lists

  1. How to handle popups in selenium?
  2. What is Page Object Model (POM) & Page Factory in Selenium?
  3. What are the differenttypes of wait and when to use what?
  4. What are the operating systems and browsers supported by Selenium?
  5. What is the default port for Selenium and can it be customized?
  6. What is the use of Capabilities class?
  7. What is the difference between Remote Webdriver and Webdriver?
  8. How to use JavaScript with Selenium WebDriver using Java?
  9. What is the diffrence between assert and verify?
  10. What are the different types of locators in Selenium and which one is preferred?
  1. Open file containing alphanumeric phone numbers, convert them to numbers ((eg: 1-800-GO-PIZZA to 18004674992)and write them to a different text file
  2. Find difference between two text files which have data similar in structure
  3. You have Order Items table and orders table. Orderitems table could have many records for an order. How to find the orders that have exactly 2 items in them? OrderId is the foreign key in orderitems table.
  4. Find duplicate numbers in a Textfile with 20000 six digit numbers. On finding duplicates, write them in another textfile with number of occurances.
  5. Find missing number from an array that is supposed to contain 1-100 numbers
  1. Difference between RESTful service and SOAP service
  2. Schedule an executable jar to run every 30 seconds in a Windows server
  3. Using regular expession, find $ amount in a string which appears after the $ character
  4. What is continuous integration?
  5. Convert xml to json?

Important Java Interview Questions

                                                      Important Java Interview Questions

What is JVM ? Why is Java platform independent ?
What is the Difference between JDK and JRE ?
What are dynamic binding (run-time) and static binding (compile-time) ?
Can you override private or static method in Java ?
What is Autoboxing and Unboxing ?
What is the difference between an Interface and an Abstract class ?
What are pass by reference and pass by value ?
What is the difference between a synchronized method (coarse grained lock) and a synchronized block (fine grained lock) ?
Why Collection doesn’t extend Cloneable and Serializable interfaces ?
What is difference between fail-fast and fail-safe ?
What is the big-O notation?
What do System.gc() and Runtime.gc() methods do ?
What is difference amoung finally, final and finalize() ?
What is the difference between JDBC and JPA ?
Java Design Patterns:
What is design patterns ? Have you used any design pattern in your code ?
Can you name few design patterns used in standard JDK library?
Give an example where you prefer abstract class over interface ?
What is Singleton design pattern in Java ? Few issues and solutions in singleton (thread-safe)?
When to use Strategy Design Pattern in Java?
What is Observer design pattern in Java? When do you use Observer pattern in Java?
Difference between Strategy and State design Pattern in Java?
What is main benefit of using factory pattern ? Where do you use it?
What is MVC design pattern ? Give one example of MVC design pattern ?
What is Chain of Responsibility design pattern ?
What is Builder design pattern in Java? When do you use Builder pattern ?
What is Adapter design pattern ? Give examples of adapter design pattern in Java?
Difference between Decorator and Proxy pattern in Java?
Can you write code to implement producer consumer design pattern in Java?
Design a Vending Machine which can accept different coins, deliver different products?
What is different between web server and application server?
What is the difference between a Servlet and a JSP ?
What are the advantages of servlets over CGI?
What are servlets filters?
What is difference between ServletConfig and ServletContext?
How can we achieve transport layer security for our web application?
Are Servlets Thread Safe? How to achieve thread safety in servlets?
What are common tasks performed by Servlet Container?
What is the difference between Applet, Servlet and Scriptlet ?
What is the difference between session and cookie ?
Explain lifecycle of a JSP?
What is a sciptlet in JSP and what is its syntax?
What do the id and scope attribute mean in the action elements?
What is the difference between JspWriter and PrintWriter?
How is Session Management done in JSP?
What are the JSP implicit objects ?
How do you implement the auto refresh in JSP?
How to disable caching on back button of the browser?
In JSP page, how can we handle runtime exception?
What is the difference between ServletContext and PageContext?
Web Service:
What is the difference between SOAP (JAX-WS) and REST (JAX-RS) web services?
How would you decide what style of Web Service to use? SOAP or REST?
Which JAX-RS implementation did you use (Jersey, RESTEasy, Restlet, Spring)?
What is the difference between web service and API?
Differentiate between SOA (Service Oriented Architecture) versus WOA (Web Oriented Architecture)?
What tools do you use to test your Web Services?
What is the difference between SOA and a Web service?
Why not favor traditional style middle-ware such as RPC, CORBA, RMI and DCOM as opposed to Web services?
What are the types of information included in SOAP header?
How can you explain HTTP Binding in SOAP ?
As per JAX-RS recommentation, what and where will you use GET, POST, PUT, DELETE methods?
What is Spring? What are benefits of Spring framework?
Which are the Spring framework modules?
What is Inversion of Control (IoC) and Dependency Injection?
What is the difference between BeanFactory and ApplicationContext?
In how many ways, you can configure Spring into our application?
Explain Spring Bean lifecycle?
What are different Spring Bean Scopes?
Difference between constructor injection and setter injection?
Name some of the design patterns used in Spring Framework?
What is bean auto wiring?
What are the JSR-250 Annotations? Explain them?
Explain AOP in terms of cross-cutting Concern, Join Point, Advice...?
What are differnt data access implementations (JDBC, JPA, Data)?
Explain @RequestMapping annotation?
Explain Directives in Angular?
Do I need Jquery for Angular?
How is the data binding in Angular ?
What is “$rootScope” and how is it related with “$scope”?
Explain compile and link phase?
What is the difference between Factory and Service?
How to implement routing in Angular?
What are the different custom directive types in AngularJS?
How do we make HTTP get and post calls in Angular?
Explain the differences between Java and JavaScript?
What are undeclared and undefined variables?
What is ‘this’ keyword in JavaScript?
Does JavaScript support automatic type conversion?
What is called Variable typing in Javascript?
Explain the difference between “==” and “===”?
What are the different types of errors in JavaScript?
What is the difference between .call() and .apply()?
How are JavaScript and ECMA Script related?
How do JavaScript timers work? What is a drawback of JavaScript timers?
Whether jQuery HTML work for both HTML and XML documents?
Difference between ID selector and class selector in jQuery?
What is $(document).ready() function? Why should you use it?
What is the difference between onload() and document.ready()?
How do you add an HTML element in DOM tree?
Difference between $(this) and this keyword in jQuery?
What is difference between detach() and remove() method in jQuery?
What is main advantage of loading jQuery library using CDN?
What is difference between jQuery.get() and jQuery.ajax() method?
What is method chaining in jQuery? what is benefit of using method chaining?
Which one is more efficient, document.getElementbyId( "myId") or $("#myId)?
What is jQuery connect?
How can we debug jQuery?
What is the use of method?
Where jQuery code is getting executed?
Performance Tuning:
How would you improve performance of a Java application?
How do you tune database performance?
How would you refresh your cache?
How would you refresh your cache if your database is shared by more than one application?
How would you detect and minimize memory leaks in Java?
Why does the JVM crash with a core dump or a Dr.Watson error?
What is structure of Java Heap ? What is Perm Gen space in Heap ?
How do you identify minor and major garbage collection in Java?
What is difference between ParNew and DefNew Young Generation Garbage collector?
How do you find GC resulted due to calling System.gc()?
What is difference between Serial and Throughput Garbage collector?
When does an Object becomes eligible for Garbage collection in Java ?
What is finalize method in Java ? When does Garbage collector calls finalize method in Java ?
Can we force Garbage collector to run at any time ?
Does Garbage collection occur in permanent generation space in JVM?
How to you monitor garbage collection activities?
What are some indications that you need to increase the SHARED_POOL_SIZE parameter?
When looking at v$sysstat you see that sorts (disk) is high. Is this bad or good? If bad, how do you correct it?
When should you increase copy latches? What parameters control copy latches?

Enjoy Learning:)