Skip to content

Commit f69af2b

Browse files
committed
add new file
1 parent b7830f8 commit f69af2b

6 files changed

Lines changed: 179 additions & 6 deletions

File tree

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
Java Servlets
22
---
33

4-
1. [What are the classes and interfaces for servlets?](#)
5-
1. [What is the difference between an applet and a servlet?](#)
4+
1. [What is different between web server and application server?](#what-is-different-between-web-server-and-application-server-)
5+
1. [Which HTTP method is non-idempotent?](#which-http-method-is-non-idempotent-)
6+
1. [What is the difference between GET and POST method?](#what-is-the-difference-between-get-and-post-method-)
7+
8+
---
9+
10+
1. ##### What is different between web server and application server? [⤴](#java-servlets-)
11+
12+
short answer: web server serves static content, application server serves dynamic content.
13+
14+
long answer:
15+
16+
A web server responsibility is to handler HTTP requests from client browsers and respond with HTML response. A web server understands HTTP language and runs on HTTP protocol.
17+
Apache Web Server is kind of a web server and then we have specific containers that can execute servlets and JSPs known as servlet container, for example Tomcat.
18+
19+
Application Servers provide additional features such as Enterprise JavaBeans support, JMS Messaging support, Transaction Management etc. So we can say that Application server is a web server with additional functionalities to help developers with enterprise applications.
20+
21+
1. ##### Which HTTP method is non-idempotent? [⤴](#java-servlets-)
22+
23+
A HTTP method is said to be idempotent if it returns the same result every time. HTTP methods GET, PUT, DELETE, HEAD, and OPTIONS are idempotent method and we should implement our application to make sure these methods always return same result. HTTP method POST is non-idempotent method and we should use post method when implementing something that changes with every request.
24+
25+
For example, to access an HTML page or image, we should use GET because it will always return the same object but if we have to save customer information to database, we should use POST method. Idempotent methods are also known as safe methods and we don’t care about the repetitive request from the client for safe methods.
26+
27+
1. ##### What is the difference between GET and POST method? [⤴](#java-servlets-)
28+
29+
- GET is a safe method (idempotent) where POST is non-idempotent method.
30+
- We can send limited data with GET method and it’s sent in the header request URL whereas we can send large amount of data with POST because it’s part of the body.
31+
- GET method is not secure because data is exposed in the URL and we can easily bookmark it and send similar request again, POST is secure because data is sent in request body and we can’t bookmark it.
32+
- GET is the default HTTP method whereas we need to specify method as POST to send request with POST method.
33+
- Hyperlinks in a page uses GET method.
34+
35+
36+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
Web Services
2+
---
3+
4+
List questions:
5+
6+
1. [What is a Web Service?](#what-is-a-web-service-)
7+
1. [What are the advantages of Web Services?](#what-are-the-advantages-of-web-services-)
8+
1. [What are different types of Web Services?](#what-are-different-types-of-web-services-)
9+
1. [What is REST Web Services?](#what-is-rest-web-services-)
10+
1. [What are advantages of REST web services?](#what-are-advantages-of-rest-web-services-)
11+
1. [What are disadvantages of REST web services?](#what-are-disadvantages-of-rest-web-services-)
12+
1. [What is a Resource in Restful web services?](#what-is-a-resource-in-restful-web-services-)
13+
1. [What are different HTTP Methods supported in Restful Web Services?](#what-are-different-http-methods-supported-in-restful-web-services-)
14+
1. [Can we maintain user session in web services?](#can-we-maintain-user-session-in-web-services-)
15+
16+
---
17+
18+
1. ##### What is a Web Service? [⤴](#web-services-)
19+
20+
Web Services work on client-server model where client applications can access web services over the network. Web services provide endpoint URLs and expose methods that can be accessed over network through client programs written in java, shell script or any other different technologies.
21+
Web services are stateless and doesn’t maintain user session like web applications.
22+
23+
1. ##### What are the advantages of Web Services? [⤴](#web-services-)
24+
25+
Some of the advantages of web services are:
26+
27+
- Interoperability: Web services are accessible over network and runs on HTTP/SOAP protocol and uses XML/JSON to transport data, hence it can be developed in any programming language. Web service can be written in java programming and client can be PHP and vice versa.
28+
- Reusability: One web service can be used by many client applications at the same time.
29+
- Loose Coupling: Web services client code is totally independent with server code, so we have achieved loose coupling in our application.
30+
- Easy to deploy and integrate, just like web applications.
31+
- Multiple service versions can be running at same time.
32+
33+
1. ##### What are different types of Web Services? [⤴](#web-services-)
34+
35+
There are two types of web services:
36+
37+
- SOAP Web Services: Runs on SOAP protocol and uses XML technology for sending data.
38+
- Restful Web Services: It’s an architectural style and runs on HTTP/HTTPS protocol almost all the time. REST is a stateless client-server architecture where web services are resources and can be identified by their URIs. Client applications can use HTTP GET/POST methods to invoke Restful web services.
39+
40+
1. ##### What is REST Web Services? [⤴](#web-services-)
41+
42+
REST is the acronym for REpresentational State Transfer. REST is an architectural style for developing applications that can be accessed over the network. REST architectural style was brought in light by Roy Fielding in his doctoral thesis in 2000.
43+
44+
REST is a stateless client-server architecture where web services are resources and can be identified by their URIs. Client applications can use HTTP GET/POST methods to invoke Restful web services. REST doesn’t specify any specific protocol to use, but in almost all cases it’s used over HTTP/HTTPS. When compared to SOAP web services, these are lightweight and doesn’t follow any standard. We can use XML, JSON, text or any other type of data for request and response.
45+
46+
1. ##### What are advantages of REST web services? [⤴](#web-services-)
47+
48+
Some of the advantages of REST web services are:
49+
50+
- Learning curve is easy since it works on HTTP protocol
51+
- Supports multiple technologies for data transfer such as text, xml, json, image etc.
52+
- No contract defined between server and client, so loosely coupled implementation.
53+
- REST is a lightweight protocol
54+
- REST methods can be tested easily over browser.
55+
56+
1. ##### What are disadvantages of REST web services? [⤴](#web-services-)
57+
58+
Some of the disadvantages of REST are:
59+
60+
- Since there is no contract defined between service and client, it has to be communicated through other means such as documentation or emails.
61+
- Since it works on HTTP, there can’t be asynchronous calls.
62+
Sessions can’t be maintained.
63+
64+
1. ##### What is a Resource in Restful web services? [⤴](#web-services-)
65+
66+
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.
67+
68+
1. ##### What are different HTTP Methods supported in Restful Web Services? [⤴](#web-services-)
69+
70+
Restful web services supported HTTP methods are – GET, POST, PUT, DELETE and HEAD.
71+
72+
1. ##### Can we maintain user session in web services? [⤴](#web-services-)
73+
74+
Web services are stateless so we can’t maintain user sessions in web services.
75+
76+
References
77+
---
78+
1. [web services interview questions](http://www.journaldev.com/9193/web-services-interview-questions-soap-restful)

‎JavaCore/2.JavaBasic.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ List questions:
5454
1. [What are polymorphism and inheritance?](#what-are-polymorphism-and-inheritance-)
5555
1. [String literal and String object](#string-literal-and-string-object-)
5656
1. [What does the keyword transient mean in Java?](#what-does-the-keyword-transient-mean-in-java-)
57+
1. [What does super keyword do?](#what-does-super-keyword-do-)
5758

5859
Main methods:
5960

@@ -302,6 +303,14 @@ Both represent mutable sequence of characters.
302303
1. ##### What does the keyword transient mean in Java? [⤴](#java-basics)
303304
It marks a member variable not to be serialized when it is persisted to streams of bytes. When an object is transferred through the network, the object needs to be 'serialized'. Serialization converts the object state to serial bytes. Those bytes are sent over the network and the object is recreated from those bytes. Member variables marked by the java transient keyword are not transferred, they are lost intentionally.
304305

306+
1. ##### What does super keyword do? [⤴](#java-basics)
307+
308+
- super is used to refer immediate parent class instance variable.
309+
- super() is used to invoke immediate parent class constructor.
310+
- super is used to invoke immediate parent class method.
311+
312+
[detail](http://www.javatpoint.com/super-keyword)
313+
305314
Main Method
306315
---
307316

‎JavaCore/3.JavaBasic2.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ List questions:
178178

179179
1. ##### How to Make an Object Immutable in Java? Why Should You Make an Object Immutable? [⤴](#java-basics-2)
180180
Well, Immutability offers several advantages including thread-safety, ability to cache and result in more readable multithreading code. See [here](http://javarevisited.blogspot.sg/2013/03/how-to-create-immutable-class-object-java-example-tutorial.html) to learn how to make object Immutable. Once again, this question can also go into more detail and depending on your answer, can bring several other questions e.g. when you mention Spring is Immutable, be ready with some reasons on Why String is Immutable in Java.
181+
182+
- Make your class final - You already have
183+
- Make all the fields private and final - Make appropriate changes in your code
184+
- Don't provide any methods that change the state of your instance
185+
- If you have mutable fields in your class, like List, or Date, making them final won't suffice. You should return a defensive copy from their getters, so that their state isn't mutated by calling methods. [stackoverflow](http://stackoverflow.com/a/18194266)
181186

182187
1. ##### Which Design Pattern Will You Use to Shield Your Code From a Third Party library Which Will Likely to be Replaced by Another in Couple of Months? [⤴](#java-basics-2)
183188
This is just one example of the scenario-based design pattern interview question. In order to test the practical experience of Java developers with more than 5 years experience, companies ask this kind of questions. You can expect more real-world design problems in different formats, some with more detail explanation with context, or some with only intent around.

‎JavaCore/4.Collections.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ List questions:
5656
1. [While passing a Collection as argument to a function, how can we make sure the function will not be able to modify it?](#while-passing-a-collection-as-argument-to-a-function-how-can-we-make-sure-the-function-will-not-be-able-to-modify-it-)
5757
1. [How can we create a synchronized collection from given collection?](#how-can-we-create-a-synchronized-collection-from-given-collection-)
5858
1. [What are best practices related to Java Collections Framework?](#what-are-best-practices-related-to-java-collections-framework--)
59+
1. [What is fail fast iterator?](#what-is-fail-fast-iterator-)
60+
1. [What is a fail-safe iterator?](#what-is-a-fail-safe-iterator-)
61+
1. [Difference between fail-fast iterator and fail-safe iterator](#difference-between-fail-fast-iterator-and-fail-safe-iterator-)
5962

6063
---
6164

@@ -76,6 +79,8 @@ List questions:
7679
utility classes Collections and Arrays
7780
```
7881

82+
[collection in java tutorial](http://www.journaldev.com/1260/collections-in-java-tutorial)
83+
7984
2. ##### The difference between List, Set, Map, and Queue in Java? [⤴](#collections)
8085

8186
| | List | Set | Map |
@@ -503,6 +508,29 @@ Check this post for use of BlockingQueue for [producer-consumer problem](http://
503508
- Use immutable classes provided by JDK as key in Map to avoid implementation of hashCode() and equals() for our custom class.
504509
Use Collections utility class as much as possible for algorithms or to get read-only, synchronized or empty collections rather than writing own implementation. It will enhance code-reuse with greater stability and low maintainability.
505510

511+
1. ##### What is fail fast iterator? [⤴](#collections)
512+
513+
An iterator is considered fail-fast if it throws a ConcurrentModificationException under either of the following two conditions:
514+
515+
- In multi-threaded environment, if one thread is trying to modify a Collection while another thread is iterating over it.
516+
- Even with single thread, if a thread modifies a collection directly while it is iterating over the collection with a fail-fast iterator, the iterator will throw this exception.
517+
518+
fail-fast iterator will throw a ConcurrentModificationException if the underlying collection is structurally modified in any way except through the iterator's own remove or add (if applicable as in list-iterator) methods.
519+
520+
Note that structural modification is any operation that adds or deletes one or more elements; merely setting the value of an element (in case of list) or changing the value associated with an existing key (in case of map) is not a structural modification.
521+
522+
1. ##### What is a fail-safe iterator? [⤴](#collections)
523+
524+
An iterator is considered fail-safe if it does not throw ConcurrentModificationException. ConcurrentModificationException is not thrown as the fail-safe iterator makes a copy of the underlying structure and iteration is done over that snapshot.
525+
526+
Since iteration is done over a copy of the collection so interference is impossible and the iterator is guaranteed not to throw ConcurrentModificationException.
527+
528+
1. ##### Difference between fail-fast iterator and fail-safe iterator. [⤴](#collections)
529+
530+
- fail-fast iterator throws a ConcurrentModificationException if the underlying collection is structurally modified whereas fail-safe iterator doesn't throw ConcurrentModificationException.
531+
- fail-fast iterator doesn't create a copy of the collection whereas fail-safe iterator makes a copy of the underlying structure and iteration is done over that snapshot.
532+
- fail-fast iterator provides operations like remove, add and set (in case of ListIterator) whereas in case of fail-safe iterators element-changing operations on iterators themselves (remove, set and add) are not supported. These methods throw UnsupportedOperationException.
533+
506534
References [⤴](#collections)
507535
---
508536

‎JavaCore/5.OOPandDesignPatterns.md‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,21 @@ List questions:
4242
1. [What is polymorphism? How does Java support it?](#what-is-polymorphism-howdoes-java-supportit-)
4343
1. [What is the difference between a mutable object and an immutable object? How can you design an object to be immutable?](#what-is-the-difference-between-amutable-object-and-animmutableobject-how-can-you-design-anobject-tobeimmutable-)
4444
1. [What is the difference between coupling and cohesion? What is the preferred relationship between software components and why?](#what-is-the-difference-between-coupling-andcohesion-what-is-the-preferred-relationship-between-softwarecomponents-andwhy-)
45+
1. [What is Static Binding and Dynamic Binding?](#what-is-static-binding-and-dynamic-binding-)
4546

4647
---
4748

4849
1. ##### Object oriented Programming (OOP) [⤴](#oop-and-design-patterns)
4950

50-
Java is a computer programming language that is concurrent, class-based and object-oriented. The advantages of object oriented software development are shown below:
51-
51+
Java is a computer programming language that is concurrent, class-based and object-oriented.
52+
53+
Object Oriented Programming System is the programming technique to write programs based on the real world objects. The states and behaviors of an object are represented as the member variables and methods. In OOPS programming programs are organized around objects and data rather than actions and logic.
54+
55+
The advantages of object oriented software development are shown below:
56+
57+
* Simplicity: OOPS programming objects model real world objects, so the complexity is reduced and the program structure is clear.
5258
* Modular development of code, which leads to easy maintenance and modification.
59+
* Extensibility: Adding new features or responding to changing operating environments can be solved by introducing a few new objects and modifying some existing ones.
5360
* Reusability of code.
5461
* Improved reliability and flexibility of code.
5562
* Increased understanding of code.
@@ -78,11 +85,15 @@ List questions:
7885

7986
**Abstraction**
8087

81-
[Abstraction](http://www.javacodegeeks.com/2014/04/why-abstraction-is-really-important.html) is the process of separating ideas from specific instances and thus, develop classes in terms of their own functionality, instead of their implementation details. Java supports the creation and existence of abstract classes that expose interfaces, without including the actual implementation of all methods. The abstraction technique aims to separate the implementation details of a class from its behavior.
88+
Abstraction is an OOPS concept to construct the structure of the real world objects. During this construction only the general states and behaviors are taken and more specific states and behaviors are left aside for the implementers.
89+
90+
[Abstraction](http://www.javacodegeeks.com/2014/04/why-abstraction-is-really-important.html)
8291

8392
**Differences between Abstraction and Encapsulation**
8493

85-
Abstraction and encapsulation are complementary concepts. On the one hand, abstraction focuses on the behavior of an object. On the other hand, encapsulation focuses on the implementation of an object’s behavior. Encapsulation is usually achieved by hiding information about the internal state of an object and thus, can be seen as a strategy used in order to provide abstraction.
94+
- Abstraction and encapsulation are complementary concepts. On the one hand, abstraction focuses on the behavior of an object. On the other hand, encapsulation focuses on the implementation of an object’s behavior. Encapsulation is usually achieved by hiding information about the internal state of an object and thus, can be seen as a strategy used in order to provide abstraction.
95+
96+
- Abstraction is implemented in Java using interface and abstract class while Encapsulation is implemented using four types of access level modifiers: public, protected, no modifier and private.
8697

8798
1. ##### What is a POJO? [⤴](#oop-and-design-patterns)
8899

@@ -362,3 +373,14 @@ List questions:
362373

363374
For example, a Swiss Army knife is a low cohesion entity because it can do multiple things, but it can’t do them very well. A multi-tool could never match the productivity of a toolbox filled with highly cohesive tools. In software applications, cohesive components are more robust and easier to test.
364375

376+
1. ##### What is Static Binding and Dynamic Binding? [⤴](#oop-and-design-patterns)
377+
378+
Static or early binding is resolved at compile time. Method overloading is an example of static binding.
379+
380+
Dynamic or late or virtual binding is resolved at run time. Method overriding is an example of dynamic binding.
381+
382+
References
383+
---
384+
1. [association-aggregation-composition-abstraction-generalization-realization-dependency](http://javapapers.com/oops/association-aggregation-composition-abstraction-generalization-realization-dependency/)
385+
2. [oops-interview-questions-answers](http://www.journaldev.com/12492/oops-interview-questions-answers)
386+
3.

0 commit comments

Comments
 (0)