Thursday, April 12, 2018

Webservices

Q) When to use REST vs SOAP?
Ans https://dzone.com/articles/web-services-architecture
https://stormpath.com/blog/rest-vs-soap

  • SOAP is good for applications that require formal contracts between the API and consumer since it can enforce the use of formal contracts by using WSDL (Web Services Description Language).
  • Additionally, SOAP has built in WS-Reliable messaging to increase security in asynchronous execution and processing.
  • Finally, SOAP has built-in stateful operations. REST is naturally stateless, but SOAP is designed to support conversational state management.

Q) How to handle security in REST webservices?
Ans https://dzone.com/articles/top-5-rest-api-security-guidelines

Q) In Restful webservices, what are the methods and their use?
Ans -POST for CREATE, PUT for update, DELETE for deletion, GET for retrieval, PATCH for partial updates  and OPTION for checking before making a GET request

Reason- POST is idempotent as per HTTP specification and a creation request should be idempotent
PATCH is also idempotent

Q) Things to keep in mind while designing a restful web service?



Useful links:
REST web services - https://www.youtube.com/watch?v=xkKcdK1u95s&list=PLCCK2CzCX8EXTVHe12NLKMHq5GytRJSUj

Monday, April 9, 2018

Spring interview questions

Q) What are bean scopes?

Q) Lifecycle of a bean?
http://javainsimpleway.com/spring-bean-life-cycle/

Q) Why is @component used?

Q) How to create a web request in spring MVC?

Q) When to use @service and @component annotations?

Q) Transaction management in Spring?

Q) What are different types of handler mappings and view resolvers in spring?

Q) How to create a synchronized bean in spring?
Ans: https://tarunsapra.wordpress.com/2011/08/21/spring-singleton-request-session-beans-and-thread-safety/
https://javabeat.net/spring-singleton-java-singleton/

Q) What is dependency injection?
Ans Dependency injection is a design pattern and IOP is the way spring achieves it

Q) How to handle internationalization and localization in spring MVC?
Ans - Steps
1) Include two links-English and French on top of jsp page
2) Register an interceptor with the name localeChangeInterceptor  in the spring cofiguration file
3) Include an entry of cookieLocaleResolver bean in the spring's configuration file

Q) Difference between bean id and bean name and their uses?
Ans - Every bean has one or more ids (also called identifiers, or names; these terms refer to the same thing). These ids must be unique within the container the bean is hosted in. A bean will almost always have only one id, but if a bean has more than one id, the extra ones can essentially be considered aliases.
When using XML-based configuration metadata, you use the 'id' or 'name' attributes to specify the bean identifier(s). The 'id' attribute allows you to specify exactly one id, and as it is a real XML element ID attribute, the XML parser is able to do some extra validation when other elements reference the id; as such, it is the preferred way to specify a bean id. However, the XML specification does limit the characters which are legal in XML IDs. This is usually not a constraint, but if you have a need to use one of these special XML characters, or want to introduce other aliases to the bean, you may also or instead specify one or more bean ids, separated by a comma (,), semicolon (;), or whitespace in the 'name' attribute.

Q) What are the new features in spring 4.0 and spring 4.1
Ans -
  •  spring-webmodule provides support over websocket based communication in web applications
  • spring 4.0 is based on servlet 3.0+ implementations
  • @RestController annotation is introduced to use with Spring applications
  • Spring 4.1 introduces @JMSListener annotations to easily register JMS listener endpoints
  • Spring 4.1 supports Jcache(JSR- 107) annotations using spring's existing cache configuration
  • Jackson's @Jsonviewisdirectlysupportedon @ResponseBodyandResponseEntitycontroller methods
Q) Difference between singleton pattern and spring singleton bean
Ans. Singleton pattern supports singleton for one object per JVM whereas spring singleton scope is one bean per application context.

Q) How is validation done using spring framework
Ans Using Validator interface

Q) Steps to create a spring mvc application

1) create a maven project with archetype as maven-archetype-webapp
2) Modify pom.xml and include spring dependencies
3) Modify web.xml to specify dispatcher servlet (Front Controller) class
4) create spring-dispatcher-servlet.xml (front controller) and specify handler mapping, controller class and view resolver settings.(Can use annotations for handler mapping and controller)
5) Create controller class

Q) Types of controllers in spring MVC?






Useful links:
http://www.baeldung.com/spring-mvc-and-the-modelattribute-annotation
https://www.youtube.com/watch?v=8V4ArtwNuwk&list=PLBgMUB7xGcO31B2gBmy1igpZn6LK78-CJ&index=12
https://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#mvc-ann-requestparam


Tuesday, April 3, 2018

Java interview questions

Q) How to find out minor gc(garbage collection) vs major gc using gc logs
Ans:2014-11-18T16:39:37.728-0800: 88.808: [Full GC [PSYoungGen: 116544K->12164K(233024K)] [PSOldGen: 684832K->699071K(699072K)] 801376K->711236K(932096K) [PSPermGen: 2379K->2379K(21248K)], 3.4230220 secs] [Times: user=3.40 sys=0.02, real=3.42 secs]

In the above statement, gc means minor gc and Full gc means major/full gc.

 https://dzone.com/articles/understanding-garbage-collection-log
http://karunsubramanian.com/websphere/troubleshooting-gc-step-by-step-instructions-to-analyze-verbose-gc-logs/

Q) How a marker interface works internally?

Q) What does ? super T and ? extends T mean in generics?
Ans http://www.oracle.com/technetwork/articles/java/juneau-generics-2255374.html

Q) Difference between port and porttype in a wsdl file
Ans: https://www.predic8.com/wsdl-reading.htm


Q) How to consume a webservice in Java/
Ans https://howtodoinjava.com/spring/spring-boot/spring-soap-client-webservicetemplate/

Q) How to render soap webservice over https?

Q) How do indexes work internally?
Ans http://www.dba-oracle.com/concepts/index_administration.htm
 https://docs.oracle.com/cloud/latest/db112/CNCPT/indexiot.htm#CNCPT1170

Q) Why do indexes slow performance?

Q) Code review checklist
Ans https://www.java-success.com/30-java-code-review-checklist-items/

Q) Explain the significance of marker interface
Q) Garbage collection algorithms
Q) sort an arraylist with US, India, Canada at the top
Q) slow updates in prod..how to fix
Q) diff in Java memory model in java8
Q) difference between transient and static
Q) Does serialzation create same object or different object? How does JVM differentiates
Q) How does spring boot work internally
Q) what is ssl
Q) Hibernate child object is lazily loaded. What happens if you call get after a session close(LazyIntiialization exception)
Q) How to add an extra parameter from database in the entity class  (Use transient)
Q) What logging is used in spring boot
Q) When does lazyinitialization exception occur
Q) Second level cache- When does it caches objects
Q) WHat are propagation levels
Q) What is metaspace
Q) How to mark an entity to be caches in second level cache (Use @Cacheacle)
Q) WHat are GC algorithms
Q) Production application -Slow Insertion-Steps to be taken
Q) How to create listener in angular application
Q) Benefits of Enum
Q) Program to find the number of repeated letters in a word
Q) Soft vs weak reference
Q) What is @embedded in hibernate
Q) Component vs contoller
Q) wsdl vs REST. why use soap?
Q) internal working of concurrenthashmap
Q) hashmap vs synchronized map
Q) Why REST is used so much?
Q) Two threads one genrate evn an other odd ?
Q) BlockingQueue
Q) An employee class with hascode returning 1 and equal returning "true". how many objects in the map if 3 are put?
Q) final list = new ArrayList(), Can i use list.set?
Q) Hww to customize serialization
Q) SOLID principles
Q) Aggregation vs composition
Q) Comparable vs comparator
Q) Clone method is in which class? How can we create a sutom marker interface?
Q) @ManytoMany Mapping in hibernate between two entities? How many tables?
Q) Bean scope in @RestController? How does it handle mutiple request?
Q) how to calcualte the frequency of a string in a list of 100 strings?
Ans: Use a map for keeping the count of a string
Q) How to create an immutable list - no cloning allowed
Q) How does @RestController handle multiple requests
Q) How does a servlet handle multiple requests?
Q) Two synchronized methods- two threads t1 and t2? Can they access at the same time?
Q) Fail fast and fail safe- How and why?
Q) Changes in Hashmap in java 8?
Q) Why are functional interfaces created?
Q) Microservices -static URLs /dynamic URLs


-----------------------------------------IRIS----------------------------------------------------------
Q) Design patterns - Prototype, Decorator
Q) sorting hashmap by value
Q) Custom hashmap- immutable
Q) SOLID principles - Examples
Q) Interface examples
Q) design patterns in Java libraries 
Q) @Qualifier 
Q) Reentrant lock - 
Q) Predicate, Supplier , Consumer
Q) How to restrict to 3 objects only 
Q) Multiple default methods in one interface?
Q) ExecutorService-> new fixed thread pool vs cache pool
Q) Context Class Loader
Q) When the application is up and running, send an email to support team. Spring
Q) Design a cache - LRU and last read
Q) millions of customers- how to handle load- Design
Q) Check out of memory in production
Q) json to string?
Q) Hashmap key - hashcode and equals - Immutable - no setters, how to set 
Q) How to validate a input json in REST
Q) Hibernate- cascading?
Q) How to handle transactions in hibernate
Q) How will you cache the data inside GET API mehtod
Q) Redis cache. How does it share data between microservics
Q) How do 2 APIs/microservices communicate with each other
Q) How to design an application with millions of users
-------------------------------------------------------------------------------------------------------
_________________________________________________________________________________

Ericsson

Q) One java application wants to connect with a third party application. Which design pattern should be used?
Ans Adapter

Q) In apache camel how do we integrate two different applications?

Q) There is an employee POJO. and a new field is required to be added without touching the existing code. What to do?
And Use inheritance

Q) How to reproduce a memory leak issue that occured in production environment to a local environment?
https://www.jahia.com/about-us/news-events/blog/tips-and-tricks-for-analyzing-java-virtual-machine-heap-memory-dumps
http://javaeesupportpatterns.blogspot.in/2011/11/hprof-memory-leak-analysis-tutorial.html

Q) Which collection to use in case of a lot of reads and few write operations?
Ans ArrayList

Q) Challenges faced in any projects?
_________________________________________________________________________________

Q) Which Java API should be used to fetch data from a legacy system?

Q) Use case- A weather service - How to reduce load on this service?
Ans Observer pattern

Q) Comparable vs comparator- which to use when?

Q) Things to keep in mind while designing a system?

Q) How to do performance management based on some input for an application?

Q) What happens if you call destroy from init in a servlet?

Q) Find third largest salaried employee in the employee table
________________________________________________________________________________

ING internal

Q) a function is not performing well in the application. What approach to find the problem. Environment is production

Q) how do you handle security in your application

Q) multithreading- fixed thread pool of 10 threads. 100 tasks are submitted. How many threads. how does submit and execute work internally.

Q) What does an angular application made of- where is template define. How to create an injectable service

Q) Where do you use functional interface in your application
Ans https://stackoverflow.com/questions/36881826/what-is-use-of-functional-interface-in-java-8/36882003?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

Q) How do you use Apache camel in your application

Q) How to make a custom object as key to a hashmap in java 8
Ans https://dzone.com/articles/java-8-hashmaps-keys-and-the-comparable-interface
https://stackoverflow.com/questions/35164645/is-it-a-bug-that-java-8s-hashmap-misbehaves-if-the-keys-implement-comparable-in
https://www.javaworld.com/article/2073618/java-s-system-identityhashcode.html

Q) Why to use lambda expressions in java8?
Ans. https://www.nagarro.com/en/perspectives/post/26/Lambda-Expressions-in-Java-8-Why-and-How-to-Use-Them

Q) How does executor framework work internally. What does runnable.execute or callable.submit do?
Ans







Good links:
Functional interface uses: http://www.baeldung.com/java-8-lambda-expressions-tips
https://netjs.blogspot.in/2016/03/effectively-final-in-java-8.html

-->