Thursday, 26 November 2015

Java Tutorial : Java pass by value (primitive data type)


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

PassPrimitiveDatatypeTest.java
public class PassPrimitiveDatatypeTest
{

    public static void main(String[] args)
    {

        int x = 3;

        changeIt(x);

        System.out.println("x value inside main method : " + x);

    }

    /*
     * Passing Primitive Data Type Arguments :
     * 
     * Primitive arguments, such as an int or a double, are passed into methods
     * by value. This means that any changes to the values of the parameters
     * exist only within the scope of the method. When the method returns, the
     * parameters are gone and any changes to them are lost.
     */

    public static void changeIt(int x)
    {
        x = 50;
        System.out.println("x value inside changeIt method : " + x);
        return;
    }

}
Output
x value inside changeIt method : 50
x value inside main method : 3
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/PassInfoDemoApp.zip?attredirects=0&d=1

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/2f20a20e875ab6e7de15adc0041c373263d61c3b/BasicJava/PassInfoDemoApp/?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
  • Java Tutorial : Java methods - Playlist

    Java Tutorial : Java overloaded methods and Constructors - Playlist

    Java Tutorial : Java Constructors - Playlist

    Java Tutorial : Java Access modifiers - Playlist

    Java Tutorial : Java overloaded Constructors


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

    Click the below Image to Enlarge
    Java Tutorial : Java overloaded Constructors 
    Java Tutorial : Java overloaded Constructors 
    Employee.java
    public class Employee
    {
    
        private String name;
        private int age;
    
        public Employee()
        {
            System.out.println("Inside Employee() constructor");
        }
    
        public Employee(String name)
        {
            System.out.println("Inside  Employee(String name) constructor");
            this.name = name;
        }
    
        public Employee(String name, int age)
        {
            System.out.println("Inside  Employee(String name,int age) constructor");
            this.name = name;
            this.age = age;
        }
    
        public Employee(int age)
        {
            System.out.println("Inside  Employee(int age) constructor");
            this.age = age;
        }
    
        public String getName()
        {
            return name;
        }
    
        public void setName(String name)
        {
            this.name = name;
        }
    
        public int getAge()
        {
            return age;
        }
    
        public void setAge(int age)
        {
            this.age = age;
        }
    
    }
    
    EmployeeDemoTest.java
    public class EmployeeDemoTest
    {
    
        public static void main(String[] args)
        {
    
            Employee employeeObject1 = new Employee();
            System.out.println("Name : " + employeeObject1.getName());
            System.out.println("Age  : " + employeeObject1.getAge());
    
            System.out.println("------------------------------------");
    
            Employee employeeObject2 = new Employee("Dave");
            System.out.println("Name : " + employeeObject2.getName());
            System.out.println("Age  : " + employeeObject2.getAge());
    
            System.out.println("------------------------------------");
    
            Employee employeeObject3 = new Employee("John", 45);
            System.out.println("Name : " + employeeObject3.getName());
            System.out.println("Age  : " + employeeObject3.getAge());
            
            System.out.println("------------------------------------");
    
            Employee employeeObject4 = new Employee(54);
            System.out.println("Name : " + employeeObject4.getName());
            System.out.println("Age  : " + employeeObject4.getAge());
    
        }
    
    }
    
    Output
    Inside Employee() constructor
    Name : null
    Age  : 0
    ------------------------------------
    Inside  Employee(String name) constructor
    Name : Dave
    Age  : 0
    ------------------------------------
    Inside  Employee(String name,int age) constructor
    Name : John
    Age  : 45
    ------------------------------------
    Inside  Employee(int age) constructor
    Name : null
    Age  : 54
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/ConstructorDemoOverloadedApp.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/2f20a20e875ab6e7de15adc0041c373263d61c3b/BasicJava/ConstructorDemoOverloadedApp/?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
  • Java Tutorial : Java private Constructor


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

    Employee.java
    public class Employee
    {
    
        private String name;
        private int age;
    
        private Employee()
        {
            System.out.println("Inside Employee() constructor");
        }
    
        public String getName()
        {
            return name;
        }
    
        public void setName(String name)
        {
            this.name = name;
        }
    
        public int getAge()
        {
            return age;
        }
    
        public void setAge(int age)
        {
            this.age = age;
        }
    }
    
    EmployeeDemoTest.java
    public class EmployeeDemoTest
    {
    
        public static void main(String[] args)
        {
    
            Employee employeeObject1 = new Employee();
            System.out.println("Name : " + employeeObject1.getName());
            System.out.println("Age  : " + employeeObject1.getAge());
    
        }
    
    }
    
    Output
    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
        The constructor Employee() is not visible
    
        at EmployeeDemoTest.main(EmployeeDemoTest.java:7)
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/ConstructorDemoPrivateApp.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/2f20a20e875ab6e7de15adc0041c373263d61c3b/BasicJava/ConstructorDemoPrivateApp/?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
  • Wednesday, 25 November 2015

    Java Tutorial : Java Constructor


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

    Click the below Image to Enlarge
    Java Tutorial : Java Constructor 
    Employee.java
    public class Employee
    {
    
        private String name;
        private int age;
    
        public Employee(String name, int age)
        {
            this.name = name;
            this.age = age;
        }
    
        public String getName()
        {
            return name;
        }
    
        public void setName(String name)
        {
            this.name = name;
        }
    
        public int getAge()
        {
            return age;
        }
    
        public void setAge(int age)
        {
            this.age = age;
        }
    
    }
    
    EmployeeDemoTest.java
    public class EmployeeDemoTest
    {
    
        public static void main(String[] args)
        {
            Employee davidEmployee = new Employee("David", 25);
            System.out.println("Name : " + davidEmployee.getName());
            System.out.println("Age  : " + davidEmployee.getAge());
            System.out.println("-------------------------------");
            Employee johnEmployee = new Employee("John", 45);
            System.out.println("Name : " + johnEmployee.getName());
            System.out.println("Age  : " + johnEmployee.getAge());
    
        }
    
    }
    
    Output
    Name : David
    Age  : 25
    -------------------------------
    Name : John
    Age  : 45
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/ConstructorDemoConstructorsApp.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/2f20a20e875ab6e7de15adc0041c373263d61c3b/BasicJava/ConstructorDemoConstructorsApp/?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
  • Java Tutorial : Java default Constructor


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

    Employee.java
    public class Employee
    {
    
        String name;
        int age;
    
        /*
         * The compiler automatically provides a no-argument default constructor if
         * the class does not have any other constructor.
         * 
         * This default constructor will call the no-argument constructor of the
         * superclass. In this situation, the compiler will complain if the
         * superclass doesn't have a no-argument constructor so you must verify that
         * it does. If your class has no explicit superclass, then it has an
         * implicit superclass of Object, which does have a no-argument constructor.
         */
    
    }
    
    EmployeeDemoTest.java
    public class EmployeeDemoTest
    {
    
        public static void main(String[] args)
        {
            /*
             * Invokes the no-argument constructor to create a new Employee object
             * called employee.
             */
            Employee employee = new Employee();
            System.out.println("Name : " + employee.name);
            System.out.println("Age  : " + employee.age);
    
        }
    
    }
    
    Output
    Name : null
    Age  : 0
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/ConstructorDemoDefaultconstructorApp.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/2f20a20e875ab6e7de15adc0041c373263d61c3b/BasicJava/ConstructorDemoDefaultconstructorApp/?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
  • Java Tutorial : Java Overloading methods


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

    Click the below Image to Enlarge
    Java Tutorial : Java Overloading methods
    Java Tutorial : Java Overloading methods
    Java Tutorial : Java Overloading methods
    DisplayValue.java
    public class DisplayValue
    {
    
        public static void main(String[] args)
        {
            DisplayValue displayValue = new DisplayValue();
            displayValue.displayValue("Hello");
            displayValue.displayValue(10);
            displayValue.displayValue(200, 400);
        }
    
        public void displayValue(String str)
        {
            System.out.println("displayValue(String str) has been called : " + str);
        }
    
        public void displayValue(int a)
        {
            System.out.println("displayValue(int a) has been called : " + a);
        }
    
        public void displayValue(int a, int b)
        {
            System.out.println("displayValue(int a,int b) : " + a + "," + b);
        }
    
    }
    
    Output
    displayValue(String str) has been called : Hello
    displayValue(int a) has been called : 10
    displayValue(int a,int b) : 200,400
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/OverloadedMethodDemoApp.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/2f20a20e875ab6e7de15adc0041c373263d61c3b/BasicJava/OverloadedMethodDemoApp/?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
  • Java Tutorial : Java Access modifiers private and public


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

    Student.java
    public class Student
    {
        /*
         * public modifier — the field is accessible from all classes.
         */
        public String name;
        
        /*
         * private modifier—the field is accessible only within its own class.
         */
        private int age;
    
    }
    
    StudentDemoTest.java
    public class StudentDemoTest
    {
    
        public static void main(String[] args)
        {
            Student student = new Student();
            student.name = "Dave";
            student.age = 23;
        }
    
    }
    
    Output
    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
        The field Student.age is not visible
    
        at StudentDemoTest.main(StudentDemoTest.java:8)
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/AccessModifiersDemoPrivate-PublicApp.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/AccessModifiersDemoPrivate-PublicApp

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/2f20a20e875ab6e7de15adc0041c373263d61c3b/BasicJava/AccessModifiersDemoPrivate-PublicApp/?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
  • Java Tutorial : Java Access modifiers Getter and Setter Methods


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

    Student.java
    public class Student
    {
    
        /*
         * private modifier—the field is accessible only within its own class.
         * 
         * In the spirit of encapsulation, it is common to make fields private. This
         * means that they can only be directly accessed from the Student class. We
         * still need access to these values, however. This can be done indirectly
         * by adding public methods that obtain the field values for us:
         */
    
        private String name;
        private int age;
    
        public String getName()
        {
            return name;
        }
    
        public void setName(String name)
        {
            this.name = name;
        }
    
        public int getAge()
        {
            return age;
        }
    
        public void setAge(int age)
        {
            this.age = age;
        }
    
    }
    
    StudentDemoTest.java
    public class StudentDemoTest
    {
    
        public static void main(String[] args)
        {
            Student student = new Student();
            student.setName("Dave"); 
            student.setAge(23);
            
            System.out.println("Name : "+student.getName());
            System.out.println("Age  : "+student.getAge());
        }
    
    }
    
    Output
    Name : Dave
    Age  : 23
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/AccessModifiersDemoGetterSetterApp.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/2f20a20e875ab6e7de15adc0041c373263d61c3b/BasicJava/AccessModifiersDemoGetterSetterApp/?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
  • Java Tutorial : Java return Statement


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

    ReturnDemo.java
    public class ReturnDemo
    {
        public static void main(String[] args)
        {
    
            /*
             * The return statement exits from the current method, and control flow
             * returns to where the method was invoked.
             * 
             * The return statement has two forms: one that returns a value, and one
             * that doesn't.
             * 
             * To return a value, simply put the value (or an expression that
             * calculates the value) after the return keyword.
             */
    
            ReturnDemo returnDemo = new ReturnDemo();
            int totalValue = returnDemo.getTotal(10, 10);
            System.out.println("totalValue : " + totalValue);
    
        }
    
        public int getTotal(int a, int b)
        {
            int c = a + b;
            /*
             * The data type of the returned value must match the type of the
             * method's declared return value.
             */
            return c;
        }
    
    }
    
    Output
    totalValue : 20
    
    ReturnVoidDemo.java
    public class ReturnVoidDemo
    {
        public static void main(String[] args)
        {
    
            /*
             * The return statement exits from the current method, and control flow
             * returns to where the method was invoked.
             * 
             * The return statement has two forms: one that returns a value, and one
             * that doesn't.
             * 
             * To return a value, simply put the value (or an expression that
             * calculates the value) after the return keyword.
             */
    
            ReturnVoidDemo returnVoidDemo = new ReturnVoidDemo();
            returnVoidDemo.calculateTotal(0, 0);
            System.out.println("End---");
    
        }
    
        public void calculateTotal(int a, int b)
        {
    
            if (a == 0 && b == 0)
            {
                /*
                 * When a method is declared void, use the form of return that
                 * doesn't return a value.
                 */
                System.out
                        .println("Both a and b are '0',So current method will exist");
                return;
            }
    
            int totalValue = a + b;
            System.out.println("totalValue :" + totalValue);
        }
    
    }
    
    Output
    Both a and b are '0',So current method will exist
    End---
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/ControlFlowDemoReturnApp.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/2f20a20e875ab6e7de15adc0041c373263d61c3b/BasicJava/ControlFlowDemoReturnApp/?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
  • Java Tutorial : Java Break with Label(Array search)


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

    BreakWithLabelDemo.java
    class BreakWithLabelDemo
    {
        public static void main(String[] args)
        {
    
            /*
             * An unlabeled break statement terminates the innermost switch, for,
             * while, or do-while statement, but a labeled break terminates an outer
             * statement.
             */
    
            int[][] arrayOfInts =
            {
            { 1, 2, 3 },
            { 4, 5, 6 },
            { 7, 8, 9 } };
    
            int searchfor = 2;
    
            int i;
            int j = 0;
            boolean foundIt = false;
    
            search: for (i = 0; i < arrayOfInts.length; i++)
            {
                System.out.println("i:" + i);
                for (j = 0; j < arrayOfInts[i].length; j++)
                {
                    System.out.println("arrayOfInts[" + i + "]" + "[" + j + "] : "
                            + arrayOfInts[i][j]);
                    if (arrayOfInts[i][j] == searchfor)
                    {
                        foundIt = true;
                        break search;
                    }
                }
                System.out.println("for loop j is completed.");
            }
    
            System.out.println("for loop i is completed.");
    
            if (foundIt)
            {
                System.out.println("Found " + searchfor + " at " + i + ", " + j);
            }
            else
            {
                System.out.println(searchfor + " not in the array");
            }
    
        }
    }
    
    Output
    i:0
    arrayOfInts[0][0] : 1
    arrayOfInts[0][1] : 2
    for loop i is completed.
    Found 2 at 0, 1
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/ControlFlowDemoBreakLabelArrayApp.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/2f20a20e875ab6e7de15adc0041c373263d61c3b/BasicJava/ControlFlowDemoBreakLabelArrayApp/?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
  • Friday, 20 November 2015

    Java Tutorial : Java Continue Statement with Label


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

    ContinueDemo.java
    public class ContinueDemo
    {
        public static void main(String[] args)
        {
    
            /*
             * The continue statement skips the current iteration of a for, while ,
             * or do-while loop. The unlabeled form skips to the end of the
             * innermost loop's body and evaluates the boolean expression that
             * controls the loop.
             */
    
            for (int i = 0; i < 2; i++)
            {
                System.out.println("i : " + i + "\n");
                for (int j = 0; j < 3; j++)
                {
                    if (j == 1)
                    {
                        continue;
                    }
                    System.out.println("j : " + j);
                }
    
                System.out.println("------------------------------");
            }
    
        }
    }
    
    Output
    i : 0
    
    j : 0
    j : 2
    ------------------------------
    i : 1
    
    j : 0
    j : 2
    ------------------------------
    
    ContinueWithLabelDemo.java
    public class ContinueWithLabelDemo
    {
        public static void main(String[] args)
        {
    
            /*
             * A labeled continue statement skips the current iteration of an outer
             * loop marked with the given label.
             */
    
            outer: for (int i = 0; i < 2; i++)
            {
                System.out.println("\n" + "i : " + i + "\n");
                for (int j = 0; j < 3; j++)
                {
                    if (j == 1)
                    {
                        continue outer;
                    }
                    System.out.println("j : " + j);
                }
    
                System.out.println("------------------------------");
            }
    
        }
    }
    
    Output
    i : 0
    
    j : 0
    
    i : 1
    
    j : 0
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/ControlFlowDemoContinuewithLabelApp.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/9f2088c41ff235b2716289e24cabde9d7d07fb91/BasicJava/ControlFlowDemoContinuewithLabelApp/?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