1.Restful API Client side code?
2.What is weaving?
3.Transaction management in Spring?
4.Spring and hibernate Integration?
5.Java 8 Features?
a.Lamda-Expression
b.Method References
c.Functional Interfaces
d.Streams
e.Optional Class
f.Date API
g.Base64
Tuesday, March 7, 2017
Friday, March 3, 2017
Angular JS 1 Tutorial
Angular Js
Controller Responsibilities
--------------------------------
1.Fetching the right data from the server for the current UI
2 Deciding which parts of that data to show to the user
3 Presentation logic, such as how to display elements, which parts of the UI to show, how to style them, etc.
4 User interactions, such as what happens when a user clicks something or how a text input should be validated
Angular Js Life Cycle
-------------------------
1. The HTML is loaded. This triggers requests for all the scripts that are a part of it.
2. After the entire document has been loaded, AngularJS kicks in and looks for the ng-app directive.
3. When it finds the ng-app directive, it looks for and loads the module that is specified and attaches it to the element.
4. AngularJS then traverses the children DOM elements of the root element with the ng-app and starts looking for directives and bind statements.
5. Each time it hits an ng-controller or an ng-repeat directive, it creates what we call a scope in AngularJS. A scope is the context for that element. The scope dictates what each DOM element has access to in terms of functions, variables, and the like.
6. AngularJS then adds watchers and listeners on the variables that the HTML ac‐cesses, and keeps track of the current value of each of them. When that value changes, AngularJS updates the UI immediately.
7. Instead of polling or some other mechanism to check if the data has changed, An‐gularJS optimizes and checks for updates to the UI only on certain events, which can cause a change in the data or the model underneath. Examples of such events include XHR or server calls, page loads, and user interactions like click or type.
a.ng-class:
The ng-class directive is used to selectively apply and remove CSS classes from elements. There are multiple ways of using ng-class, and we will talk about what we feel is the most declarative and cleanest option. The ng-class directive can take strings or objects as values. If it is a string, it simply applies the CSS classes directly.
If it is an object (which we are returning from the function in the controller), An‐gularJS takes a look at each key of the object, and depending on whether the value for that key is true or false, applies or removes the CSS class.
b.ng-show
There are two directives in AngularJS that deal with hiding and showing HTML elements: ng-show and ng-hide. They inspect a variable and, depending on the truthiness of its value, show or hide elements in the UI, respectively. In this case,we say show the assignee span if note.assignee is true. AngularJS treats true,nonempty strings, nonzero numbers, and nonnull JS objects as truthy. So in this case, we get to see the assignee span if the note has an assignee.
Form States:
-----------
a.$invalid :AngularJS sets this state when any of the validations (required, ng-minlength, and others) mark any of the fields within the form as invalid.
b.$valid: The inverse of the previous state, which states that all the validations in the form are currently evaluating to correct.
c.$pristine: All forms in AngularJS start with this state. This allows you to figure out if a user has started typing in and modifying any of the form elements. Possible usage: disabling the reset button if a form is pristine.
d.$dirty :The inverse of $pristine, which states that the user made some changes (he can revert it, but the $dirty bit is set).
e.$error: This field on the form houses all the individual fields and the errors on each form element. We will talk more about this in the following section.
Built-in Angular Js Validators:
-------------------------------
a.required :As previously discussed, this ensures that the field is required, and the field is marked invalid until it is filled out.
b.ng-required: Unlike required, which marks a field as always required, the
c.ng-required directive allows us to conditionally mark an input field as required based on a Boolean condition in the controller.
d.ng-minlength: We can set the minimum length of the value in the input field with this directive.
e.ng-maxlength: We can set the maximum length of the value in the input field with this directive.
f.ng-pattern: The validity of an input field can be checked against the regular expression pattern specified as part of this directive.
type="email" :Text input with built-in email validation.
type="number" :Text input with number validation. Can also have additional attributes for min and max values of the number itself.
type="date" :If the browser supports it, shows an HTML datepicker. Otherwise, defaults to a text input. The ngmodel that this binds to will be a date object. This expects the date to be in yyyy-mm-dd format (e.g.,
2009-10-24).
type="url" :Text input with URL validation.
Common AngularJS Services
---------------------------
1.$window:
The $window service in AngularJS is nothing but a wrapper around the global win‐dow object. The sole reason for its existence is to avoid global state, especially in tests. Instead of directly working with the window object, we can ask for and work with $window. In the unit tests, the $window service can be easily mocked out (avail‐able for free with the AngularJS mocking library).
2.$location:
The $location service in AngularJS allows us to interact with the URL in the
browser bar, and get and manipulate its value. Any changes made to the $location service get reflected in the browser, and any changes in the browser are immediately captured in the $location service. The $location service has the following functions, which allow us to work with the URL:
a.absUrl
A getter that gives us the absolute URL in the browser (called $location.
absUrl()).
b.url
A getter and setter that gets or sets the URL. If we give it an argument, it will set the URL; otherwise, it will return the URL as a string.
c.path
Again, a getter and setter that sets the path of the URL. Automatically adds the forward slash at the beginning. So $location.path() would give us the current path of the application, and $location.path("/new") would set the pathto /new.
d.search
Sets or gets the search or query string of the current URL. Calling $location.search() without any arguments returns the search parameter as an object. Calling $location.search("test") removes the search parameter from the URL, and calling $location.search("test", "abc"); sets the search pa
rameter test to abc.
3.$http
Config function :
------------------
• The config function executes before the AngularJS app executes. So we can be assured that this executes before our controllers, services, and other functions.
• The config function follows the same Dependency Injection pattern, but gets providers injected in. In this case, we ask for the ItemServiceProvider.
• At this point, we can now call functions and set values that the provider exposes.
We are able to the call the disableDefaultItems function that we defined in the
provider.
• The config function could also set up URL endpoints, locale information, routingconfiguration for our application, and so on: things that need to be executed and initialized before our application starts.
• We can try changing the value of shouldHaveDefaults to true (this would come from the server or URL, or some other way usually) to see the effect it has on ourapplication.
Controller Responsibilities
--------------------------------
1.Fetching the right data from the server for the current UI
2 Deciding which parts of that data to show to the user
3 Presentation logic, such as how to display elements, which parts of the UI to show, how to style them, etc.
4 User interactions, such as what happens when a user clicks something or how a text input should be validated
Angular Js Life Cycle
-------------------------
1. The HTML is loaded. This triggers requests for all the scripts that are a part of it.
2. After the entire document has been loaded, AngularJS kicks in and looks for the ng-app directive.
3. When it finds the ng-app directive, it looks for and loads the module that is specified and attaches it to the element.
4. AngularJS then traverses the children DOM elements of the root element with the ng-app and starts looking for directives and bind statements.
5. Each time it hits an ng-controller or an ng-repeat directive, it creates what we call a scope in AngularJS. A scope is the context for that element. The scope dictates what each DOM element has access to in terms of functions, variables, and the like.
6. AngularJS then adds watchers and listeners on the variables that the HTML ac‐cesses, and keeps track of the current value of each of them. When that value changes, AngularJS updates the UI immediately.
7. Instead of polling or some other mechanism to check if the data has changed, An‐gularJS optimizes and checks for updates to the UI only on certain events, which can cause a change in the data or the model underneath. Examples of such events include XHR or server calls, page loads, and user interactions like click or type.
a.ng-class:
The ng-class directive is used to selectively apply and remove CSS classes from elements. There are multiple ways of using ng-class, and we will talk about what we feel is the most declarative and cleanest option. The ng-class directive can take strings or objects as values. If it is a string, it simply applies the CSS classes directly.
If it is an object (which we are returning from the function in the controller), An‐gularJS takes a look at each key of the object, and depending on whether the value for that key is true or false, applies or removes the CSS class.
b.ng-show
There are two directives in AngularJS that deal with hiding and showing HTML elements: ng-show and ng-hide. They inspect a variable and, depending on the truthiness of its value, show or hide elements in the UI, respectively. In this case,we say show the assignee span if note.assignee is true. AngularJS treats true,nonempty strings, nonzero numbers, and nonnull JS objects as truthy. So in this case, we get to see the assignee span if the note has an assignee.
Form States:
-----------
a.$invalid :AngularJS sets this state when any of the validations (required, ng-minlength, and others) mark any of the fields within the form as invalid.
b.$valid: The inverse of the previous state, which states that all the validations in the form are currently evaluating to correct.
c.$pristine: All forms in AngularJS start with this state. This allows you to figure out if a user has started typing in and modifying any of the form elements. Possible usage: disabling the reset button if a form is pristine.
d.$dirty :The inverse of $pristine, which states that the user made some changes (he can revert it, but the $dirty bit is set).
e.$error: This field on the form houses all the individual fields and the errors on each form element. We will talk more about this in the following section.
Built-in Angular Js Validators:
-------------------------------
a.required :As previously discussed, this ensures that the field is required, and the field is marked invalid until it is filled out.
b.ng-required: Unlike required, which marks a field as always required, the
c.ng-required directive allows us to conditionally mark an input field as required based on a Boolean condition in the controller.
d.ng-minlength: We can set the minimum length of the value in the input field with this directive.
e.ng-maxlength: We can set the maximum length of the value in the input field with this directive.
f.ng-pattern: The validity of an input field can be checked against the regular expression pattern specified as part of this directive.
type="email" :Text input with built-in email validation.
type="number" :Text input with number validation. Can also have additional attributes for min and max values of the number itself.
type="date" :If the browser supports it, shows an HTML datepicker. Otherwise, defaults to a text input. The ngmodel that this binds to will be a date object. This expects the date to be in yyyy-mm-dd format (e.g.,
2009-10-24).
type="url" :Text input with URL validation.
Common AngularJS Services
---------------------------
1.$window:
The $window service in AngularJS is nothing but a wrapper around the global win‐dow object. The sole reason for its existence is to avoid global state, especially in tests. Instead of directly working with the window object, we can ask for and work with $window. In the unit tests, the $window service can be easily mocked out (avail‐able for free with the AngularJS mocking library).
2.$location:
The $location service in AngularJS allows us to interact with the URL in the
browser bar, and get and manipulate its value. Any changes made to the $location service get reflected in the browser, and any changes in the browser are immediately captured in the $location service. The $location service has the following functions, which allow us to work with the URL:
a.absUrl
A getter that gives us the absolute URL in the browser (called $location.
absUrl()).
b.url
A getter and setter that gets or sets the URL. If we give it an argument, it will set the URL; otherwise, it will return the URL as a string.
c.path
Again, a getter and setter that sets the path of the URL. Automatically adds the forward slash at the beginning. So $location.path() would give us the current path of the application, and $location.path("/new") would set the pathto /new.
d.search
Sets or gets the search or query string of the current URL. Calling $location.search() without any arguments returns the search parameter as an object. Calling $location.search("test") removes the search parameter from the URL, and calling $location.search("test", "abc"); sets the search pa
rameter test to abc.
3.$http
Config function :
------------------
• The config function executes before the AngularJS app executes. So we can be assured that this executes before our controllers, services, and other functions.
• The config function follows the same Dependency Injection pattern, but gets providers injected in. In this case, we ask for the ItemServiceProvider.
• At this point, we can now call functions and set values that the provider exposes.
We are able to the call the disableDefaultItems function that we defined in the
provider.
• The config function could also set up URL endpoints, locale information, routingconfiguration for our application, and so on: things that need to be executed and initialized before our application starts.
• We can try changing the value of shouldHaveDefaults to true (this would come from the server or URL, or some other way usually) to see the effect it has on ourapplication.
Directives :
AngularJS directives are what controls the rendering of the HTML inside an AngularJS application.
myapp = angular.module("myapp", []);
myapp.directive('div', function() {
var directive = {};
directive.restrict = 'E'; /* restrict this directive to elements */
directive.template = "My first directive: {{textToInsert}}";
return directive;
});
$watch()
The $scope.watch() function creates a watch of some variable. When you register a watch you pass two functions as parameters to the $watch() function:
- A value function
- A listener function
Here is an example:
$scope.$watch(function() {},
function() {}
);
Thursday, March 2, 2017
Spring Interview Quetions
1. What is dependency injection and what are the advantages?
2. What is an interface and what are the advantages of making use of them in Java?
3. What is meant by “application-context” and how do you create one?
4. What is the concept of a “container” and what is its lifecycle?
5. Dependency injection using Java configuration
6. Dependency injection in XML, using constructor or setter injection
7. Dependency injection using annotations (@Component, @Autowired)
8. Component scanning, Stereotypes and Meta-Annotations
9. Scopes for Spring beans. What is the default?
10. What is an initialization method and how is it declared in a Spring bean?
11. What is a destroy method, how is it declared and when is it called?
12. What is a BeanFactoryPostProcessor and what is it used for?
13. What is a BeanPostProcessor and how is the difference to a
14. BeanFactoryPostProcessor? What do they do? When are they called?
15. Are beans lazily or eagerly instantiated by default? How do you alter this behavior?
16. What does component-scanning do?
17. What is the behavior of the annotation @Autowired with regards to field injection,
18. constructor injection and method injection?
19. How does the @Qualifier annotation complement the use of @Autowired?
20. What is the role of the @PostConstruct and @PreDestroy annotations? When will they get called?
22. What is a proxy object and what are the two different types of proxies Spring can
create?
24. What is the power of a proxy object and where are the disadvantages?
25. What are the limitations of these proxies (per type)?
26. How do you inject scalar/literal values into Spring beans?
27. How are you going to create a new instance of an ApplicationContext?
28. What is a prefix?
29. What is the lifecycle on an ApplicationContext?
30. What does the "@Bean annotation do?
31. How are you going to create an ApplicationContext in an integration test or a JUnit
test?
33. What do you have to do, if you would like to inject something into a private field?
34. What are the advantages of JavaConfig? What are the limitations?
35. What is the default bean id if you only use "@Bean"?
36. Can you use @Bean together with @Profile?
37. What is Spring Expression Language (SpEL for short)?
38. What is the environment abstraction in Spring?
39. What can you reference using SpEL?
40. How do you configure a profile. What are possible use cases where they might be
useful?
42. How many profiles can you have?
43. How do you enable JSR-250 annotations like @PostConstruct?
44. Why are you not allowed to annotate a final class with @Configuration
45. Why must you have a default constructor in your @Configuration annotated class?
46. Why are you not allowed to annotate final methods with @Bean?
47. What is the preferred way to close an application context?
48. How can you create a shared application context in a JUnit test?
49. What does a static @Bean method do?
50. What is a ProperyPlaceholderConfigurer used for?
51. What is @Value used for?
52. What is the difference between $ a
Subscribe to:
Posts (Atom)