Monday, 7 September 2015

How to downgrade your Xperia T2 Ultra Lolipop to Android Kitkat

I was facing very bad experience in using my Sony Xperia T2 ultra phone after i upgraded it to Lolipop version.

The phone was pathetically working slow. I wanted to go back to factory version of this.

If you wish to do the same, here are the below steps and then a you tube video from external source to show how these steps can be followed.

1. Download Flashtool from
https://drive.google.com/file/d/0B1AAC4lt7nzOQzR3aTZKUFZqem8/view?usp=sharing

2. Download Kitkat 4.4.3 from
https://drive.google.com/file/d/0B1oU02TyhZkAVTBvUU9MamRQZzg/edit

3. Copy above downloaded kitkat 4.4.3 file to C:\users\<username>\.flashtools\firmwares

4. Start Flash Tool.

5. Wait for any pending things to be completed in flash tool.

6. Click on left most button (which looks like zigzag spike). This will start the flash mode.

7. Now select the file which would be the one we just copied to flashtool directory.

8. Start the flashing. Wait for some time. Follow the onscreen instructions. When asked to press the back button, press the volume down key.

9. Wait for flashing to complete.

10. Disconnect and restart the phone.

Below is the youtube video to explain the above process


    Saturday, 15 November 2014

    How to make Spring beans thread-safe ?

    Spring beans are singleton by default.
    Singleton means bean identified by a particular bean id will have only one instance.

    Consider the following code:
    @Controller
    public class MyServlet {
    
        @Autowired
        private HelloService service;
    
        @RequestMapping(value="/hello", method = RequestMethod.GET)
        public void sayHello(HttpServletRequest req, HttpServletResponse res) throws IOException {
            service.doStuff();
        }
    
    }
    
    
    public class HelloService {
    
        private int i = 1;
    
        public void doStuff() {
            System.out.println("Started " + i);
            i++;
            System.out.println(Thread.currentThread().getName() + " Done " + i);
        }
    }
    The output will be something like this:
    32911580@qtp-28064776-0 - Started 1
    7802158@qtp-28064776-2 - Started 2
    32911580@qtp-28064776-0 - Done 3
    7802158@qtp-28064776-2 - Done 3
    This prove the "i" var is shared between multiple threads.
    Now lets try to define the HelloService bean as prototype, like this
    <bean id="helloService" class="my.package.HelloService" scope="prototype" />
    In this case as well, the result is the same.
    The only ways this can be solved is : move the declaration into doStuff() method, but it's not what we want - make the doStuff() method, but this means have locks
    What I would like is have a new instance of HelloService on every call.
    Since you have only one instance of MyServlet you will also have only one instance of HelloService.
    One of the following spring scopes help: request A new instance for each HTTP request. session A new instance of the class for each new HttpSession created in a servlet container.
    This will change the semantics of your code. If you declare the bean in the scope request your counter will always be 1.
    So, to make bean thread-safe, make the bean definition scope as "request" or "session".

    Wednesday, 12 November 2014

    How to create a Bootable Windows 7 USB Flash Drive

    Instructions to create a Bootable Windows 7 USB Flash Drive 

    rufus How to Create a Bootable Windows 7 USB Flash Drive
    • Step 1: Download rufus on your computerand run it .
    • Step 2: Plug in your USB flash drive into your computer .
    • Step 3: From Rufu’s settings, Choose NTFS as the file system.
    • Step 4: Check ” Quick format ” and ”Create extended label and icon files “
    • Step 5: Check ” Create a bootable disk using ” and click the drive icon beside it to select the windows 7 ISO file .
    • Step 6: Now click on start to create a bootable window 7 USB flash drive .
    After a few minutes your Windows 7 bootable  USB flash drive will be  ready for installation. Reboot your PC and set the bootable flash drive as a first boot priority in the bios settings. Save the bios settings and reboot once again to continue with the windows 7 installation process .
     Note: You have to allow booting from USB devices in your BIOS settings in order to proceed further with the windows 7 installation .

    For those who install using the bootable USB Flash Drive

    For newer desktop computer or laptop with USB 3.0 Ports, be sure to plug it in USB 2.0 ports to avoid the error. 

    The rest proceed to the next step

    To fix the problem:


    • Browse the file f6flpy-x86 or f6flpy-x64 file included in DVD drivers

    • If the file is not in the DVD, download the file in Microsoft Website

    • extract the file, put it in usb and browse the file.

    Additional Resources

    • f6flpy-x64  f6flpy-x86  Windows 7 download f6flpy-x86 sata drivers

    Sunday, 2 November 2014

    Why should immutable class be declared as final?

    We have read that to make a class immutable in Java, we should do the following,
    1. Do not provide any setters
    2. Mark all fields as private
    3. Make the class final
    Now have you ever thought why is step 3 required? Why should I mark the class final?
    Lets see with the help of example.
    If you don't mark the class final, it might be possible for me to suddenly make your seemingly immutable class actually mutable. For example, consider this code:
    public class Immutable {
         private final int value;
    
         public Immutable(int value) {
             this.value = value;
         }
    
         public int getValue() {
             return value;
         }
    }
    Now, suppose I do the following:
    public class Mutable extends Immutable {
         private int realValue;
    
         public Mutable(int value) {
             super(value);
    
             realValue = value;
         }
    
         public int getValue() {
             return realValue;
         }
         public void setValue(int newValue) {
             realValue = newValue;
         }
    }
    Notice that in my Mutable subclass, I've overridden the behavior of getValue to read a new, mutable field declared in my subclass. As a result, your class, which initially looks immutable, really isn't immutable. I can pass this Mutable object wherever an Immutable object is expected, which could do Very Bad Things to code assuming the object is truly immutable. Marking the base class finalprevents this from happening.

    Sunday, 5 October 2014

    How to show Alert Dialog in Android applications?


    How to Show Alert Dialog in Android


    1
    Import the AlertDialog class to your Android application.

    import android.app.AlertDialog;


    2
    Set up the AlertDialog class to the body of your application like this. Set some properties for the AlertDialog object.

    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("Reset...");
    alertDialog.setMessage("Are you sure?");
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
    // here you can add functions
    }
    });
    alertDialog.setIcon(R.drawable.icon);
    alertDialog.show();


    3
    Save your application and run. You will get the image as below.


    Tuesday, 9 September 2014

    What is difference between Program Files and Program Files(x86) folders in Windows 7 ?

    The difference between the two is that "Program Files" is used to install softwares which are 64-bit softwares and "Program Files (x86)" is used to install softwares which are 32-bit softwares.

    This is the default behavior. So if u find any softwares under "Program Files", remember they are 64-bit softwares and vice-versa.

    Wednesday, 20 August 2014

    Why wait (), notify () and notifyAll () must be called from synchronized block or method in Java ?

    Most of Java developer knows that wait() ,notify() and notifyAll() method of object class must have to be called inside synchronized method or synchronized block in Java but how many times we thought why ?

    We use wait () and notify () or notifyAll () method mostly for inter-thread communication. One thread is waiting after checking a condition e.g. In Producer Consumer example Producer Thread is waiting if buffer is full and Consumer thread notify Producer thread after he creates a space in buffer by consuming an element. calling notify() or notifyAll() issues a notification to a single or multiple thread that a condition has changed and once notification thread leaves synchronized block , all the threads which are waiting fight for object lock on which they are waiting and lucky thread returns from wait() method after reacquiring the lock and proceed further. Let’s divide this whole operation in steps to see a possibility of race condition between wait () and notify () method in Java, we will useProduce Consumer thread example to understand the scenario better:

       1. The Producer thread tests the condition (buffer is full or not) and confirms that it must wait (after finding buffer is full).
       2. The Consumer thread sets the condition after consuming an element from buffer.
       3. The Consumer thread calls the notify () method; this goes unheard since the Producer thread is not yet waiting.
       4. The Producer thread calls the wait () method and goes into waiting state.

    So due to race condition here we potential lost a notification and if we use buffer or just one element Produce thread will be waiting forever and your program will hang.

    Now let's think how does this potential race condition get resolved? This race condition is resolved by using synchronized keyword and locking provided by java. In order to call the wait (), notify () or notifyAll () methods in Java, we must have obtained the lock for the object on which we're calling the method. Since the wait () method in Java also releases the lock prior to waiting and reacquires the lock prior to returning from the wait () method, we must use this lock to ensure that checking the condition (buffer is full or not) and setting the condition (taking element from buffer) is atomic which can be achieved by using synchronized method or block in Java.

    Just to summarize we call wait (), notify () or notifyAll method in Java from synchronized method or synchronized block in Java to avoid:
    1) IllegalMonitorStateException in Java which will occur if we don't call wait (), notify () or notifyAll () method from synchronized context.
    2) Any potential race condition between wait and notify method in Java.