18 June, 2014

Whats New in Java 8 ?

Java Platform, Standard Edition 8 is a major feature release in brief.
  • Java Programming Language
    • Lambda Expressions, a new language feature, has been introduced in this release. They enable you to treat functionality as a method argument, or code as data. Lambda expressions let you express instances of single-method interfaces (referred to as functional interfaces) more compactly.
    • Method references provide easy-to-read lambda expressions for methods that already have a name.
    • Default methods enable new functionality to be added to the interfaces of libraries and ensure binary compatibility with code written for older versions of those interfaces.
    • Repeating Annotations provide the ability to apply the same annotation type more than once to the same declaration or type use.
    • Type Annotations provide the ability to apply an annotation anywhere a type is used, not just on a declaration. Used with a pluggable type system, this feature enables improved type checking of your code.
    • Improved type inference.
    • Method parameter reflection.
  • Collections
    • Classes in the new java.util.stream package provide a Stream API to support functional-style operations on streams of elements. The Stream API is integrated into the Collections API, which enables bulk operations on collections, such as sequential or parallel map-reduce transformations.
    • Performance Improvement for HashMaps with Key Collisions.
  • Compact Profiles contain predefined subsets of the Java SE platform and enable applications that do not require the entire Platform to be deployed and run on small devices.
  • Security
    • Client-side TLS 1.2 enabled by default
    • New variant of AccessController.doPrivileged that enables code to assert a subset of its privileges, without preventing the full traversal of the stack to check for other permissions
    • Stronger algorithms for password-based encryption
    • SSL/TLS Server Name Indication (SNI) Extension support in JSSE Server
    • Support for AEAD algorithms: The SunJCE provider is enhanced to support AES/GCM/NoPadding cipher implementation as well as GCM algorithm parameters. And the SunJSSE provider is enhanced to support AEAD mode based cipher suites. See Oracle Providers Documentation, JEP 115.
    • KeyStore enhancements, including the new Domain KeyStore type java.security.DomainLoadStoreParameter, and the new command option -importpassword for the keytool utility
    • SHA-224 Message Digests
    • Enhanced Support for NSA Suite B Cryptography
    • Better Support for High Entropy Random Number Generation
    • New java.security.cert.PKIXRevocationChecker class for configuring revocation checking of X.509 certificates
    • 64-bit PKCS11 for Windows
    • New rcache Types in Kerberos 5 Replay Caching
    • Support for Kerberos 5 Protocol Transition and Constrained Delegation
    • Kerberos 5 weak encryption types disabled by default
    • Unbound SASL for the GSS-API/Kerberos 5 mechanism
    • SASL service for multiple host names
    • JNI bridge to native JGSS on Mac OS X
    • Support for stronger strength ephemeral DH keys in the SunJSSE provider
    • Support for server-side cipher suites preference customization in JSSE
  • JavaFX
    • The new SwingNode class enables developers to embed Swing content into JavaFX applications. See the SwingNode javadoc and Embedding Swing Content in JavaFX Applications.
    • The new UI Controls include the DatePicker and the TreeTableView controls.
    • The javafx.print package provides the public classes for the JavaFX Printing API. See the javadoc for more information.
    • The WebView class provides new features and improvements. Review Supported Features of HTML5 for more information about additional HTML5 features including Web Sockets, Web Workers, and Web Fonts.
    • Enhanced text support including bi-directional text and complex text scripts such as Thai and Hindi in controls, and multi-line, multi-style text in text nodes.
    • Support for Hi-DPI displays has been added in this release.
    • The CSS Styleable* classes became public API. See the javafx.css javadoc for more information.
    • The new ScheduledService class allows to automatically restart the service.
    • JavaFX is now available for ARM platforms. JDK for ARM includes the base, graphics and controls components of JavaFX.
  • Tools
    • The jjs command is provided to invoke the Nashorn engine.
    • The java command launches JavaFX applications.
    • The java man page has been reworked.
    • The jdeps command-line tool is provided for analyzing class files.
    • Java Management Extensions (JMX) provide remote access to diagnostic commands.
    • The jarsigner tool has an option for requesting a signed time stamp from a Time Stamping Authority (TSA).
    • Javac tool
      • The -parameters option of the javac command can be used to store formal parameter names and enable the Reflection API to retrieve formal parameter names.
      • The type rules for equality operators in the Java Language Specification (JLS) Section 15.21 are now correctly enforced by the javac command.
      • The javac tool now has support for checking the content of javadoc comments for issues that could lead to various problems, such as invalid HTML or accessibility issues, in the files that are generated when javadoc is run. The feature is enabled by the new -Xdoclint option. For more details, see the output from running "javac -X". This feature is also available in the javadoc tool, and is enabled there by default.
      • The javac tool now provides the ability to generate native headers, as needed. This removes the need to run the javah tool as a separate step in the build pipeline. The feature is enabled in javac by using the new -h option, which is used to specify a directory in which the header files should be written. Header files will be generated for any class which has either native methods, or constant fields annotated with a new annotation of type java.lang.annotation.Native.
    • Javadoc tool
      • The javadoc tool supports the new DocTree API that enables you to traverse Javadoc comments as abstract syntax trees.
      • The javadoc tool supports the new Javadoc Access API that enables you to invoke the Javadoc tool directly from a Java application, without executing a new process. The javadoc tool now has support for checking the content of javadoc comments for issues that could lead to various problems, such as invalid HTML or accessibility issues, in the files that are generated when javadoc is run. The feature is enabled by default, and can also be controlled by the new -Xdoclint option. For more details, see the output from running "javadoc -X". This feature is also available in the javac tool, although it is not enabled by default there.
  • Internationalization
    • Unicode Enhancements, including support for Unicode 6.2.0
    • Adoption of Unicode CLDR Data and the java.locale.providers System Property
    • New Calendar and Locale APIs
    • Ability to Install a Custom Resource Bundle as an Extension
  • java.lang and java.util Packages
    • Parallel Array Sorting
    • Standard Encoding and Decoding Base64
    • Unsigned Arithmetic Support
  • JDBC
    • The JDBC-ODBC Bridge has been removed.
  • Networking
    • The class java.net.URLPermission has been added.
    • In the class java.net.HttpURLConnection, if a security manager is installed, calls that request to open a connection require permission.
  • Concurrency
    • Classes and interfaces have been added to the java.util.concurrent package.
    • Methods have been added to the java.util.concurrent.ConcurrentHashMap class to support aggregate operations based on the newly added streams facility and lambda expressions.
    • Classes have been added to the java.util.concurrent.atomic package to support scalable updatable variables.
    • Methods have been added to the java.util.concurrent.ForkJoinPool class to support a common pool.
    • The java.util.concurrent.locks.StampedLock class has been added to provide a capability-based lock with three modes for controlling read/write access.
  • HotSpot
    • Removal of PermGen.
    • Default Methods in the Java Programming Language are supported by the byte code instructions for method invocation.
  • Java Mission Control 5.3 Release Notes
    • JDK 8 includes Java Mission Control 5.3.

17 June, 2014

Accenture Java Interview Questions & Answers

Accenture interview question for Java 3-8 year experience .

  




Q1. Why do you want to work in this industry / company?


Ans: First you should try to convince that this company gives huge opportunity in many aspect i.e. new technologies implementation, the policy of company suits you like professionalism.   Also you can mention that you are big fan of this company and its your dream company. Basically show your all positive attitude towards company.


Q2. Which location do you want to work in and why?


Ans : Give your own choice. Also mention a valid reason for why you are interested for that location. The reason should be always positive and clear. Example :- you can support your family from this location,

Q3. Describe a problem you faced and how you deal with it ?


Ans : You can describe any issue you faced during your project work in the organization. And what the solution you have implemented for that issue.

Q4. What are the types of class loaders in Java?


Ans  :  As per my knowledge there are basically 3 types of class loader like bootstarp classloader,extension class loader and system class loader.
  • Bootstrap Class Loader
    Bootstrap class loader loads java’s core classes like java.lang, java.util etc. These are classes that are part of java runtime environment. Bootstrap class loader is native implementation and so they may differ across different JVMs.
  •  Extensions Class Loader
    JAVA_HOME/jre/lib/ext contains jar packages that are extensions of standard core java classes. Extensions class loader loads classes from this ext folder. Using the system environment propery java.ext.dirs you can add ‘ext’ folders and jar files to be loaded using extensions class loader
  • System Class Loader
                  Java classes that are available in the java classpath are loaded using System class loader

Q5. Write your own ArrayList in Java ?

      Your own code here .

Q6. How to read and write image from a file ?


Ans : You can use ImageIo.read() and ImageIO.write()  method of javax.imageio package.

Q7. What is difference between static and init block in java.


Q8. How ConcurrentHashMap works?


Ans : The basic design of ConcurrentHashMap is to handling threading. Basically it locks each of the box (by default 16) which can be locked independently and thread safe for operation. And it does not expose the internal lock process.

Q9. Can a static block throw exception?


Ans : Yes. We can throw checked exception.

Q10. What is difference between iterator access and index access?


Ans : Basically iterator access process the traverse operation through each element, where index access process access direct the element by using the index.

Q11. Why character array is better than string for storing password in java?


Ans : Because, character array stores data in encrypted format which is not readable by human. But,the string stores the data in human readable format which is not secure.

Q12. what is daemon thread in java ?


Ans : A daemon thread is normally runs on background. And it does not prevent the JVM from exiting when the program finishes but the thread is still running.

Q13. What is Java Reflection API?


Ans  : Reflection is one of the most powerful api which help to work with classes, methods and variables  dynamically. Basically it inspect the class attributes at runtime. Also we can say it provides a metadata about the class. 

Q14. What is the difference between Serializable and Externalizable interfaces? 


Ans : Both interfaces are used for implement serialization. But, the basic difference is Serializable interface does not have any method (it’s a marker interface ) and Externalizable interface having 2 methods such as readExternal() and writeExternal(). Serializable interface is the super interface for Externalizable interface. 

08 March, 2014

How to stop windows 8 maintenance in progress ?

How to stop windows 8 maintenance in progress ?


This is always a ridiculous task. Just I want get rid of this, because its troubling me. Apparently you need to changes few settings.

Follow the steps for settings :-


Click the lower left corner to open the Start screen.

Type Schedule tasks in the Start screen

1. Click Settings

2. Click Schedule tasks

3. Go to Task Scheduler Library\Microsoft\Windows\TaskScheduler

4. Right Click Regular Maintenance

5. Click Properties

6. Click the Settings tab

7. Mark check in the box to Allow task to be run on demand

8. Click OK

9. Right Click Regular Maintenance again for testing whether its running or not and click on Run.

10. Again Right Click Regular Maintenance and click on End  for end this process.



Now your maintenance icon from task bar removed.
Its working NOW.WOW !!!

06 August, 2013

Why Interface methods are Public ?


Do you know why methods are Public in Interface ?

/*
 * @Author Manoj
 * Interface with two method
 */

interface IMyInterFace{
    public void display();
    public void calculate();
}



//Implementation Class
class MyImplClass implements IMyInterFace{   
   
   
    //Interface Method
    public void display(){
        System.out.println("Hi: Override-Display");
    }
   
    //private void display(){
    //    System.out.println("Hi: Override-Display with Private");
    //If you run this method then, Error Weaker Access Privileges
    //}
   
    //Interface method
    public void calculate(){
        System.out.println("Hi: Override-calculate");
    }
   
    //Class Method
    public void show(){
        System.out.println("Hi: I am Own Method");
    }
   
    public static void main(String str[]){
        IMyInterFace f=new MyImplClass();
        f.display();
    }
}


Output:- Hi: Override-Display




Explanation :-

In the above example , Interface methods are public means extremely strong access.When , you try to access those public method with private or protected (weak access privilege than public) then, you will face error.So, I override those two interface methods with same strong access privilege (public).
Please know more about strong/weak access privilege.

As you know ,objects define their interaction with the outside world through the methods that they expose. Methods form the object's interface with the outside world.So, the most common form, an interface is a group of related methods with empty bodies.

When you are creating an Interface, you must have to declare the methods as Public inside the interface.When you are creating an Interface , it means you are creating a common schema/structure and you are going to implement over any class (Known as Implementation Class). If you need more interesting points about Interface then , Click.


But , our point is why all methods are public in interface.Because of  weaker access privileges.Interface means you are going to implement those methods in implementation classes.So, that interface method can accessed by any where , only require to implementing that Interface.When you are declaring a method(Without body) inside interface  , by default you are making that method with the most strong access privileges (public).

  1. Do you really know , what is weaker access privilege ?
  2. Are you really interested on Interface ?
  3. What is Access Specifier when Overriding ?







Hope it will help you.
Any suggestions or comments will appreciated.

31 July, 2013

Attempting to assign weaker access privileges - Error in Java

As per the rule in overriding , you cannot apply weaker access specifier over a stronger access specifier.Suppose , your parent class has a method Display() with stronger access specifier like Public, then you cannot use weaker access specifier like private or public when you are overriding the Display() method.

Note :-

 Public is the 1st stronger access specifier
 Protected is the 2nd stronger access specifier
 Default is the 3rd stronger access specifier
 Private is the most weaker access specifier

 Always keep in mind about the access specifiers has vital role in inheritance (OOPS concept).

 Example :-

 /*
 * @Author Manoj
 *
 */


class AccessTest{
    protected void display(){ //Stronger Access specifier
        System.out.println("Hello AccessTest:Display");
    }
}

class TestWithMain extends AccessTest{
    // I am trying to override with weaker specifier , it show error
    // You can use public or protected (higher or same level of access specifier)
    private void display(){
        System.out.println("Hello TestWithMain:display");
    }   
    public static void main(String str[]){       
        AccessTest acObj=new TestWithMain();
        acObj.display();
    }   
}

 
 Error :-

 TestWithMain.java:8: display() in TestWithMain cannot override display() in AccessTest;
 attempting to assign weaker access privileges; was protected
    private void display(){

   

So, now if you change the access specifier to protected or public then it will work properly.

Changed executable code :-

    public void display(){
        System.out.println("Hello TestWithMain:display");
    }

   
    OR
   
    protected void display(){
        System.out.println("Hello TestWithMain:display");
    }

   

Hope it will help you.

Access Specifier in Method Overriding

As per the rule in overriding , you cannot apply weaker access specifier over a stronger access specifier.Suppose , your parent class has a method Display() with stronger access specifier like Public, then you cannot use weaker access specifier like private or public when you are overriding the Display() method.

Note :-

 Public is the 1st stronger access specifier
 Protected is the 2nd stronger access specifier
 Default is the 3rd stronger access specifier
 Private is the most weaker access specifier

 Always keep in mind about the access specifiers has vital role in inheritance (OOPS concept).

 Example :-

 /*
 * @Author Manoj
 *
 */


class AccessTest{
    protected void display(){ //Stronger Access specifier
        System.out.println("Hello AccessTest:Display");
    }
}

class TestWithMain extends AccessTest{
    // I am trying to override with weaker specifier , it show error
    // You can use public or protected (higher or same level of access specifier)
    private void display(){
        System.out.println("Hello TestWithMain:display");
    }   
    public static void main(String str[]){       
        AccessTest acObj=new TestWithMain();
        acObj.display();
    }   
}

 
 Error :-

 TestWithMain.java:8: display() in TestWithMain cannot override display() in AccessTest;
 attempting to assign weaker access privileges; was protected
    private void display(){

   

So, now if you change the access specifier to protected or public then it will work properly.

Changed executable code :-

    public void display(){
        System.out.println("Hello TestWithMain:display");
    }

   
    OR
   
    protected void display(){
        System.out.println("Hello TestWithMain:display");
    }

   

Hope it will help you.

29 July, 2013

How to inherit a constructor in JAVA

First of all when we are talking about the inheritance , Java does not inherit the construtor from super class.As we know constructor is one of the member of a , but we cannot inherit it for sub class (child class).Yes, we can invoke a super class (parent class) constructor from sub class by using the keyword "super".

Few Points about 'super' Keyword :-

1. Its a reserved keyword by Java API.
2. It is used to invoke or call super class (parent class) members .
3. When 'super' keyword is used inside the sub class (child class) constructor , 'super' keyword
     is the first line inside the constructor.

Example :-

/*
 * @Author Manoj
 * 29/07/2013
 */

class SUP{
    public SUP(String s){
        System.out.println("Hi Super: "+s);
    }
}


//SUB class extending SUP class
class SUB extends SUP{
    public SUB(String p){
        // Explicitly call the super class argument constructor
        // super is the first line inside the constructor
        super(p);
        System.out.println("Hi SUB: "+p);   
    }
   
    public static  void main(String str[]){
        new SUB("Manoj Kumar");
    }
}





OutPut :-



Hi Super: Manoj Kumar
Hi SUB: Manoj Kumar

Note :- If super class(parent class) constructor is a no-argument constructor the no need to call that constructor by using 'super'
keyword inside the sub class (child class) constructor .

When you invoke sub class (child class) constructor with no-argument, automatically super class (parent class) no-argument constructor
called or invoked.

Hope it will help you.

26 July, 2013

How do I default printer service in java ?


Code :


package experiment.java.printing;

import javax.print.PrintService;
import javax.print.PrintServiceLookup;

public class getDefaultPrinter{
    public static void main(String str[]){
        try{
        //Get print server as your local setting ( Printer)
        PrintService services = PrintServiceLookup.lookupDefaultPrintService();          
        System.out.println("Default Printer Name ::"+services.getName());
       
    }catch(Exception e){
        System.out.println("Error in get Default Printer service::"+e);
       
    }
       
    }
   
}


Example of Enumeration in java

import java.util.Enumeration;
import java.util.Vector;

/*
    Example of Enumaration with Vector
    @Author Manoj
*/

class MyEnumaration{
    public static void main(String str[]){
        Vector<String> vtr=new Vector<String>();
        vtr.add("Hi");
        vtr.add("Tester");
        vtr.add("How");
        vtr.add("Are");
        vtr.add("You?");
        Enumeration enumobj=vtr.elements();
        while(enumobj.hasMoreElements()){
        System.out.println(enumobj.nextElement());
           
        }
       
    }
}

OUTPUT:-


Hi
Tester
How
Are
You?


Read more about Enumeration.

02 July, 2013

hashCode() in Java

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable. The general contract of hashCode is:
  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables.
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)