Wednesday, March 20, 2019

Java interview questions

Most Common Java interview questions

  • String vs StringBuffer vs StringBuilder 
  1. String : immutable 
  2. StringBuffer : mutable , synchronized
  3. StringBuilder : mutable , not tread safe .

  • Explain toString method.

getClass().getName() + '@' + Integer.toHexString(hashCode())


  • Explain hashcode

it is a native method in object Class , returns integer code .
Two unequal objects can have same hashcode


  • Explain finalize

called before Garbage Collection .
  • How to create a immutable class ?
  1. make the class as final
  2. attributes as private and remove setters .
  3. getters should return a copy of object .
  • what is transient ?
Transient attributes are not serialized .
  • What is volatile ?
Changes made by one thread is immediately reflected on other thread .

  • What is static inner class 
  1. can be accessed without creating object of outer class , does not have access to instance variables .
  • What is Stack
    LIFO 
    1. push : add element on the top of stack
    2. pop : remove element from the top of stack
    3. peek : returns element at top of stack without removing it .
  • What is Queue 
FIFO .
  1. add : adds to last , in case of capacity restriction throws IllegalStateException.
  2. remove : returns and remove the element on the top of the queue , throws NoSuchElementException if the queue is empty .
  3. element : returns the element on the top of the queue , throws NoSuchElementException if the queue is empty .
  4. offer :  adds to last , in case of capacity restriction returns false .
  5. poll: returns and remove the element on the top of the queue , returns null if the queue is empty 
  6. peek: returns  the element on the top of the queue , returns null if the queue is empty .
  • What is Dqueue ?
supports insertion and removal from both ends .
  1. push  (addFirst)  : add element on the top of stack
  2. pop : remove element from the top of stack
  3. peek : returns element at top of stack without removing it .
  4. add : adds to last , in case of capacity restriction throws IllegalStateException.
  5. remove : returns and remove the element on the top of the queue , throws NoSuchElementException if the queue is empty .
  6. element : returns the element on the top of the queue , throws NoSuchElementException if the queue is empty .
  7. offer :  adds to last , in case of capacity restriction returns false .
  8. poll: returns and remove the element on the top of the queue , returns null if the queue is empty 
  9. peek: returns  the element on the top of the queue , returns null if the queue is empty .

  • What is the difference between ArrayList and Vector?
Vector increase of capacity by double of its current capacity , ArrayList increase its capacity by 50%.
  • What is the difference between ArrayList and LinkedList ?
  1. LinkedList implements Dqueue has additional methods .
    1. decendingIterator
    2. getFirst
    3. getLast
    4. addFirst
    5. addLast
  2. Add and remove is faster , get and set is slower in LinkedList.
  3. ArrayList stores data in contiguous locations LinkedList store data using pointers and reference 
  4. LinkedList is better if we need to perform data manipulation , arrayList is better if we just want to send the data.
  • Explain Legacy collection in  java ?
All are synchronized
  1. Vector , Stack (LIFO ) :  dynamic array
  2. Dictionary (abstract) , Hashtable (concrete ), Properties ( string key and value , loaded to/from file)  :  key value pair ,null key not allowed 
  3. Enumeration : Iterate over legacy collection

  • How to make ArrayList thread safe.
  1. Use Collections.synchronizedList
  2. CopyOnWriteArrayList : can be modified during iteration but modified values will not be reflected .


  • How do HashMap handles different key with same hashcode ?
takes the hashcode of the key and check if it matches a with the hashcode of existing key . If the same hashcode exists then it compares both the keys using equals method . If both the keys are same it replaces the existing value with the new one . If both the keys does not match then it adds a new entry  in the same bucker .

  • What is BlockingQueue
Thread-safe , does not accept null value . FIFO . It is used to implement producer / consumer issues .
  1. put : add the element to the queue , if space is not available it waits for the space to be available.
  2. take : returns element from head of the queue , if no elements wait for the element to come.
  • What are the new features added in Java 7?
  1. Try with resources : the resources will be closed automatically (ARM), 
    • should implement AutoCloseable introduced in Java 7 .
    • to support ARM Suppressed Exceptions are introduced .
    • the exceptions originating at try block is propagated and the exceptions occurring in finally block is suppressed . 
    • addSuppressed and getSuppressed methods added in Throwable class
    • Closeable interface now extends AutoClosable interface .
  2. Multiple Exception in single catch separated by | . 
  3. Underscore in numeric literals
  4. Binary literals 0b,0B
  5. Switch case with string
  6.  Type interface for generic instance.using <> .
  7. Java.nio.file package : used to create, delete , copy , move etc. files and directories.
  8. @SafeVarargs : used by programmer to mark that no unsafe operations are performed in the constructor with var args .
  9. String constant pool is stored in heap instead of perm gen.

  • New features in Java 8
  1. Perm gen is removed.
  2. Functional interface
  3. Lambda support
  4. Interface default and static 
  5. For each in iterator
  6. Java stream API.
  7. Optional class : avoid null pointer
  • Explain interface default method :
  1. The implementing class does need not implement the default method.
  2. Sub interfaces can override or make it abstract .

  • Explain method reference
Static method 
Class name :: method name
Instance method
Object name:: method name


  • How does multiple inheritance issue for default method is handled .
It is mandatory for the implementing class to implement a default method in case of multiple inheritance issue .

  • What is optional class in Java 8
Pre defined action instead of throwing null pointer exception.


  • Explain functional interface

@FunctionalInterface annotation will add a compile time check for an interface to have only one abstract method. It will be used for lambda expressions.
  • Explain memory management in Java.
  1. Heap : stores object data.
  2. Permgen : stores class data ,method local initialization , string contact pool.
  3. Stack : store data required while returning from method
  • How to manage memory ?
  1. System.gc() or Runtime.gc() : garbage collector may be called .
  2. Runtime.freeMemory() : free memory 
  3. Runtime.totalMemory() : total memory available
  4. Runtime.maxMemory() : maximum memory that JVM is going to use
      • What is just in time compiler(JIT)
      converts byte code to native code to boost performance .
      • Explain Creational Design Patterns .
      1. Factory 
      2. Abstract Factory
      3. Builder : create complex object , method chaining .
      4. Singleton
      5. Prototype
      • Explain Structural Design Patter .
      1. Adapter
      2. Bridge
      3. Composite
      4. Decorator
      5. Facade
      6. Flywheel
      7. Proxy
      • Explain Behavioral Design Patter .
      1. Chain of Responsibility
      2. Command
      3. Interpretor : how to include language  elements
      4. Iterator
      5. Mediator : simplify communication between objects
      6. Observer : multiple objects notification
      7. State : modify the behavior on state change
      8. Template : abstract definition of algorithm
      9. Visitor : add polymorphic functions to class noninvasively .

      • How can we make singleton class thread safe.
      Null check for instance and creation of new object should be done inside a synchronized block.
      • What is executor service?
      It provides a pool of threads and API to assign task for it.Simplifies task execution in async mode.

      • What is Thread.yeald?
      Thread Scheduler checks if any other thread available with same or higher priority and transfer the processor to it .


      • Explain serialization

      1. Serializable interface should be implemented .
      2. Serializable is a marker interface for identification .
      3. sub class must be serializable ,  super class need not be serializable .
      4. Transient and static attributes are not serialized.
      5. readresolve method can be implemented and same instance can be returned, while deserialization of singleton class.
      6. Write replace is called before write object .

      • Explain serialVersionUID .
      1.  if it not present java compiler adds it .
      2.  it is static final and long . 
      3. It is used to check the sender and receiver are compatible if there is mismatch in the serialVersionUID InvalidClassException is thrown .
      4. If there is no serialVersionUID and we have serialized an object  , we added some field and now if we want to deserialize it we get InvalidClassException .


      • Explain Externalizable interface 
      used for custom serialization 

      1. readExternal
      2. writeExternal


      • Explain classloaders 
      they load classes during runtime dynamically .

      1. Bootstrap : parent of all , first to be loaded
      2. extension : load all classes from .jar from  java.ext.dirs
      3. system : loads the classes at java.class.path or classes specified at -classpath .

      Sunday, March 17, 2019

      Spring Interview Question

      Most Common Spring Interview Questions : This blog is just for a revision .


      • What is dependency injection ?
      Spring IoC container takes care of object creation and wiring them together.
      1. Constructor constructor-arg : for mandatory dependencies
      2. Setter ref : for optional dependencies
      3. using @Autowired
      • Types of IoC container?
      1. BeanFactory
      2. ApplicationContext
      • What are the advantages of ApplicationContext?
      1. Internationalization
      2. Annotation support
      3. Load all beans on start 
      4. lazy-init for lazy loading
      5. No need to register AutowiredBeanPostProcessor
      6. Automatic BeanPostProcessor , BeanFactoryPostProcessor registration
      7. Easy MessageSource access (for i18n)
      8. ApplicationEvent publication
      • Advantages of spring IoC ?
      1. Less code
      2. Easy testing
      3. Loose coupling
      4. Lazy loading
      • What is spring bean ?
      java class created by spring IoC container .
      • Explain Spring bean life cycle.
      1. Check the configuration
      2. Initialization
      3. Dependency Injection
      4. set bean name
      5. set bean class loader
      6. set bean factory
      7. set resource loader
      8. set application event publisher
      9. set message source 
      10. set Application Context
      11. set Servlet context
      12. postProcessBeforeInitialization
      13. afterPropertiesSet
      14. init method
      15. postProcessAfterInitialization
      16. destroy
      17. destroy
      • Explain scope of bean .
      1. singleton : default , one instance in the container 
      2. prototype : new instance every time the getBean is called
      3. request : one bean for life cycle of http request 
      4. session : one bean for life cycle of http session
      5. global session : one bean for life cycle of ServletContext
      • What is BeanPostProcessor ?
      implementation can define a callback method .
      1. postProcessBeforeInitialization  before init method
      2. postProcessAfterInitialization after init method
      • How to create ApplicationContext ?
      1. XML based :ClassPathXmlApplicationContext("xml file")
      2. Annotation based : in web-servlet.xml use  <context:component-scan base-package= > .
      3. Java based :  @Configuration ,  @Bean , @Scope, @Import , @ComponentScan
      • Explain  JSR 250  annotations used in spring .
      1. @PostConstruct : alternative to init 
      2. @PreDestroy : alternative to destroy
      3. @Resource(name ="")   : similar to @Autowired @Qualifier("") 
      • Explain other annotations in spring to be used with annotation based configuration
      1. @Required:applied on setter , the value should be provided in xml 
      2. @Component parent of annotations
        • @Controller , 
        • @Repository , 
        • @Service 
      •  Explain Autowiring .
      Enables us to inject dependency implicitly, using autowire in xml
      1. no : explicit bean references 
      2. byName : by the bean name in xml file.
      3. byType : matches the type of the bean 
      4. contructor : check the type of the parameter in constructor 
      • Explain inner bean 
      A bean used as property of another bean . A <bean> inside <property> .
      • What are the new features in Spring 4 .
      1. Added path to RequestMapping
      2. MVC test framework
      3. @RestController and AsyncRestTemplate is used.
      4. instread of response it returns ListenableFuture 
      5. uses java 8 , minimum requirement is Java 6.
      6. define external bean configuration using a Groovy
      7. Added @Description
      8. @Lazy can be used in bean injection and definition .
      9. @Autowired @Value can be used as meta annotations
      10. Introduced ordering for autowired , using @Order and Ordered interface .
      11. @Bean in @Configuration Class
      12. Conditional filtering of beans added for @Conditional .
      13. Generic type as qualifier for injecting bean
      14. create custom annotation to expose attribute of the source annotation .
      • New features added in Spring 5.
      1. bean scopes : singleton, prototype , request , session , application , websocket (one bean for lifecycle of Websocket )


      • Explain the components of Spring MVC.
      1. Dispatcher Servlet
      2. Handler Mapping
      3. Controller
      4. Model And View
      5. View Resolver
      6. View
      • Explain Dispatcher Servlet
      Front Controller for all incoming Request.
      entry added in web.xml for dispatcher servlet
        • org.springframework.web.servlet.DispatcherServlet
        • loadOnStartUp = 1
      Create {servlet-name}-servlet.xml,specify

        • context:component-scan
        • mvc:annotation-driven



      • What is handler mapping

      Dispatcher servlet checks with handler mapping and  redirects to the appropriate controller .


      • What is view resolver ?
      It determines the view to which the request has to be transferred .

      1. InternalResourceViewResolver : based on URL , suffix and prifix
      2. XmlViewResolver : view definition in  a dedicated XML .
      3. ResourceBundleViewResolver : view definition in a property file .




        • What is ServletContext ?
        One per application , created once the web application is deployed .
        To access in spring context , the controller must implement ServletContextAware   ,add either of the following code  
        1. 
        @Autowired
        ServletContext context; 

        2.
        private ServletContext context;

        public void setServletContext(ServletContext servletContext) {
            this.context = servletContext;
        }

        Methods :

        1. getInitParameter () : returns value set in <context-param> <param-name>
        • What is servletConfig?
        One per servlet

        1. getInitParameter(String name): returns value set in <init-param><name>  
        2. getInitParameterNames(): returns all <init-param>
        3. getServletContext(): returns ServletContext
        4. getServletName(): returns value set in <servlet><servlet-name>


        • What is servlet context listener ?

        gets notified when servlet context is initialized or destroyed .
        • Explain  Spring MVC annotations?
        1. @Controller : class is a web request handler 
        2. @Component : auto-detection when using annotation-based 
        3.  @RestController = @Controller + @ResponseBody
        4. @RequestMapping method: get/put value : URL
        5. @PathVariable input in request URL.
        6. @RequestParam input in url with ?id=
        7. @Transactional : can be applied to class or method.
        8. @EnableWebMvc enable spring MVC through java configuration.

        • What is WebMvcConfigurer .

        To customise web MVC configuration.
        Like add view controller
        View resolver in java code .


        • What is WebApplicationInitializer

        used to configure servlet context programmatically , used as an alternative to configuration in web.xml


        • Explain file upload in spring 
        1. use CommonsMultipartResolver add dependency commons-fileupload
        2. add bean configuration in servlet-config.xml file 
          • "multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
        3. input type = file in html
        4. @RequestParam MultipartFile
        • What is a profile

        If we want enable a bean only during development and not in production we can assign the profile to the bean , using @Profile("dev")

        • How to declare a profile ?
        1. Set the servlet context init Param using WebApplicationInitializer
        2. Set context Param in web.xml
        3. Set the JVM system parameter
        4. Set the environment variable
        5. Set in maven profile
        6.  Configurable environment set active profile
        • Explain spring events 
        1. event class should extend ApplicationEvent
        2. publish event can be done using applicationEventPublisher.publishEvent(customSpringEvent);
        3. listener has to implement ApplicationListener<MyEvent>
        4. listener need to override onApplicationEvent(MyEvent myEvent)
        • What are the events related to ApplicationContext
        1. ContextRefreshedEvent
        2. ContextStartedEvent
        3. ContextStoppedEvent
        4. ContextClosedEvent
        • What is Join Point ?
        An event occurred during the execution of a program.
        1. method called 
        2. state changed
        3. exception occurred 
        • What is an Point Cut ?
        an expression
        • What is an advice ?
        Action taken (method ).
        1. before
        2. after
        3. around : decides whether the method gets executed or not
        4. afterReturning :executed only if method executed successfully .
        5. afterThrowing : executed only if exception is occurred during method execution .
        • What is aspect ?
        class that implements cross cutting concerns .
        1. logging
        2. security
        3. transaction management
        4. exception handling
        5. performance testing
        • What is weaving?
        Linking aspect with other objects/application types to create adviced object.
        • What is proxy?
        Object created after applying advice to target object.


        • What are the features of spring boot?
        1. Auto configuration : configure beans based on the jar available at classpath  and beans used in the project . Annotations used : @ConditionalOnClass, @ConditionalOnMissingBean .
        2. Starters project
        3. Cli using groovy
        4. Actuator
        5. Initializer

        • Explain Spring Boot Annotations
        1. @SpringBootApplication 
        2. @EnableAutoConfiguration
        • What is Spring Boot Initilizr ?
        It is used to generate a new project .


        • What is Spring Boot Actuator
        adds production grade services to the application

        1. info
        2. health : up
        3. trace
        4. httptrace

        • How do you create Logger in Spring boot .
        org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(MyClass.class);
        configure logger level , file path , pattern console profile in application.properties
        create logback.xml



        Friday, March 15, 2019

        Angular interview Questions





        Most Common Angular Interview Questions :


        • What is Angular  ?
        Client Side Framework based on node js and typescript


        • What are the building blocks of Angular ?
        Component , Template , Service , Dependency Injection , Data binding , Routing , Module


        • How does Angular Application starts ?

        main.ts -> platformBrowserDynamic().bootstrapModule(AppModule) -> AppModule

        • What is a component ?
        Basic building block , it has template which is loaded on using the selector .


        • What is a template ?
        it is the html part of component .
        Two types are there
        1. within the component.ts enclosed in back tick
        2. in a separate html file .


        • How to style a component ?
        Three ways : 1. inside the component.ts using style
        2. in a separate css using styleUrl
        3 . multiple css files can be included using styles [] .

        • What is providers for component ?
        It specifies the Services to be used in the component .
        • Explain model to view binding ?
        Two ways : {{}} Interpolation : variables defined in component can be used in template .
        [] property binding : a known property of html element is bound to a variable defined in component .


        • Explain view to model binding ?
        using () : event binding : binds an event to method defined in component .


        • Explain two way binding ?
        using [()] : it is a combination of event binding and property binding , it synchronizes the data between model and view . 
        eg : <input [(ngModel)] = "myInput" > <span >you entered {{myInput}} </span>


        • What is a module ?
        Module groups related components , services , directives and pipes .
        4 Parts :
        1. declarations [] : list of components , pipes and directives
        2. imports [] : list of modules , used to import routes
        3. providers [] : list of services
        4. bootstrap : the root component that Angular creates and inserts into the index.html.


        • What is a root module ?
        The module loaded on start of the app . This imports BrowserModule  . Only one per app .

        • What are directives ?
        Add to the DOM .
        3 Types :
        Components :directives with template.
        Structural :  add / remove DOM elements. *ng-if , *ng-for
        Attribute  : change the appearance or behavior of an element, component, or another directive. Eg : ngClass

        • How to create custom attribute directive ?
        using @Directive , in the constructor we can access the native element from ElementRef.nativeElement , using which we can manipulate the DOM.
        we can also use @Input to get the input in the specified property .


        • How to create custom structural directive ?
        using @Directive , inject ViewContainerRef and TemplateRef , in ngOnChanges()  using this.container.createEmbeddedView  .



        • How to pass data from parent and child component ?
        Using @Input on a property in child component and pass the data to property in while it is called in parent component .


        • How to pass data from child to parent component ?
        1.  Using @ViewChild(Component class) add to a variable of Child component in parent  component  
        2.  Using @Output and EventEmitter .eg :  @Output() voted = new EventEmitter<boolean>();            this.voted.emit(agreed);
        Note: EventEmitter is subclass of Observable .
        • How to pass data between unrelated component ?
        Using a service , create a variable as BehaviorSubject type , another variable as observable for the variable  and a method to change the value . Subscribe the observable in both components , if value is changed from one component it will be reflected in other component .
        • What is LifeCycle hook?
        For a component Angular creates it, renders it, creates and renders its children, checks it when its data-bound properties change, and destroys it before removing it from the DOM. 
        1. ngOnChanges()
        2. ngOnInit()
        3. ngDoCheck()
        4. ngAfterContentInit()
        5. ngAfterContentChecked()
        6. ngAfterViewInit()
        7. ngAfterViewChecked()
        8. ngOnDestroy() 
        Before these methods the constructor is called .
        • What is a service ?
        It is used to perform a task , like http put or get .


        • What is dependency Injection ?
        Angular creates instance of all  the services and makes it available for the component . Services are singleton .

        1. constructor injection :dependencies are made available through constructor 
        2. property injection :directly setting the object property .
        • What is @optional
        For optional dependencies , injector will inject null if dependencies are not found.
        • What is injector?
        resolves token into dependency .

        • Explain   Hierarchical injector.
        tree of injectors that parallels an app's component tree
        • What is a provider ?

        is an instruction to the DI system on how to obtain a value for a dependency .
        • What is view provider
        does not allow content be injected in the projected content
        • How to create a service ?
        using @Injectible

        • When to use @providedin : root ?
        when service is used anyway , if service is rarely used specify the service in provider [] of component .providedIn can also hold any module other than root .
        • What is routing?
        Loading of components based on URL .
        • How to add routing to an angular app?
        Create Routes[] in module , in imports add RouterModule.forRoot(appRoutes).Add router-outlet where the component should be loaded.
        • What is RouterLink directive ?
        generates hyperlink that can be embedded in anchor tags for navigation .
        • What is redirectTo ?
        It is used to match a wildcard and redirect to a different URL . The component associated with the redirected URL will be loaded .

        • What is useHash:true
        enables hash(#) based routing .
        • What is Routing module?

        AppRoutingModule is top level module dedicated for routing .In the ng module exports: [ RouterModule ]


        • What is a feature module ?

        Contains a group of components, directives pipes  with similar features  and imported in root module .
        • What is lazy routing ?

        Root module should be split into feature module and a routing module . Feature modules can have its own routing module . RouterModule.forRoot() is used in the app Routing Module and RouterModule.forChild() is used in the Routing Module of feature module . In the app routing module loadChildren is used instead of component .

        • What is route Guards ?
        tells the router whether or not to navigate to the requested route 
        CanActivate
        CanActivateChild
        CanDeactivate
        CanLoad
        Resolve
        • What is form ?
        Handles user data . 2 Types :
        1. Template driven :
        2. Model Driven /Reactive
        • Explain Template driven form .
        Used for the following :

        1.  two-way data binding : ngModel , ngModelGroup
        2.  change tracking: pristine, dirty , valid 
        3.  validation : required  , pattern , minlength 
        4.  error handling  *ngIf

        • Explain Model Driven / reactive Forms .


        Using ReactiveFormsModule
        1. FormGroup FormControl
        2. FormBuilder
        3. FormArray



        • How to create a custom validator ?


        Create a typescript class with a method
        Add it in formbuilder . Group method for the name



        • What is shadow DOM?
        provides hidden area on the page for scripts HTML and CSS . Markup and styles in this area will not affect the other part of the page also will not be affected by other  part .
        • What is view encapsulation ?
        Added to a component using encapsulation attribute .
        1. ViewEncapsulation.Native : lets angular to use the shadow DOM . isolates the component , default styles will not be applied to this component . 
        2. ViewEncapsulation.Emulated : applied by  default 
        3. ViewEncapsulation.None : the styles defined for this component is applied to all other component .
        • Diffentiate observable and promise.
        1. Promise is executed immediately, observable is lazy and executes only if it is subscribed.
        2. Observable can be cancelled, promise can't.
        3. Promise handles single event , observable is a stream and allows multiple events.
        • What is async pipe?
        It allows to bind with the observable directly in the template.
        The advantage of using AsyncPipe is that we don’t need to call subscribe on our observable and store the intermediate data on our component.
        • How to create a promise .
        Promise handles single event when async operation completes or fails
        let promise = new Promise((resolve, reject) => {
            //http call 
          });
        return promise;
        •  What is transpilation ?
        Convert from one type of source code to another type of source code .

        1. Build time : takes the type script files and compiles it to javascript files 
        2. Runtime : happens at the browser at runtime . Typescript compiles is loaded in the browser which compiles the typescript files on the fly .


        • What is webpack?
        A tool to bundle application source code and load that code from server to browser .

        • What are the special characters in angular ?
        1. [] : property binding 
        2. {{}} : interpolation
        3. () : event binding
        4. [()] : two way binding 
        5. | : pipe
        6. * : structural directive
        7. ?  : safe navigation 
        8. # : template reference variable 
        • Explain folders in angular project ?
        1. e2e : contain end to end tests
        2. src : application code
        3. assets : static content like images .
        4. environments : configuration for developer and production environments .
        • Explain the important files in Angular .
        1. package.json
        2. angular.json
        3. main.ts
        4. tslint.json
        5. tsconfig.app.json
        6. proxyconfig.json
        • How do you change the path of node_modules?
        • What are the symbols ~ and ^ in node modules 
        • How do you build your application for production
        ng build --prod
        the bundles will be generated in dist folder

        • What are polyfils
        Polyfil scripts should be loaded for angular application to work on the supported browser .
        • Explain angular binding Construct .
        1. Interpolation
        2. property binding
        3. attribute binding
        4. class binding
        5. style binding
        6. event binding
        • What is XHR ?
        XML Http Request built in object in browser to request data from server .

        • How does angular safegaurd the app against XSS attacks ?
        Cross side scripting is injecting malicious code in web pages gain access and steal data .Sanitization : Inspection of untrusted value and turing it value that is safe to insert in DOM. Security Constructs are as below

        1. HTML 
        2. style
        3. URL
        4. resource URL
        • What is DomSanitizer ?
        helps preventing the cross side .
        1. Sanitize :
        2. bypassSecurityTrustHtml
        3. bypassSecurityTrustScript
        4. bypassSecurityTrustStyle
        5. bypassSecurityTrustUrl
        6. bypassSecurityTrustResourceUrl

        • How does hot reloading works internally?



        Saturday, March 2, 2019

        ERROR Error: Found the synthetic property @transitionMessages.

        Hi Guys ,

        Today I have faced this error :

        ERROR Error: Found the synthetic property @transitionMessages.

        The fix is to add the following modules to your ng module file .

        ------------app.module.ts---------------------------------------------------------

        import { BrowserModule } from '@angular/platform-browser';
        import { NgModule } from '@angular/core';
        import { AppComponent } from './app.component';
        import { HttpModule } from '@angular/http';
        import {MatSelectModule} from '@angular/material/select';
        import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

        const appRoutes:Routes =[
        {path:'cust-detail',component: CustDetailComponent},
        {path:'mcq',component: MCQComponent},
        {path:'sign-up',component: SignUpComponent}
        ];

        @NgModule({
          declarations: [
            AppComponent,
            CustDetailComponent,
            MCQComponent,
            SignUpComponent
          ],
          imports: [
            BrowserModule,
        FormsModule,
        MatSelectModule,
        BrowserAnimationsModule
          ],
          providers: [QuizServiceService],
          bootstrap: [AppComponent]
        })
        export class AppModule { }

        ----------------------------------------------------------------------------------------
        This error comes if you are using mat-select and mat-option . This is required module so we need to import it to make the select functionality work .

        The full stack trace is as below :


        ERROR Error: Found the synthetic property @transitionMessages. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application.
            at checkNoSyntheticProp (platform-browser.js:1141)
            at DefaultDomRenderer2.push../node_modules/@angular/platform-browser/fesm5/platform-browser.js.DefaultDomRenderer2.setProperty (platform-browser.js:1125)
            at DebugRenderer2.push../node_modules/@angular/core/fesm5/core.js.DebugRenderer2.setProperty (core.js:11505)
            at setElementProperty (core.js:8261)
            at checkAndUpdateElementValue (core.js:8212)
            at checkAndUpdateElementInline (core.js:8159)
            at checkAndUpdateNodeInline (core.js:10503)
            at checkAndUpdateNode (core.js:10469)
            at debugCheckAndUpdateNode (core.js:11102)
            at debugCheckRenderNodeFn (core.js:11088)
        View_MatFormField_10 @ MatFormField.html:1
        push../node_modules/@angular/core/fesm5/core.js.DebugContext_.logError @ core.js:11306
        push../node_modules/@angular/core/fesm5/core.js.ErrorHandler.handleError @ core.js:1719
        (anonymous) @ core.js:4578
        push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:391
        push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:150
        push../node_modules/@angular/core/fesm5/core.js.NgZone.runOutsideAngular @ core.js:3779
        push../node_modules/@angular/core/fesm5/core.js.ApplicationRef.tick @ core.js:4578
        (anonymous) @ core.js:4462
        push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:391
        onInvoke @ core.js:3820
        push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:390
        push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:150
        push../node_modules/@angular/core/fesm5/core.js.NgZone.run @ core.js:3734
        next @ core.js:4462
        schedulerFn @ core.js:3551
        push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:196
        push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next @ Subscriber.js:134
        push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next @ Subscriber.js:77
        push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next @ Subscriber.js:54
        push../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next @ Subject.js:47
        push../node_modules/@angular/core/fesm5/core.js.EventEmitter.emit @ core.js:3535
        checkStable @ core.js:3789
        onHasTask @ core.js:3833
        push../node_modules/zone.js/dist/zone.js.ZoneDelegate.hasTask @ zone.js:443
        push../node_modules/zone.js/dist/zone.js.ZoneDelegate._updateTaskCount @ zone.js:463
        push../node_modules/zone.js/dist/zone.js.Zone._updateTaskCount @ zone.js:291
        push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:212
        drainMicroTaskQueue @ zone.js:601
        Promise.then (async)
        scheduleMicroTask @ zone.js:584
        push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:413
        push../node_modules/zone.js/dist/zone.js.Zone.scheduleTask @ zone.js:238
        push../node_modules/zone.js/dist/zone.js.Zone.scheduleMicroTask @ zone.js:258
        scheduleResolveOrReject @ zone.js:879
        ZoneAwarePromise.then @ zone.js:1012
        push../node_modules/@angular/core/fesm5/core.js.PlatformRef.bootstrapModule @ core.js:4345
        ./src/main.ts @ main.ts:11
        __webpack_require__ @ bootstrap:76
        0 @ main.ts:12
        __webpack_require__ @ bootstrap:76
        checkDeferredModules @ bootstrap:43
        webpackJsonpCallback @ bootstrap:30
        (anonymous) @ main.js:1

        ERROR in node_modules/rxjs-compat/operator/shareReplay.d.ts(2,10): error TS2305:

        Hi Guys ,

        Today I have faced this error :


        ERROR in node_modules/rxjs-compat/operator/shareReplay.d.ts(2,10): error TS2305:



        You will face this error if you are using "rxjs-compat": "^6.4.0", in package .json .

        To fix set the version of rxjs and rxjs-compat as below .

        ---------------------package.json--------------------------------

        "rxjs": "6.3.3",
            "rxjs-compat": "6.3.3"

        ----------------------------------------------------------------------

        update to package.json needs npm update
        ng serve , it works !

        The full stack trace is as below :


        ERROR in node_modules/rxjs-compat/operator/shareReplay.d.ts(2,10): error TS2305: Module '"F://study/angular4/projects/mcq/mcq/node_modules/rxjs/internal-compatibility/index"' has no exported member 'ShareReplayConfig'.





        Friday, March 1, 2019

        ERROR in node_modules/rxjs/Observable.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Observable'.

        Hi Guys ,

        Today I have faced this error :


        ERROR in node_modules/rxjs/Observable.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Observable'.


        I faced this error since i didn't installed material module. Here's the solution if you face the same  issue.
        Go to the command prompt and type the following command:

        npm install --save rxjs-compat 

        Once installed ng serve,it should work.


        The full stack trace is as below :



        ERROR in node_modules/rxjs/Observable.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Observable'.
        node_modules/rxjs/Rx.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat'.
        src/app/quiz-service.service.ts(4,10): error TS2305: Module '"F:/shahbaz/study/angular4/projects/mcq/mcq/node_modules/rxjs/Observable"' has no exported member 'Observable'.
        src/app/quiz-service.service.ts(14,5): error TS2339: Property 'map' does not exist on type 'Observable<Response>'.

        ERROR Error: Found the synthetic property @transitionMessages. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application.

        Hi Guys ,

        Today I have faced this error :



        ERROR Error: Found the synthetic property @transitionMessages. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application.


        The solution is to add  in the @Component annotation use animations: [ <specify your Animation Method here> ]


        ec2-user@ec2 Permission denied