Study Viral (Java Tutorials For Beginners - Step By Step)
  • Home
  • Java Tutorials
    • Core Java
    • Java Swing
    • MS Access JDBC Java Application
  • Facebook Page
  • Programs
    • C Programs
    • C++ Programs
    • Java Programs
    • Python Programs
  • UGC NET
  • Home
  • Java Tutorials
    • Core Java
    • Java Swing
    • MS Access JDBC Java Application
  • Facebook
  • Programs
    • C Programs
    • C++ Programs
    • Java Programs
    • Python Programs
  • UGC NET

Java Tutorial - 26 Enhanced For Loop in Java - StudyViral

 November 24, 2017     Java Tutorials     No comments   



Java Tutorial - 26 Enhanced For Loop in Java - StudyViral

Enhanced for Loop in JAVA
Enhanced for loop is used to scan/iterate an Array instead  of using traditional loops.
It was introduced in Java 1.5
We can also use it for iterate elements of Collection.

Enhanced is simple to use because it doesn't required condition to control the loop.
But it is inflexible beacause we can't use it to display individual element of array through index. It display all elements of array from first to last.


    public class DemoEnchacedLoop {
 public static void main(String[] args) {
  String str[] = {"abc","def","ghi","jkl","mno","pqr"};
  
  for(String s : str) {
   //System.out.println(s);
  }
  
  int ar[] = {1,2,3,4,5,6,7,8,9,10,11};
  for(int i : ar) {
   //System.out.println(i);
  }
  
  int arr[][] = {{22,33,44},{55,66,77},{88,99,10}};
  
  for(int a[]:arr) {
   for(int a1 : a) {
    System.out.print(a1+" ");
   }
   System.out.println();
  } 
 }
}

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Java Tutorial - 25 Array (2-Dimensional Array)in Java - Study Viral

 November 24, 2017     Java Tutorials     No comments   





Java Tutorial - 25 Array (2-Dimensional Array)in Java - Study Viral

2D (or 2 Dimensional Array)

Two-dimensional arrays are arrays of arrays.
Initializing two-dimensional arrays:
int[][] arr1 = new int[3][3];

The 1st dimension represent rows or number of one dimension, the 2nd dimension represent columns or number of elements in the each one dimensions.
int[][] arr2 = { {1,2,3}, {4,5,6}, {7,8,9} };
int[][] arr3 = new int[][] { {1,2,3}, {4,5,6}, {7,8,9} };
int[][] arr4 = new int[3][] { {1,2,3}, {4,5,6}, {7,8,9} };//error

You can initialize the row dimension without initializing the columns but not vice versa
int[][] x = new int[3][];
int[][] x = new int[][3]; //error

The length of the columns can vary for each row and initialize number of columns in each row.

int [][]x = new int [2][];
x[0] = new int[5];
x[1] = new int [5];

int [][]x = new int [3][];
x[0] = new int[]{0,1,2,3};
x[1] = new int []{4,5,6};
x[2] = new int[]{7,8,9,10,11};

Jagged array is array of arrays such that member arrays can be of different sizes,
i.e., we can create a 2-D arrays but with variable number of columns in each row.
These type of arrays are also known as Jagged arrays.

int x[] = {1, 2, 3};
int y[] = {6, 5, 4};
int z[] = {9, 8, 7};

int c[][]={x, y, z};
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Java Tutorial - 24 Array (One Dimensional Array) in Java - Study Viral

 November 24, 2017     Java Tutorials     No comments   



Java Tutorial - 24 Array (One Dimensional Array) in Java - Study Viral

An Array are continues memory allocation
which contains homogenous set of data.

An array is container object that holds a fixed
number of values of same/single type.

Array can be created as:

int arr1[] = {10,20,30,40,50};


int arr2[] = new int[] {10,20,30,40,50};


int arr3[] = new int[5];


we can find size of array by using
build-in property i.e. length
e.g.     arr3.length;
which returns int value

NOTE : Array always begins with index zero

We can't access array element beyond the range

We can't resize the array but can use same
refernce variable to new refernce array
e.g.  int ar[] = new int[5];
    ar[] = new int[10];


ArrayCopy
To copy array elements from one element
to another array, we use a static method
arraycopy from System class

public static void arraycopy(ar1,s_index,ar2,s_index,ar1.length);


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Java Tutorial 23 - Break and Continue in Java - Study Viral

 November 24, 2017     Java Tutorials     No comments   



Java Tutorial 23 - Break and Continue in Java - Study Viral

 Break – When break statement encountered inside a loop then the loop is terminated and program control resumes with the next statement after the loop structure.
        break;

Continue – When continue statement is encountered inside the loop with some condition then continue skipped that particular iteration and loop proceeds with next iteration.
        continue;


public class DemoBreakContinue {
    public static void main(String[] args) {       
        for(int i=1; i<=10 ;i++) {
            if(i==4) {
                continue;
            }
            System.out.println("i :: "+i);
        }
        System.out.println("wow i am out of loop");
    }
}
public class DemoBreakContinue {
    public static void main(String[] args) {       
        for(int i=1; i<=10 ;i++) {
            if(i==4) {
                break;
            }
            System.out.println("i :: "+i);
        }
        System.out.println("wow i am out of loop");
    }
} 
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Java Tutorial 22 - Nested Loops in Java - Study Viral

 November 24, 2017     Java Tutorials     No comments   

Java Tutorial 22 - Nested Loops in Java - Study Viral


A nested loop means a loop within a loop.
Or we can say an inner loop within the body of an outer loop.






A Clock is a fine example of nested loop where HOUR hand and MINUTE
hand all spin around the face of the clock.
The HOUR hand is like outer loop and MINUTE hand is like inner loop.
The HOUR hand only makes one revolution for every 60 of the MINUTE
hand’s revolution.(i.e. MINUTE hand increment it value by 1 ).


In case of pattern programs outer loop used for generating ROWS and inner
loop is used for generating COLUMNS for particular ROWS.
We can use it in patterns, 2D arrays and it just like GRID or table.



public class DemoNestedLoop {

 public static void main(String[] args) {
  
  for(int outer = 1;outer <=3 ; outer++) {
   for(int inner = 1; inner <=3 ; inner++) {
    System.out.println("outer :: "+outer +"\tinner ::"+inner);
   }
   System.out.println();
  }
  
  for(int i = 0;i <= 5; i++) {
   for(int j = 0;j < i; j++) {
    System.out.print(" "+j);
   }
   System.out.println();
  }
 }
}
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Java Tutorial 21- Loops in Java - Study Viral

 November 24, 2017     Java Tutorials     No comments   


Java Tutorial 21- Loops in Java - Study Viral
Loops are also known as an iteration statements.

Loops are used to repeat some set of code again and again until some condition is true.

In Java there are FOUR type of loops.

  1. —while loop
  2. —do-while loop
  3. —for loop
  4. —Enhanced for loop

Loop Requirements

  • Loop control variable
  • Initialize the loop control variable
  • Condition Check for loop
  • Increment/Decrements
Syntax While Loop
int a;   // Loop Control Variable
a = 0;   // Initialize Variable
while (a < 4)   // Condition Check
{
    System.out.println(“a :: ”+a);
    a++;   // Increment
}
Syntax do-while Loop
int a;  // Loop Control Variable
a = 0;  // Initialize Variable
do{
     System.out.println(“a :: ”+a);
     a++;  //Increment
} while (a < 4);  // Condition Check
Syntax for Loop
for( int i =0 ; i < 4 ; i++) 
{
     System.out.println(“a :: ”+a);
}
Loop Control Variable
Condition
Output
Increment
int a = 0
a<4 or 0<4 [True]
a :: 0
a++ (1)
int a = 1
a<4 or 1<4 [True]
a :: 1
a++ (2)
int a = 2
a<4 or 2<4 [True]
a :: 2
a++ (3)
int a = 3
a<4 or 3<4 [True]
a :: 3
a++ (4)
int a = 4
a<4 or 4<4 [False]
Loop Ended
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Java Tutorial 20 - Scanner Class - Study Viral

 November 12, 2017     Java Tutorials     No comments   




Java Tutorial 20 - Scanner Class - Study Viral



Scanner Class exists in java.util Package.
It is used to read input from keyboard and contains many methods which helps to store that input into primitive data-types as well as for String class objects.
Java Scanner class extends Object class and implements Iterator and Closeable interfaces.
A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods.

public byte nextByte( )
public short nextShort( )
public int nextInt( )
public long nextLong( )
public float nextFloat( )
public double nextDouble( )
public String next( )
public String nextLine( )

www.studyviral.in
Email : info@studyviral.in
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Java Tutorial 19 - Switch Case Statement - Study Viral

 November 12, 2017     Java Tutorials     No comments   



Java Tutorial 19 - Switch Case Statement - Study Viral

This video show the use of Switch Case Statement.
The switch statement is a multi-way branch statement. It provides an easy way to dispatch execution to different parts of code based on the value of the expression.
It can accepts byte, short, char, and int primitive data types.
 It also works with enumerated types, the String class, and a few special classes that wrap certain primitive types: Character, Byte, Short, and Integer.

www.StudYViraL.in
E-mail : info@studyviral.in
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Java Tutorial -18 - Introduction To Eclipse IDE for JAVA Programming

 November 12, 2017     Java Tutorials     No comments   




Introduction To Eclipse IDE for JAVA Programming.
In this video you can see how to download Eclipse and how to run you first java program in it.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Posts Older Posts Home

Facebook

StudyViral

Labels

Alphabet Pattern Binary Tree BLOB (Binary Large Object) Computer Networks Computer Science And Applications Paper-II Data Structure DBMS Digital Clock Digital Watch Extra Tutorials File Upload Find Age from Date of Birth Graph-Algorithms Java and J2EE web applications JAVA JDK 12 Java Mail API Java MySQL Java Programs Java Programs List Java Servlets Java Swing Java Swing With MySQL Database Java Tutorials JCalender KVS Compuer Science - January 2017 Question Paper MS Access JDBC Java Application Multiuser Login NETBEANS 11 IDE Occurrence of Digits in Number Operation System Pattern Program Reverse of String Sending Email Servlet Servlet Tutorial Software Engineering Star Struts 2 FrameWork Struts 2 Registration Form UGC NET JULY 2018 Windows Commands

Popular Posts

  • Program 01: Write a program to display/print your name.
     Program 01 - Write a program to display/print your name. This is a very basic and introductory program in Java. You might see similar p...
  • Install NetBeans 11 IDE on Windows 10 - Study Viral
    Install NetBeans 11 IDE on Windows 10 - Study Viral How to Install NetBeans 11 IDE on Windows 10. Download Link : https://netbeans...
  • Create CON, AUX, NUL name folder and files in Windows - Study Viral
    Create CON, AUX, NUL name folder and files in Windows - Study Viral Most of you may be aware of many MS-DOS commands but still n...

Categories

  • Alphabet Pattern (13)
  • Binary Tree (2)
  • BLOB (Binary Large Object) (1)
  • Computer Networks (2)
  • Computer Science And Applications Paper-II (40)
  • Data Structure (6)
  • DBMS (1)
  • Digital Clock (1)
  • Digital Watch (1)
  • Extra Tutorials (3)
  • File Upload (1)
  • Find Age from Date of Birth (1)
  • Graph-Algorithms (1)
  • Java and J2EE web applications (3)
  • JAVA JDK 12 (1)
  • Java Mail API (3)
  • Java MySQL (5)
  • Java Programs (44)
  • Java Programs List (3)
  • Java Servlets (3)
  • Java Swing (16)
  • Java Swing With MySQL Database (4)
  • Java Tutorials (37)
  • JCalender (1)
  • KVS Compuer Science - January 2017 Question Paper (6)
  • MS Access JDBC Java Application (6)
  • Multiuser Login (1)
  • NETBEANS 11 IDE (1)
  • Occurrence of Digits in Number (1)
  • Operation System (4)
  • Pattern Program (8)
  • Reverse of String (2)
  • Sending Email (1)
  • Servlet (3)
  • Servlet Tutorial (3)
  • Software Engineering (4)
  • Star (7)
  • Struts 2 FrameWork (2)
  • Struts 2 Registration Form (1)
  • UGC NET JULY 2018 (40)
  • Windows Commands (2)

Pages

  • Java Tutorials
  • ASP.NET (in Hindi)
  • Java Programs List

Blog Archive

  • ►  2021 (3)
    • ►  April 2021 (3)
  • ►  2019 (7)
    • ►  June 2019 (1)
    • ►  May 2019 (2)
    • ►  March 2019 (4)
  • ►  2018 (111)
    • ►  November 2018 (7)
    • ►  October 2018 (20)
    • ►  September 2018 (10)
    • ►  August 2018 (3)
    • ►  July 2018 (19)
    • ►  June 2018 (5)
    • ►  May 2018 (2)
    • ►  April 2018 (3)
    • ►  March 2018 (11)
    • ►  February 2018 (18)
    • ►  January 2018 (13)
  • ▼  2017 (36)
    • ►  December 2017 (10)
    • ▼  November 2017 (9)
      • Java Tutorial - 26 Enhanced For Loop in Java - Stu...
      • Java Tutorial - 25 Array (2-Dimensional Array)in J...
      • Java Tutorial - 24 Array (One Dimensional Array) i...
      • Java Tutorial 23 - Break and Continue in Java - St...
      • Java Tutorial 22 - Nested Loops in Java - Study Viral
      • Java Tutorial 21- Loops in Java - Study Viral
      • Java Tutorial 20 - Scanner Class - Study Viral
      • Java Tutorial 19 - Switch Case Statement - Study V...
      • Java Tutorial -18 - Introduction To Eclipse IDE fo...
    • ►  October 2017 (7)
    • ►  September 2017 (10)

About Me

Rohit Basra
Hello guys my name Rohit Basra. I love to code and teach java language.
View my complete profile

Followers

Copyright © Study Viral (Java Tutorials For Beginners - Step By Step) | Powered by Blogger