January 31, 2014

VJ Andy to enter Bani-Ishq Da Kalma!

After successfully winning the hearts of millions of viewers with his amazing comic skills in Bigg Boss season 7, VJ Andy is all set to add another feather in his cap. He will soon enter in  Bani -Ishq Da Kalma.

He will play a fashion designer, who will give Bani a makeover. Though he will shoot only for a day, his stint will last for more than 3-4 episodes.

-K Himaanshu Shukla...

Copyright © 2014 - ScrutinyByKHimaanshu

January 30, 2014

TAM RATINGS: TVM(TRP) & GVT(GRP) Ratings 2014- Week 4

As per the TVT data sourced from TAM subscribers in the HSM market for Week 4 (January 21-27) of 2014, the major GECs continued to witness further fall in viewership. On the other hand, Life OK saw growth in viewership for the second straight week. Sab TV also saw gains.

Star Plus continued to see a fall in viewership for the third consecutive week in 2014 to 606 million TVTs from 626 million TVTs in Week 3.

Colors climbed back to No. 2. However, the channel has also seen degrowth in Week 4 with gross TVT of 449 million, as compared to 467 million TVTs in the previous week.

Zee TV, on the other hand, slid to the third position, garnering 441 million TVTs, down from 471 million TVTs in Week 3.

Life OK continued to see growth this week as well, garnering gross TVTs of 375 million, up from last week’s 347 million TVTs.

Sab TV also saw slight growth in viewership at 323 million TVTs from 318 million TVTs in Week 3.

Sony Entertainment TV remained at the sixth position, continuing to lose viewership this week as well. The channel registered gross TVTs of 254 million, down from 258 million in Week 3.

GVTs Channel Wise :-
  • Star Plus 606361 (625772)
    Colors 449428 (466690)
    Zee TV 441168 (470680)
    Life OK 375025 (347326)
    SAB 323148 (318311)
    Sony 253722 (257635)
    Sahara One 36351 (35959) 

  • Iss Pyaar Ko Kya Naam Doon 2.9 (3.0 )
  • Ek Ghar banauga : 4.2 (4.3)
  • Saath Nibhana Saatiya 9.7 (10.4)
  • Saraswatichandra 5.9 (5.8)
  • Meri Bhabhi 4.9(5.4)
  • Mahabharat 7.0 (7.7)
  • Diya Aur Baati Hum  13.3 ( 13.5)
  • Yeh Rishta Kya Kehla Hai 8.2 (8.8)
  • Pyaar Ka Dard 6.4 (6.5)
  • Veera 5.8  (5.1)
  • Yeh Hai Mohabbatein 3.8(3.8)
  • Arjun:1.7 (2.0)
  • Nach Baliye:3.7 (4.4 )
  • Star Verdict: 1.3(1.4)
  • Koffee With Karan-4  0.7 (0.9)
    • India’s Got Talent 6.9 (  7.9 TVM ). 
    • Comedy Nights with Kapil 10.1 (11.0 ).
    • Beintehaa 2.9 (2.8) ,
    • Rang Rasiya 2.8 (2.7 )
    • Balika Vadhu 7.2 (6.3),
    • Sasural Simar Ka  6.2  (5.9) ,
    • Madhubala  4.0 (3.5), 
    • Bani 3.4 (3.3), 
    • Sanskar 1.8 (1.8 )
    Zee TV:-
    • Aur Pyaar Ho Gaya ( M-F , 10 pm ) rates 3.9 ( 3.6 TVM ).
      Jodha Akbar  10.1 (9.8),
      EK Muthhi Aasman 3.6 (3.8 ),
      Sapne Suhane Ladakpan Ke 5.9 ( 6.4 ),
      Do Dil Bandhe Ek Dori se  5.1 ( 5.5 ), 
      Pavitra Ristha  5.2 (5.1),
      Qubool Hai  6.2 (5.9),
      Doli Armanon Ki 3.0 (3.1)  ,
      DID   3.5 (5.4), 
      Ba Se Badhe  1.7 ( 1.9).
       Life OK:-
      • Hatim continues to rate high at  4.9 (4.8 TVM).
      • Shapath  moves up to 5.0 ( 4.0 )
      • Mahadev 3.3 (3.3),
      • Tumhari Pakhi 2.4 ( 2.4 ),
      • Ek Boond Ishq 2.7 (2.7),
      • Gustak DIl 2.4 ( 2.8),
      • Do Dil Ek Jaan 1.2 (1.2),
      • Savdhan India  2.9 ( 3.3)

      SAB TV :-
      • Tarak Mehta 9.0 (8.8),
      • Sab Khelo Sab Jeeto 2.2 ( 2.2),
      • Chidiya Ghar 4.2 (4.3),
      • Jeanie Aur Juju 2.3 (2.3),
      • Baal Veer 3.3 (3.3),
      • FIR 2.1 (2.0),
      • Laapataganj 2.2 ( 2.1)
      • Main Na Bhulungi 1.1 (1.1) .
      • Ek Nayi Pehchaan 2.3 (2.1).  
      • Boogie Woogie drops to  2.1 ( 2.7),
      • Desh Ki Beti Nandini 1.4 ( 1.6),
      • Crime Patrol  3.6 (3.4),
      • CID 4.4 (4.5),
      • Maharana Patap  3.1 ( 3.5 )
      • Jee Le Jara  1.6 ( 1.7 ).
      • All ratings are mentioned in TVMs (Television Viewership in Millions )
      • TRP= TVM/2
      -K Himaanshu Shukla...

      Copyright © 2014 - ScrutinyByKHimaanshu

      How to get a machine serial number from Java?

      import java.util.Scanner;
      public class GetMachineSerialNumber
          public static void main(String[] args)
                  Process process = Runtime.getRuntime().exec(new String[] { "wmic", "bios", "get", "serialnumber" });
                  Scanner sc = new Scanner(process.getInputStream());
                  String property = sc.next();
                  String serialnum = sc.next();
                  System.out.println(property + ": " + serialnum);
              catch (Exception e)

       OUTPUT: SerialNumber: L908230

      January 29, 2014

      How to fetch Mac ID of Client machine using Java Applet in a web based application?

      1). You need to download "java-plugin-
      2). Create a Java Project "GetClientMacID". Project Structure will look like this:

      3). Create a Java Applet "MacIDFinder"

      import java.applet.Applet;
      import java.net.NetworkInterface;
      import java.net.SocketException;
      import java.util.ArrayList;
      import java.util.Enumeration;
      import netscape.javascript.JSObject;

      public class MacIDFinder extends Applet
          public static String sep = ":";

          public static String getMacFromInterface(NetworkInterface ni) throws SocketException
              byte mac[] = ni.getHardwareAddress();
              if (mac != null)
                  StringBuilder macAddress = new StringBuilder("");
                  String sep = "";
                  for (byte o : mac)
                      macAddress.append(sep).append(String.format("%02X", o));
                      sep = ":";
                  return macAddress.toString();
              return "";

          public static String[] getInterfaces()
                  Enumeration nis = NetworkInterface.getNetworkInterfaces();
                  ArrayList result = new ArrayList();
                  while (nis.hasMoreElements())
                      NetworkInterface ni = nis.nextElement();
                      if (ni.isUp() && !ni.isLoopback() && !ni.isVirtual()) {
                          String mac = getMacFromInterface(ni);
                          String str = mac;//ni.getDisplayName() + ";" + mac;
                  return result.toArray(new String[0]);
              catch (Exception e)
              return new String[0];
          public static String getInterfacesJSON() {
                  String macs[] = getInterfaces();

                  String sep = "";
                  StringBuilder macArray = new StringBuilder("");
                  for (String mac : macs)
                      sep = "','";

                  return macArray.toString();
              catch (Exception e)
              return "[]";
          public static void setSep( String sep )
              try {
                  MacIDFinder.sep = sep;
              } catch( Exception ex ) {          
          public void start()
              JSObject window = JSObject.getWindow(this);
              String macid=getInterfacesJSON();
              System.out.println( "Mac ID Of Client is: " + macid );
              window.call("setMacAddress", new Object[] {macid})   ;

      4).  Now create a "build.xml"  file:

          <target name="clean">
              <delete dir="build"/>

          <target name="compile">
              <mkdir dir="build"/>
              <javac srcdir="." destdir="build" classpath="./java-plugin-"/>

          <target name="jar">
              <mkdir dir="build"/>
              <jar destfile="build/macidfinder.jar" basedir="build">
                      <attribute name="Main-Class" value="MacIDFinder"/>

          <target name="run">
              <java jar="build/macidfinder.jar" fork="true"/>

      5). Drag and drop above Build.xml on Ant View:
      6). Now execute clean, compile and jar, which will generate "macidfinder.jar" in build folder:

      7). To need to sign the jar before embedding the applet in JSP. 

      Why need to sign Java Applet? Java applets are living in a restricted environment so called “sandbox”, when it is running inside web browser. This prevents the applets from accessing system resources and devices such as files, network connections, printers, cameras, microphones, etc, without user-granted permission. This tight security is designed to make users safe from malicious code which always tries to execute automatically without user’s intervention.

      Go to the command prompt and execute below command, which will generate the key which will be used for Jar Signing:

      keytool -genkey -alias macid123 -validity 30

       Where "macid123" is test alias.  -validity 30  means your key has a validity of 30 days. if not specified the certificate that you are generating and signing has a default validity for 180 days. 

      D:\>keytool -genkey -alias macid123 -validity 30
      Enter keystore password:
       Re-enter new password:mac768
      What is your first and last name?
        [Unknown]:  K Himaanshu Shukla
      What is the name of your organizational unit?
        [Unknown]:  Scrutiny
      What is the name of your organization?
        [Unknown]:  Scrutiny
      What is the name of your City or Locality?
        [Unknown]:  Mumbai
      What is the name of your State or Province?
        [Unknown]:  Maharastra
      What is the two-letter country code for this unit?
        [Unknown]:  91
      Is CN=K Himaanshu Shukla, OU=Scrutiny, O=Scrutiny, L=Mumbai, ST=Maharastra, C=91
        [no]:  y

      Enter key password for <macid123>
              (RETURN if same as keystore password):
      Re-enter new password:mac768

      8).  To sign the jar execute the below command:
      jarsigner macidfinder.jar  macid123

      It will ask you for the password which you have specified in step 7.

      D:\>jarsigner macidfinder.jar  macid123
      Enter Passphrase for keystore: mac768
      jarsigner: unable to open jar file: macidfinder.jar

      9).  Now create a jsp in which you will be embedding the above applet:

      <applet width="50" height="50" code="MacIDFinder.class" codebase="${pageContext.request.contextPath}"  archive="
      macidfinder.jar, java-plugin-"></applet>
      <input type="hidden" id="maccid" name="maccid" />

      10).  Copy macidfinder.jar, java-plugin- in the same location where your JSP is present.

      11).  Add the below java script code in your JSP.


      setMacAddress()  will be called from the start() method of MacIDFinder from the below code:

      window.call("setMacAddress", new Object[] {macid})  ;

       setMacAddress()  java script will set the fetched Mac ID in hidden variable.

      -K Himaanshu Shukla

      Siddharth Malhotra and Varun Dhawan learned to romance from Shahrukh & Kajol

      Sidharth Malhotra and Parineeti Chopra Promoted their upcoming film 'Hasee toh Phasee' which is scheduled to release on 7th February, 2014 on 'Comedy Nights with Kapil'

      The duo had a gala time shooting with Kapil and were seen laughing throughout. The film will be the Sidharth's second film after his impressive Bollywood debut in "Student of the Year." He is also said to be looking forward to his third project, an action drama titled "The Villain" under Ekta Kapoor production. 

      While shooting for the Comedy show, Siddharth revealed that he and his Student of the Year co-star Varun Dhawan used to copy Shahrukh Khan-Kajol and learnt their romantic scenes from them.

      He said that during the shoot of My Name is Khan, he and Varun were assisting Karan Johar. And to polish their acting skills, they used to enact romantic scenes that Kajol and SRK were doing in the film. He also revealed that he and Varun were huge fans of both the actors and were in complete awe of them when they used to act.

      Copyright © 2014 - ScrutinyByKHimaanshu

      Varun Badola to play Urvashi Dholakia's husband in Jaya Bachchan's show Vasundhara!

      As we already informed Urvashi Dholakia & Vishal Singh have been finalized to play eldest bahu and middle son in Jaya Bachchan's small screen debut show. Anupam Kher is approached to play jaya's husband. Now we heard Varun Badola, who was last seen in Zee TV's popular show Phir Subah Hogi has been roped in to play the elder son. Varun has been paired opposite Urvashi.

      For those uninitiated, the show is tentatively titled Vasundhara is based on the Gujarati novel Yog Viyog (written by Kajal Oza Vaidya).

      We tried to contact Varun, but he remained unavailable for comments.

      -K Himaanshu Shukla...

       Related News:
      Click Here to read more about Jaya Bachchan's debut show Vasudhara

      Copyright © 2014 - ScrutinyByKHimaanshu

      Ashish Kapoor to enter Saraswatichandra as Gautam Rode's brother

      Actor Ashish Kapoor, who was last seen in Savitri, will soon enter in Saraswatichadra as Saras's (Gautam Rode) real brother. He will play Jaywardhan and his main motive is to take revenge from Gumaan Vyas (Monica Bedi).

      We tried to contact Ashish, but he remained unavailable for comments.

      -K Himaanshu Shukla...

      Copyright © 2014 - ScrutinyByKHimaanshu

      January 28, 2014

      Ravishing Payal Rohatgi & Pooja Misrra took the Auditions for Perfect Miss Mumbai 2014

      ‘Perfect Miss Mumbai’ (PMM) is a unique platform for the girls 18 years of age and above to jump start and dazzle in the glamour industry. Yesterday (28 January, 2014) ex-Bigg Boss contestants Payal Rohatgi & Pooja Misrra along with organizer Gurubhai Thakkar and Khooshi Thakkar took auditions for girls, who came to take part in a beauty pageant.

      The grand finale will be held on the 27th April, 2014 in Mumbai. The winner of PMM-2014 contest will bag many accolades, being the cover girl of 'Perfect Woman Magazine' is one of it.

      Copyright © 2014 - ScrutinyByKHimaanshu

      January 27, 2014

      Siddharth Malhotra and Sahil Anand cross swords for the box-office pie

      Siddharth Malhotra and Sahil Anand made their Bollywood debut with Karan Johar’s Student Of The Year. Both the actors have crossed swords for the box office pie as their second film Hasee Toh Phasee (starring Siddharth & Parineeti Chopra) and Babloo Happy Hai (starring Sahil & Erica Fernandes) are releasing on the same day.

      Says a source, “Directed by 'I Am Kalam' fame Nila Madhab Panda, Babloo Happy Hai was scheduled to release on 31st January, 2014 but now it has ended up releasing with Hasee Toh Phasee.”

      When contacted Sahil said, “Sid is a superstar and very good friend of mine. I never considered him as a rival. I am happy to know that our films are releasing on same date.

      Copyright © 2014 - ScrutinyByKHimaanshu

      January 24, 2014

      Anupam Kher to play Jaya Bachchan's husband in Sony TV's show?

      Veteran actor Anupam Kher is approached to play Jaya Bachchan's husband in tentatively titled show Vasundhara on Sony TV. The show, will be produced under Jaya Bachchan's banner is based on the Gujarati novel Yog Viyog (written by Kajal Oza Vaidya).

      According to our reliable sources, "Late Farooque Sheikh was supposed to play Jaya's husband, but due to his untimely demise Kher was approached."

      The source further added , "Talented actor Naseeruddin Shah was also approached, but he politely declined the offer as right now he is not keen in doing a TV show."

      For those uninitiated, Jaya shared screen space with Anupam in 'Laaga Chunari Mein Daag'.

      Anupam Kher remained unavailable to comment.

      -K Himaanshu Shukla...

       Related News:
      Click Here to read more about Jaya Bachchan's debut show Vasudhara

      Copyright © 2014 - ScrutinyByKHimaanshu

      Spring Interview Questions

      Q: What is Spring?
      A: Spring is an open source development framework for enterprise Java. The core features of the Spring Framework can be used in developing any Java application, but there are extensions for building web applications on top of the Java EE platform. Spring framework targets to make J2EE development easier to use and promote good programming practice by enabling a POJO-based programming model.

      Q: what are benefits of using spring?
      A: Following is the list of few of the great benefits of using Spring Framework:
      • Lightweight: Spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 2MB.
      • Inversion of control (IOC): Loose coupling is achieved in spring using the technique Inversion of Control. The objects give their dependencies instead of creating or looking for dependent objects.
      • Aspect oriented (AOP): Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services.
      • Container: Spring contains and manages the life cycle and configuration of application objects.
      • MVC Framework: Spring's web framework is a well-designed web MVC framework, which provides a great alternative to web frameworks such as Struts or other over engineered or less popular web frameworks.
      • Transaction Management: Spring provides a consistent transaction management interface that can scale down to a local transaction (using a single database, for example) and scale up to global transactions (using JTA, for example).
      • Exception Handling: Spring provides a convenient API to translate technology-specific exceptions (thrown by JDBC, Hibernate, or JDO, for example) into consistent, unchecked exceptions.
      Q: What are the different modules in Spring framework?
      A: Following are the modules of the Spring framework:
      • Core module
      • Bean module
      • Context module
      • Expression Language module
      • JDBC module
      • ORM module
      • OXM module
      • Java Messaging Service(JMS) module
      • Transaction module
      • Web module
      • Web-Servlet module
      • Web-Struts module
      • Web-Portlet module
      Q: What is Spring configuration file?
      A: Spring configuration file is an XML file. This file contains the classes information and describes how these classes are configured and introduced to each other.

      Q: What is Dependency Injection?
      A: Inversion of Control (IoC) is a general concept, and it can be expressed in many different ways and Dependency Injection is merely one concrete example of Inversion of Control.
      This concept says that you do not create your objects but describe how they should be created. You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (the IOC container) is then responsible for hooking it all up. We can say that, Dependency Injection design pattern allows us to remove the hard-coded dependencies and make our application loosely coupled, extendable and maintainable. 

      Q: What are the different types of IoC (dependency injection)?
      A: Types of IoC are:
      • Constructor-based dependency injection: Constructor-based DI is accomplished when the container invokes a class constructor with a number of arguments, each representing a dependency on other class.
      • Setter-based dependency injection: Setter-based DI is accomplished by the container calling setter methods on your beans after invoking a no-argument constructor or no-argument static factory method to instantiate your bean.
      Q: Which DI would you suggest Constructor-based or setter-based DI?
      A: Since you can mix both, Constructor- and Setter-based DI, it is a good rule of thumb to use constructor arguments for mandatory dependencies and setters for optional dependencies. Note that the use of a @Required annotation on a setter can be used to make setters required dependencies.

      Q: What are the benefits of IOC?
      A: The main benefits of IOC or dependency injection are:
      • It minimizes the amount of code in your application.
      • It makes your application easy to test as it doesn't require any singletons or JNDI lookup mechanisms in your unit test cases.
      • Loose coupling is promoted with minimal effort and least intrusive mechanism.
      • IOC containers support eager instantiation and lazy loading of services.
      Q: What is AOP?
      A: Aspect-oriented programming or AOP is one of the feature provided by Spring, actually it's not just a feature it a model of programming itself.

      Suppose we have a common procedure across different objects, e.g Log message. To implement this, we can have a logMessage() method in all the objects. But this is not really a good design, because we are repeating the same method in all the objects. What we can do, we will create a new Logger class, which has logMessage() method. All other objects will refer to the Logger object's logMessage() method to print the message.

      Now, if you are making a design diagram which depicts the relationship between all the objects and you want to know which object is an important one (by checking their relationship with other objects). In such case, the Logger will be the most important object, although it's not adding any business value.

      The problem with this approach is that there will be too many relationships to the crosscutting objects and we need to still write the code to call the logMessage() method in all the business objects. In case, we use a different log implementation, then we need to make changes in all the business objects and make the changes accordingly to call the new log method.

      All the applications have one other cross cutting concerns like logging, security or transactions. With AOP, we can remove the cross cutting concerns.

      With AOP, we will create a 'Logging Aspect' class. After creating the aspect, we do not reference it from the objects, instead we will define the 'aspect configuration' which tells to which objects or methods these aspects apply to.

      Suppose we have three business objects Partner, Vendor and Customer, each having the create() method and we need a logging mechanism while creating the Vendor and Customer. We need to do 'aspect configuration', Spring will make sure to call the logging method before creating the Vendor or a Customer. In case you decide to change the logging mechanism, all you need to make changes in 'aspect configuration'.

      We can configure aspect to run before or after a particular (target) method.

      Steps we need to take to write Aspect oriented program:

      • Write Aspects.
      • Configure where the aspects apply.
      Q: What is Spring IoC container?
      A: The Spring IoC creates the objects, wire them together, configure them, and manage their complete lifecycle from creation till destruction. The Spring container uses dependency injection (DI) to manage the components that make up an application.

      Q: What are types of IoC containers? Explain them.
      A: There are two types of IoC containers:
      • Bean Factory container: This is the simplest container providing basic support for DI .The BeanFactory is usually preferred where the resources are limited like mobile devices or applet based applications
      • Spring ApplicationContext Container: This container adds more enterprise-specific functionality such as the ability to resolve textual messages from a properties file and the ability to publish application events to interested event listeners.
      Q: Give an example of BeanFactory implementation.
      A: The most commonly used BeanFactory implementation is the XmlBeanFactory class. This container reads the configuration metadata from an XML file and uses it to create a fully configured system or application.

      Q: What are the common implementations of the ApplicationContext?
      A: The three commonly used implementation of 'Application Context' are:
      • FileSystemXmlApplicationContext: This container loads the definitions of the beans from an XML file. Here you need to provide the full path of the XML bean configuration file to the constructor.
      • ClassPathXmlApplicationContext: This container loads the definitions of the beans from an XML file. Here you do not need to provide the full path of the XML file but you need to set CLASSPATH properly because this container will look bean configuration XML file in CLASSPATH.
      • WebXmlApplicationContext: This container loads the XML file with definitions of all beans from within a web application.
      Q: What is the difference between Bean Factory and ApplicationContext?
      A: Following are some of the differences:
      • Application contexts provide a means for resolving text messages, including support for i18n of those messages.
      • Application contexts provide a generic way to load file resources, such as images.
      • Application contexts can publish events to beans that are registered as listeners.
      • Certain operations on the container or beans in the container, which have to be handled in a programmatic fashion with a bean factory, can be handled declaratively in an application context.
      • The application context implements MessageSource, an interface used to obtain localized messages, with the actual implementation being pluggable.
      Q: What are Spring beans?
      A: The objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. These beans are created with the configuration metadata that you supply to the container, for example, in the form of XML <bean/> definitions.

      Q: What does a bean definition contain?
      A: The bean definition contains the information called configuration metadata which is needed for the container to know the followings:
      • How to create a bean
      • Bean's lifecycle details
      • Bean's dependencies
      Q: How do you provide configuration metadata to the Spring Container?
      A: There are following three important methods to provide configuration metadata to the Spring Container:
      • XML based configuration file.
      • Annotation-based configuration
      • Java-based configuration
      Q: How do add a bean in spring application?
      A: Check the following example:
      <?xml version="1.0" encoding="UTF-8"?>

      <beans xmlns="http://www.springframework.org/schema/beans"

         <bean id="helloWorld" class="com.tutorialspoint.HelloWorld">
             <property name="message" value="Hello World!"/>


      Q: How do you define a bean scope?
      A: When defining a <bean> in Spring, you have the option of declaring a scope for that bean. For example, to force Spring to produce a new bean instance each time one is needed, you should declare the bean's scope attribute to be prototype. Similar way if you want Spring to return the same bean instance each time one is needed, you should declare the bean's scope attribute to be singleton.

      Q: What bean scopes does Spring support? Explain them.
      A: The Spring Framework supports following five scopes, three of which are available only if you use a web-aware ApplicationContext.
      • singleton: This scopes the bean definition to a single instance per Spring IoC container.
      • prototype: This scopes a single bean definition to have any number of object instances.
      • request: This scopes a bean definition to an HTTP request. Only valid in the context of a web-aware Spring ApplicationContext.
      • session: This scopes a bean definition to an HTTP session. Only valid in the context of a web-aware Spring ApplicationContext.
      • global-session: This scopes a bean definition to a global HTTP session. Only valid in the context of a web-aware Spring ApplicationContext.
      Q: What is default scope of bean in Spring framework?
      A: The default scope of bean is Singleton for Spring framework.

      Q: Are Singleton beans thread safe in Spring Framework?
      A: No, singleton beans are not thread-safe in Spring framework.

      Q: Explain Bean lifecycle in Spring framework?
      A: Following is sequence of a bean lifecycle in Spring:
      • Instantiate - First the spring container finds the bean's definition from the XML file and instantiates the bean..
      • Populate properties - Using the dependency injection, spring populates all of the properties as specified in the bean definition..
      • Set Bean Name - If the bean implements BeanNameAware interface, spring passes the bean's id to setBeanName() method.
      • Set Bean factory - If Bean implements BeanFactoryAware interface, spring passes the beanfactory to setBeanFactory() method.
      • Pre Initialization - Also called postprocess of bean. If there are any bean BeanPostProcessors associated with the bean, Spring calls postProcesserBeforeInitialization() method.
      • Initialize beans - If the bean implements IntializingBean,its afterPropertySet() method is called. If the bean has init method declaration, the specified initialization method is called.
      • Post Initialization - If there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called.
      • Ready to use - Now the bean is ready to use by the application.
      • Destroy - If the bean implements DisposableBean , it will call the destroy() method .
      Q: What are inner beans in Spring?
      A: A <bean/> element inside the <property/> or <constructor-arg/> elements defines a so-called inner bean. An inner bean definition does not require a defined id or name; the container ignores these values. It also ignores the scope flag. Inner beans are always anonymous and they are always scoped as prototypes. 

      Q: How can you inject Java Collection in Spring?
      A: Spring offers four types of collection configuration elements which are as follows:
      • <list>: This helps in wiring i.e. injecting a list of values, allowing duplicates.
      • <set>: This helps in wiring a set of values but without any duplicates.
      • <map>: This can be used to inject a collection of name-value pairs where name and value can be of any type.
      • <props>: This can be used to inject a collection of name-value pairs where the name and value are both Strings.
      Q: What is bean auto wiring?
      A: The Spring container is able to autowire relationships between collaborating beans. This means that it is possible to automatically let Spring resolve collaborators (other beans) for your bean by inspecting the contents of the BeanFactory without using <constructor-arg> and <property> elements.

      Q: What are different Modes of auto wiring?
      A: The autowiring functionality has five modes which can be used to instruct Spring container to use autowiring for dependency injection:
      • no: This is default setting which means no autowiring and you should use explicit bean reference for wiring. You have nothing to do special for this wiring. This is what you already have seen in Dependency Injection chapter.
      • byName: Autowiring by property name. Spring container looks at the properties of the beans on which autowire attribute is set to byName in the XML configuration file. It then tries to match and wire its properties with the beans defined by the same names in the configuration file.
      • byType: Autowiring by property datatype. Spring container looks at the properties of the beans on which autowire attribute is set to byType in the XML configuration file. It then tries to match and wire a property if its type matches with exactly one of the beans name in configuration file. If more than one such beans exist, a fatal exception is thrown.
      • constructor: Similar to byType, but type applies to constructor arguments. If there is not exactly one bean of the constructor argument type in the container, a fatal error is raised.
      • autodetect: Spring first tries to wire using autowire by constructor, if it does not work, Spring tries to autowire by byType.
      Q: What are the limitations with autowiring?
      A: Limitations of autowiring are:
      • Overriding possibility: You can still specify dependencies using <constructor-arg> and <property> settings which will always override autowiring.
      • Primitive data types: You cannot autowire so-called simple properties such as primitives, Strings, and Classes.
      • Confusing nature: Autowiring is less exact than explicit wiring, so if possible prefer using explicit wiring.
      Q: Can you inject null and empty string values in Spring?
      A: Yes.

      Q: What is Annotation-based container configuration?
      A: An alternative to XML setups is provided by annotation-based configuration which relies on the bytecode metadata for wiring up components instead of angle-bracket declarations. Instead of using XML to describe a bean wiring, the developer moves the configuration into the component class itself by using annotations on the relevant class, method, or field declaration.

      Q: How do you turn on annotation wiring?
      A: Annotation wiring is not turned on in the Spring container by default. So, before we can use annotation-based wiring, we will need to enable it in our Spring configuration file by configuring <context:annotation-config/>. 

      Q: What does @Required annotation mean?
      A: This annotation simply indicates that the affected bean property must be populated at configuration time, through an explicit property value in a bean definition or through autowiring. The container throws BeanInitializationException if the affected bean property has not been populated.

      Q: What does @Autowired annotation mean?
      A: This annotation provides more fine-grained control over where and how autowiring should be accomplished. The @Autowired annotation can be used to autowire bean on the setter method just like @Required annotation, constructor, a property or methods with arbitrary names and/or multiple arguments.

      Q: What does @Qualifier annotation mean?
      A: There may be a situation when you create more than one bean of the same type and want to wire only one of them with a property, in such case you can use @Qualifier annotation along with @Autowired to remove the confusion by specifying which exact bean will be wired. 

      Q: What are the JSR-250 Annotations? Explain them.
      A: Spring has JSR-250 based annotations which include @PostConstruct, @PreDestroy and @Resource annotations.
      • @PostConstruct: This annotation can be used as an alternate of initialization callback.
      • @PreDestroy: This annotation can be used as an alternate of destruction callback.
      • @Resource : This annotation can be used on fields or setter methods. The @Resource annotation takes a 'name' attribute which will be interpreted as the bean name to be injected. You can say, it follows by-name autowiring semantics.
      Q: What is Spring Java Based Configuration? Give some annotation example.
      A: Java based configuration option enables you to write most of your Spring configuration without XML but with the help of few Java-based annotations.
      For example: Annotation @Configuration indicates that the class can be used by the Spring IoC container as a source of bean definitions. The @Bean annotation tells Spring that a method annotated with @Bean will return an object that should be registered as a bean in the Spring application context. 

      Q: How is event handling done in Spring?
      A: Event handling in the ApplicationContext is provided through the ApplicationEvent class and ApplicationListener interface. So if a bean implements the ApplicationListener, then every time an ApplicationEvent gets published to the ApplicationContext, that bean is notified.

      Q: Describe some of the standard Spring events.
      A: Spring provides the following standard events:
      • ContextRefreshedEvent: This event is published when the ApplicationContext is either initialized or refreshed. This can also be raised using the refresh() method on the ConfigurableApplicationContext interface.
      • ContextStartedEvent: This event is published when the ApplicationContext is started using the start() method on the ConfigurableApplicationContext interface. You can poll your database or you can re/start any stopped application after receiving this event.
      • ContextStoppedEvent: This event is published when the ApplicationContext is stopped using the stop() method on the ConfigurableApplicationContext interface. You can do required housekeep work after receiving this event.
      • ContextClosedEvent: This event is published when the ApplicationContext is closed using the close() method on the ConfigurableApplicationContext interface. A closed context reaches its end of life; it cannot be refreshed or restarted.
      • RequestHandledEvent: This is a web-specific event telling all beans that an HTTP request has been serviced.
      Q: What is Aspect?
      A: A module which has a set of APIs providing cross-cutting requirements. For example, a logging module would be called AOP aspect for logging. An application can have any number of aspects depending on the requirement. In Spring AOP, aspects are implemented using regular classes (the schema-based approach) or regular classes annotated with the @Aspect annotation (@AspectJ style).

      Q: What is the difference between concern and cross-cutting concern in Spring AOP?
      A: Concern: Concern is behavior which we want to have in a module of an application. Concern may be defined as a functionality we want to implement. Issues in which we are interested define our concerns.
      Cross-cutting concern: It's a concern which is applicable throughout the application and it affects the entire application. e.g. logging , security and data transfer are the concerns which are needed in almost every module of an application, hence are cross-cutting concerns.

      Q: What is Join point?
      A: This represents a point in your application where you can plug-in AOP aspect. You can also say, it is the actual place in the application where an action will be taken using Spring AOP framework.

      Q: What is Advice?
      A: This is the actual action to be taken either before or after the method execution. This is actual piece of code that is invoked during program execution by Spring AOP framework.

      Q: What is Pointcut?
      A: This is a set of one or more joinpoints where an advice should be executed. You can specify pointcuts using expressions or patterns as we will see in our AOP examples.

      Q: What is Introduction?
      A: An introduction allows you to add new methods or attributes to existing classes.

      Q: What is Target object?
      A: The object being advised by one or more aspects, this object will always be a proxy object. Also referred to as the advised object.

      Q: What is Weaving?
      A: Weaving is the process of linking aspects with other application types or objects to create an advised object.

      Q: What are the different points where weaving can be applied?
      A: Weaving can be done at compile time, load time, or at runtime.

      Q: What are the types of advice?
      A: Spring aspects can work with five kinds of advice mentioned below:
      • before: Run advice before the a method execution.
      • after: Run advice after the a method execution regardless of its outcome.
      • after-returning: Run advice after the a method execution only if method completes successfully.
      • after-throwing: Run advice after the a method execution only if method exits by throwing an exception.
      • around: Run advice before and after the advised method is invoked.
      Q: What is XML Schema based aspect implementation?
      A: Aspects are implemented using regular classes along with XML based configuration.

      Q: What is @AspectJ? based aspect implementation?
      A: @AspectJ refers to a style of declaring aspects as regular Java classes annotated with Java 5 annotations.

      Q: How JDBC can be used more efficiently in spring framework?
      A: JDBC can be used more efficiently with the help of a template class provided by spring framework called as JdbcTemplate.

      Q: How JdbcTemplate can be used?
      A: With use of Spring JDBC framework the burden of resource management and error handling is reduced a lot. So it leaves developers to write the statements and queries to get the data to and from the database. JdbcTemplate provides many convenience methods for doing things such as converting database data into primitives or objects, executing prepared and callable statements, and providing custom database error handling. 

      Q: What are the types of the transaction management Spring supports?
      A: Spring supports two types of transaction management:
      • Programmatic transaction management: This means that you have managed the transaction with the help of programming. That gives you extreme flexibility, but it is difficult to maintain.
      • Declarative transaction management: This means you separate transaction management from the business code. You only use annotations or XML based configuration to manage the transactions.
      Q: Which of the above transaction management type is preferable?
      A: Declarative transaction management is preferable over programmatic transaction management though it is less flexible than programmatic transaction management, which allows you to control transactions through your code. 

      Q: What is Spring MVC framework?
      A: The Spring web MVC framework provides model-view-controller architecture and ready components that can be used to develop flexible and loosely coupled web applications. The MVC pattern results in separating the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements.

      Q: What is a DispatcherServlet?
      A: The Spring Web MVC framework is designed around a DispatcherServlet that handles all the HTTP requests and responses. 

      Q: What is WebApplicationContext ?
      A: The WebApplicationContext is an extension of the plain ApplicationContext that has some extra features necessary for web applications. It differs from a normal ApplicationContext in that it is capable of resolving themes, and that it knows which servlet it is associated with.

      Q: What are the advantages of Spring MVC over Struts MVC ?
      A: Following are some of the advantages of Spring MVC over Struts MVC:
      • Spring's MVC is very versatile and flexible based on interfaces but Struts forces Actions and Form object into concrete inheritance.
      • Spring provides both interceptors and controllers, thus helps to factor out common behavior to the handling of many requests.
      • Spring can be configured with different view technologies like Freemarker, JSP, Tiles, Velocity, XLST etc. and also you can create your own custom view mechanism by implementing Spring View interface.
      • In Spring MVC Controllers can be configured using DI (IOC) that makes its testing and integration easy.
      • Web tier of Spring MVC is easy to test than Struts web tier, because of the avoidance of forced concrete inheritance and explicit dependence of controllers on the dispatcher servlet.
      • Struts force your Controllers to extend a Struts class but Spring doesn't, there are many convenience Controller implementations that you can choose to extend.
      • In Struts, Actions are coupled to the view by defining ActionForwards within a ActionMapping or globally. SpringMVC has HandlerMapping interface to support this functionality.
      • With Struts, validation is usually performed (implemented) in the validate method of an ActionForm. In SpringMVC, validators are business objects that are NOT dependent on the Servlet API which makes these validators to be reused in your business logic before persisting a domain object to a database.
      Q: What is Controller in Spring MVC framework?
      A: Controllers provide access to the application behavior that you typically define through a service interface. Controllers interpret user input and transform it into a model that is represented to the user by the view. Spring implements a controller in a very abstract way, which enables you to create a wide variety of controllers.

      Q: Explain the @Controller annotation.
      A: The @Controller annotation indicates that a particular class serves the role of a controller. Spring does not require you to extend any controller base class or reference the Servlet API. 

      Q: Explain @RequestMapping annotation.
      A: @RequestMapping annotation is used to map a URL to either an entire class or a particular handler method.

      Q: What are the ways to access Hibernate by using Spring?
      A: There are two ways to access hibernate using spring:
      • Inversion of Control with a Hibernate Template and Callback.
      • Extending HibernateDAOSupport and Applying an AOP Interceptor node.
      Q: What are ORM's Spring supports ?
      A: Spring supports the following ORM's :
      • Hibernate
      • iBatis
      • JPA (Java Persistence API)
      • TopLink
      • JDO (Java Data Objects)
      • OJB

      RSSChomp Blog Directory