Monday 30 January 2017

Java Tutorial: Java Synchronization (Why we use Synchronization[Bank] | Synchronization in java)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=Pr7NlI7nbFg&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial: Java Synchronization (Why we use Synchronization[Bank] | Synchronization in java) 
Java Tutorial: Java Synchronization (Why we use Synchronization[Bank] | Synchronization in java) 
Java Tutorial: Java Synchronization (Why we use Synchronization[Bank] | Synchronization in java) 
Java Tutorial: Java Synchronization (Why we use Synchronization[Bank] | Synchronization in java) 
Java Tutorial: Java Synchronization (Why we use Synchronization[Bank] | Synchronization in java) 
Java Tutorial: Java Synchronization (Why we use Synchronization[Bank] | Synchronization in java) 
Java Tutorial: Java Synchronization (Why we use Synchronization[Bank] | Synchronization in java) 
Java Tutorial: Java Synchronization (Why we use Synchronization[Bank] | Synchronization in java) 
Java Tutorial: Java Synchronization (Why we use Synchronization[Bank] | Synchronization in java) 
Java Tutorial: Java Synchronization (Why we use Synchronization[Bank] | Synchronization in java) 
Java Tutorial: Java Synchronization (Why we use Synchronization[Bank] | Synchronization in java) 
Java Tutorial: Java Synchronization (Why we use Synchronization[Bank] | Synchronization in java) 
Java Tutorial: Java Synchronization (Why we use Synchronization[Bank] | Synchronization in java) 
BankAccount.java
public class BankAccount
{

    private int accountNumber;
    private double accountBalance;
    
    private AccountDAO dao;

    public synchronized boolean deposit(double amount)
    {
        double newAccountBalance;
        /*
         * Get the current balance from DB table.
         */
        accountBalance = dao.getCurrentAccountBalance(accountNumber);
        
        if (amount < 0.0)
        {
            /*
             * Can not deposit a negative amount.
             */
            return false; 
        }

        else
        {
            newAccountBalance = accountBalance + amount;
            /*
             * Update the new balance in the DB table.
             */         
            dao.updateAccountBalance(newAccountBalance);
            return true;
        }

    }
}
AccountDAO.java
public class AccountDAO
{

    public double getCurrentAccountBalance(int accountNumber)
    {
        /*
         * Code to get the current balance from DB table.
         */
        return 0;
    }

    public void updateAccountBalance(double newAccountBalance)
    {
        /*
         * Code to update the new balance in the DB table.
         */ 
        
    }

}
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/SynchronizationDemo_Bank_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/SynchronizationDemo_Bank_App/SynchronizationDemo

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/28b772df8f5b4b9e60fd873726243fc258cd34a2/BasicJava/SynchronizationDemo_Bank_App/SynchronizationDemo/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Java Tutorial: Java Synchronization (Java Synchronization | Synchronization in java) - Playlist

    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java)


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=Y9vFftRKUEY&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    Java Tutorial: Java Synchronization (Why we use Synchronization | Synchronization in java) 
    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Java Tutorial: Java Synchronization (Java Synchronization | Synchronization in java)


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=xTBu6iXL8LM&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial: Java Synchronization (Java Synchronization | Synchronization in java) 
    See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Java Tutorial: Java Runtime class (gc method)


    Click here to watch in Youtube : 
    https://www.youtube.com/watch?v=AHhIMs3HAyI&list=UUhwKlOVR041tngjerWxVccw

    RuntimeDemo.java
    import java.io.IOException;
    
    public class RuntimeDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            /*
             * Returns the runtime object associated with the
             * current Java application.
             */
            Runtime runtime = Runtime.getRuntime();
    
            System.out.println("Runs the Gargage collector..");
            /*
             * Runs the garbage collector.
             * 
             * Calling this method suggests that the Java
             * virtual machine expend effort toward recycling
             * unused objects in order to make the memory they
             * currently occupy available for quick reuse. When
             * control returns from the method call, the virtual
             * machine has made its best effort to recycle all
             * discarded objects.
             * 
             * The name gc stands for "garbage collector". The
             * virtual machine performs this recycling process
             * automatically as needed, in a separate thread,
             * even if the gc method is not invoked explicitly.
             * 
             * The method System.gc() is the conventional and
             * convenient means of invoking this method.
             */
            runtime.gc();
    
        }
    
    }
    
    Output
    Runs the Gargage collector..
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/RuntimeDemo_GC_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/RuntimeDemo_GC_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/28b772df8f5b4b9e60fd873726243fc258cd34a2/BasicJava/RuntimeDemo_GC_App/?at=master

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Java Tutorial: Java Runtime class (halt method)


    Click here to watch in Youtube : 
    https://www.youtube.com/watch?v=U0h2VimMOkQ&list=UUhwKlOVR041tngjerWxVccw

    RuntimeDemo.java
    import java.io.IOException;
    
    /*
     * public void halt(int status)
     * 
     * Parameters: 
     * -----------
     * 
     * status - Termination status. By convention, a nonzero
     * status code indicates abnormal termination.
     */
    public class RuntimeDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            /*
             * Returns the runtime object associated with the
             * current Java application.
             */
            Runtime runtime = Runtime.getRuntime();
    
            System.out.println("Before halt method is called..");
            /*
             * Forcibly terminates the currently running Java
             * virtual machine.
             * 
             * This method should be used with extreme caution.
             * Unlike the exit method, this method does not
             * cause shutdown hooks to be started and does not
             * run uninvoked finalizers if finalization-on-exit
             * has been enabled. If the shutdown sequence has
             * already been initiated then this method does not
             * wait for any running shutdown hooks or finalizers
             * to finish their work.
             */
            runtime.halt(0);
            System.out.println("After halt method is called..");
        }
    
    }
    
    Output
    Before halt method is called..
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/RuntimeDemo_halt_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/RuntimeDemo_halt_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/28b772df8f5b4b9e60fd873726243fc258cd34a2/BasicJava/RuntimeDemo_halt_App/?at=master

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Java Tutorial: Java Runtime class (exec(String command,String[] envp,File dir) method)



    Click here to watch in Youtube : 
    https://www.youtube.com/watch?v=-AzVJNru9Ls&list=UUhwKlOVR041tngjerWxVccw

    RuntimeDemo.java
    import java.io.File;
    import java.io.IOException;
    
    /*
     * public Process exec(String command, String[] envp,
     *                              File dir) throws IOException
     * 
     * Parameters: 
     * -----------
     * 
     * command - a specified system command.
     * 
     * envp - array of strings, each element of which has
     * environment variable settings in the format
     * name=value, or null if the subprocess should inherit
     * the environment of the current process.
     * 
     * dir - the working directory of the subprocess, or
     * null if the subprocess should inherit the working
     * directory of the current process.
     */
    
    public class RuntimeDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            /*
             * Returns the runtime object associated with the
             * current Java application.
             */
            Runtime runtime = Runtime.getRuntime();
    
            /*
             * Create a file with the working directory we wish
             */
            File dir = new File("D:/Work/");
    
            /*
             * Executes the specified string command in a
             * separate process with the specified environment
             * and working directory.
             * 
             * It will open a new notepad.
             */
            Process process = runtime.exec("notepad.exe", null, dir);
            System.out.println("is process alive = " + process.isAlive());
        }
    
    }
    
    Output
    is process alive = true
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/RuntimeDemo_exec_cmd_envp_dir_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/RuntimeDemo_exec_cmd_envp_dir_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/28b772df8f5b4b9e60fd873726243fc258cd34a2/BasicJava/RuntimeDemo_exec_cmd_envp_dir_App/?at=master

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Java Tutorial: Java Runtime class (exec(String command,String[] envp) method)


    Click here to watch in Youtube : 
    https://www.youtube.com/watch?v=BEARNZg4-SM&list=UUhwKlOVR041tngjerWxVccw

    RuntimeDemo.java
    import java.io.IOException;
    
    /*
     * public Process exec(String command, String[] envp)
     *                                      throws IOException
     *
     * Parameters:
     * -----------
     *
     * command - a specified system command.
     *
     * envp - array of strings, each element of which has
     * environment variable settings in the format
     * name=value, or null if the subprocess should inherit
     * the environment of the current process.
     */
    public class RuntimeDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            /*
             * Returns the runtime object associated with the
             * current Java application.
             */
            Runtime runtime = Runtime.getRuntime();
    
            /*
             * Executes the specified string command in a
             * separate process with the specified environment.
             *
             * It will open a new notepad.
             */
            Process process = runtime.exec("notepad.exe",null);
            System.out.println("is process alive = " + process.isAlive());
        }
    
    }
    
    Output
    is process alive = true
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/RuntimeDemo_exec_cmd_envp_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/RuntimeDemo_exec_cmd_envp_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/28b772df8f5b4b9e60fd873726243fc258cd34a2/BasicJava/RuntimeDemo_exec_cmd_envp_App/?at=master

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Java Tutorial: Java Runtime class (exec(String[] cmdarray,String[] envp,File dir) method)


    Click here to watch in Youtube : 
    https://www.youtube.com/watch?v=Irfb6Fru4XQ&list=UUhwKlOVR041tngjerWxVccw

    RuntimeDemo.java
    import java.io.File;
    import java.io.IOException;
    
    /*
     * public Process exec(String[] cmdarray, String[] envp,
     *                              File dir) throws IOException
     * 
     * Parameters: 
     * -----------
     * 
     * cmdarray - array containing the command to call and
     * its arguments.
     * 
     * envp - array of strings, each element of which has
     * environment variable settings in the format
     * name=value, or null if the subprocess should inherit
     * the environment of the current process.
     * 
     * dir - the working directory of the subprocess, or
     * null if the subprocess should inherit the working
     * directory of the current process.
     */
    public class RuntimeDemo
    {
    
        public static void main(String[] args) throws IOException
        {
    
            String[] cmdArray = new String[2];
    
            cmdArray[0] = "notepad.exe";
            cmdArray[1] = "Hello.txt";
    
            System.out.println(
                    "Executing notepad.exe and opening Hello.txt");
    
            /*
             * Returns the runtime object associated with the
             * current Java application.
             */
            Runtime runtime = Runtime.getRuntime();
    
            File dir = new File("D:/work");
            /*
             * Executes the specified string command in a
             * separate process with the specified environment
             * and working directory.
             * 
             * Returns: A new Process object for managing the
             * subprocess
             */
            Process process = runtime.exec(cmdArray, null, dir);
    
            System.out.println("is process alive = " + process.isAlive());
            System.out.println(cmdArray[1] + " should now open.");
        }
    
    }
    
    Output
    Executing notepad.exe and opening Hello.txt
    is process alive = true
    Hello.txt should now open.
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/RuntimeDemo_exec_cmdarray_envp_dir_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/RuntimeDemo_exec_cmdarray_envp_dir_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/28b772df8f5b4b9e60fd873726243fc258cd34a2/BasicJava/RuntimeDemo_exec_cmdarray_envp_dir_App/?at=master

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Java Tutorial: Java Runtime class (exec(String[] cmdarray, String[] envp) method)


    Click here to watch in Youtube : 
    https://www.youtube.com/watch?v=KrGPHOtlq9U&list=UUhwKlOVR041tngjerWxVccw

    RuntimeDemo.java
    import java.io.IOException;
    
    /*
     * public Process exec(String[] cmdarray, String[] envp)
     *                                      throws IOException
     * 
     * Parameters: 
     * -----------
     * 
     * cmdarray - array containing the command to call and
     * its arguments. 
     * 
     * envp - array of strings, each element
     * of which has environment variable settings in the
     * format name=value, or null if the subprocess should
     * inherit the environment of the current process.
     */
    
    public class RuntimeDemo
    {
    
        public static void main(String[] args) throws IOException
        {
    
            String[] cmdArray = new String[2];
    
            cmdArray[0] = "notepad.exe";
            cmdArray[1] = "Hello.txt";
    
            System.out.println("Executing notepad.exe and opening Hello.txt");
    
            /*
             * Returns the runtime object associated with the
             * current Java application.
             */
            Runtime runtime = Runtime.getRuntime();
    
            /*
             * Executes the specified command and arguments in a
             * separate process with the specified environment.
             * 
             * Returns: A new Process object for managing the
             * subprocess
             */
            Process process = runtime.exec(cmdArray, null);
    
            System.out.println("is process alive = " + process.isAlive());
            System.out.println(cmdArray[1] + " should now open.");
        }
    
    }
    
    Output
    Executing notepad.exe and opening Hello.txt
    is process alive = true
    Hello.txt should now open.
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/RuntimeDemo_exec_cmdarray_envp_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/RuntimeDemo_exec_cmdarray_envp_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/28b772df8f5b4b9e60fd873726243fc258cd34a2/BasicJava/RuntimeDemo_exec_cmdarray_envp_App/?at=master

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Java Tutorial: Java Runtime class (exec(String[] cmdarray) method)


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=dW75MCvPRtI&list=UUhwKlOVR041tngjerWxVccw

    RuntimeDemo.java
    import java.io.IOException;
    
    /*
     * public Process exec(String[] cmdarray) throws
     *                                      IOException
     * 
     * Parameters: 
     * -----------
     * 
     * cmdarray - array containing the command to call and
     * its arguments.
     */
    public class RuntimeDemo
    {
    
        public static void main(String[] args) throws IOException
        {
    
            String[] cmdArray = new String[2];
    
            cmdArray[0] = "notepad.exe";
            cmdArray[1] = "Hello.txt";
    
            System.out.println("Executing notepad.exe and opening Hello.txt");
    
            /*
             * Returns the runtime object associated with the
             * current Java application.
             */
            Runtime runtime = Runtime.getRuntime();
    
            /*
             * Executes the specified command and arguments in a
             * separate process.
             * 
             * Returns: A new Process object for managing the
             * subprocess
             */
            Process process = runtime.exec(cmdArray);
    
            System.out.println("is process alive = " + process.isAlive());
            System.out.println(cmdArray[1] + " should now open.");
        }
    
    }
    
    Output
    Executing notepad.exe and opening Hello.txt
    is process alive = true
    Hello.txt should now open.
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/RuntimeDemo_exec_cmdarray_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/RuntimeDemo_exec_cmdarray_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/28b772df8f5b4b9e60fd873726243fc258cd34a2/BasicJava/RuntimeDemo_exec_cmdarray_App/?at=master

    See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Friday 27 January 2017

    Java Tutorial: Java Runtime class (How to terminate JVM using exit method)


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=vBFQ0N_CFsA&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial: Java Runtime class (How to terminate JVM using exit method) 
    RuntimeDemo.java
    import java.io.IOException;
    
    /*
     * public void exit(int status)
     * 
     * Parameters: 
     * -----------
     * 
     * status - Termination status. By convention, a nonzero
     * status code indicates abnormal termination.
     */
    public class RuntimeDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            /*
             * Returns the runtime object associated with the
             * current Java application.
             */
            Runtime runtime = Runtime.getRuntime();
    
            System.out.println("Before exit method is called..");
            /*
             * Terminates the currently running Java virtual
             * machine by initiating its shutdown sequence..
             */
            runtime.exit(0);
    
            System.out.println("After exit method is called..");
        }
    
    }
    
    Output
    Before exit method is called..
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/RuntimeDemo_exit_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/RuntimeDemo_exit_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/c72ef0bb7cf33f5c158c45d824df234766210e9a/BasicJava/RuntimeDemo_exit_App/?at=master

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial