Category: java tutorial

java tutorial

History of java

History of Java:

Java is a programming language originally developed by James Gosling at Sun Microsystems. Java is an object-oriented language similar to C++. The language was initially called Oak after an oak tree that stood outside Gosling’s office, but a different organization named OAK TECHNOLOGIES was already trademarked the name. So they decided to rename the name to Java, a type of coffee which the developers were drinking while thinking of a new name. Hence you see a cup of hot tea as their logo in java applications.

JAMES  GOSLING

There are given the major points that describes the history of java:

  • James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. The small team of sun engineers called Green Team.
  • Originally designed for small, embedded systems in electronic appliances like set-top boxes.
  • Firstly, it was called “Greentalk” by James Gosling and file extension was .gt.
  • After that, it was called Oak and was developed as a part of the Green project.
  • Why Java named as “Oak”.
  • Why Oak? Oak is a symbol of strength and choosen as a national tree of many countries like U.S.A., France, Germany, Romania etc.
  • In 1995, Oak was renamed as “Java” because it was already a trademark by Oak Technologies.

Why Java Programming named as “Java”:

Why had they choosen java name for  java  language? The team gathered to choose a new name. The suggested words were “dynamic”, “revolutionary”, “Silk”, “jolt”, “DNA” etc. They wanted something that reflected the essence of the technology: revolutionary, dynamic, lively, cool, unique, and easy to spell and fun to say. According to James Gosling “Java was one of the top choices along with Silk”. Since java was so unique, most of the team members preferred java.

  • Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers “write once, run anywhere”, meaning that compiled Java code can run on all platforms that support Java without the need for recompilation. Java applications are typically compiled to bytecode that can run on any Java virtual machine regardless of computer architecture. As of 2016, Java is one of the most popular programming languages in use, particularly for client-server web applications, with a reported 9 million developers. The language derives much of its syntax from C and C++, but it has fewer low-level facilities than either of them.

Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers “write onc…

 

There were five primary goals in the creation of the Java language:

  1. It must be “simple, object-oriented, and familiar”.
  2. It must be “robust and secure”.
  3. It must be “architecture-neutral and portable”.
  4. It must execute with “high performance”.
  5. It must be “interpreted, threaded, and dynamic”.
  • Java version history

As of 20 March 2018, both Java 8 and 10 are officially supported. Major release versions of Java, along with their release dates:

  • JDK 1.0 (January 23, 1996)
  • JDK 1.1 (February 19, 1997)
  • J2SE 1.2 (December 8, 1998)
  • J2SE 1.3 (May 8, 2000)
  • J2SE 1.4 (February 6, 2002)
  • J2SE 5.0 (September 30, 2004)
  • Java SE 6 (December 11, 2006)
  • Java SE 7 (July 28, 2011)
  • Java SE 8 (March 18, 2014)
  • Java SE 9 (September 21, 2017)
  • Java SE 10 (March 20, 2018)
  • Java Runtime Environment

The Java Runtime Environment (JRE) released by Oracle is a freely available software distribution containing a stand-alone JVM (HotSpot), the Java standard library (Java Class Library), a configuration tool, and—until its discontinuation in JDK 9—a browser plug-in. It is the most common Java environment installed on personal computers in the laptop and desktop form factor. Mobile phones including feature phones and early smartphones that ship with a JVM are most likely to include a JVM meant to run applications targeting Micro Edition of the Java platform. Meanwhile, most modern smartphones, tablet computers, and other handheld PCs that run Java apps are most likely to do so through support of the Android operating system, which includes an open source virtual machine incompatible with the JVM specification. (Instead, Google’s Android development tools take Java programs as input and output Dalvik bytecode, which is the native input format for the virtual machine on Android devices.

  • Platform Independent 

A Java code will run on any JVM (Java Virtual Machine). Literally you can run same Java code on Windows JVM,                 Linux       JVM, Mac JVM or any other JVM practically and get same result every time.

  • Multithreaded

A thread in Java refers to an independent program. Java supports multithread which means Java is capable of                  running many tasks simultaneously, sharing the same memory.

  • Dynamic

Java is a Dynamic programming language which means it executes many programming behavior at Runtime and             don’t need to be passed at compile time as in the case of static programming.

  • Distributed

Java Supports distributed System which means we can access files over Internet just by calling the methods.

  • Portable

A Java program when compiled produce bytecodes. Bytecodes are magic. These bytecodes can be transferred via network and can be executed by any JVM, hence came the concept of ‘Write once, Run Anywhere(WORA)’.

  • Security

Unlike other programming Language where Program interacts with OS using User runtime environment of OS, Java provides an extra layer of security by putting JVM between Program and OS. Java compiler converts source code into bytecode which can understand by JVM only and it converts it into binary language , which is an encrypted form. So, bytecode makes java more secure.

 

  • High Level Programming Language

Java is a High Level Programming Language the syntax of which is human readable. Java lets programmer to concentrate on what to achieve and not how to achieve. The JVM converts a Java Program to Machine understandable language.

  • High Performance

Java make use of Just-In-Time compiler for high performance. Just-In-Time compiler is a computer program that turns Java byte codes into instructions that can directly be sent to compilers.

  • Places where Java is used

Java is implemented over a number of places in modern world. It is implemented as Standalone Application, Web Application, Enterprise Application and Mobile Application. Games, Smart Card, Embedded System, Robotics, Desktop, etc.

 

Features of JAVA

Features of java:

There is given many features of java.

  1. Simple
  2. Object-Oriented
  3. Portable
  4. Platform independent
  5. Secured
  6. Robust
  7. Architecture neutral
  8. Dynamic
  9. Interpreted
  10. High Performance
  11. Multithreaded
  12. Distributed

Simple: Java is simple programming language, because,

  • Java applications will take less memory and less execution time.
  • Java has removed all most all the confusion oriented features like pointers, multiple inheritance etc.
  • Java is using all the simplified syntaxes from C and C++.

Object-oriented:

Java is an object oriented programming language because , JAVA is able to store data in the form of objects only.

Java provides the flexibility in the case of the primitive data type and static data.

Primitive data type we can access directly and also using the wrapper class concept:

For ex:

Int a=10;

Or using Wrapper class:

Integer b=new Integer();

: b=10;

Also same thing for static data because we can access static data with the object or also without the object.
Basic concepts of OOPs are:
1.     Object

2.     Class

3.     Inheritance

4.     Polymorphism

5.     Abstraction

6.     Encapsulation

 

Platform Independent:

Java is platform independent programming language because, Java allows its applications to compile on one operating system and to execute on the another operating system. A platform is the hardware or software environment in which a program runs. It can be more clarified with the help of below example:

 

Secured:

Java is very good secure programming language, because:

  1. Java has provided an implicit component inside JVM in the form of “security manager” to provide implicit security.
  2. Java has provided a separate middleware services in the form of JAAS( Java Authentication and Authorization Services ) in order to provide web security.
  3. Java has provided very good predefined implementations for almost all well known network security algorithms.

Robust:

Java is Robust programming language because,

  1. Java provides memory management system in the form of heap memory management system, it is a dynamic memory management system, it allocates and deallocates memory for the objects at Runtime.
  2. Java provides Exception Handling mechanism because, Java has a predefined library to represent and handle almost all the generated exceptions in java applications.

Architecture-neutral:

Java is and Architecture Neutral Programming language because, Java allows its applications to compile on one H/w Architecture and to execute on another H/w Architecture. So basically we can conclude that Java language does not depend on the architecture of computer. Ex- In C programming, int data type occupies 2 bytes of memory for 32-bit architecture and 4 bytes of memory for 64-bit architecture. But in java, it occupies 4 bytes of memory for both 32 and 64 bit architectures.

Portable:

Java is a portable programming language because, JAVA is able to run its applications under all the operating systems and under all the H/W Systems.

Distributed:

By using Java language we are able to prepare two types of applicatios:

a.     Standalone Applications- if we design any java application without using Client-Server architecture then that application is called as Standalone Applications.

b.     Distributed Applications- if we design any java applications on the basis of client-server architecture then that java application is called as Distributed applications.

To prepare Distributed applications, Java has provided a separate module that is “J2EE/JAVA EE”.

Interpretative:

Java is both completive programming language and Interpretative language because:

1.     To check developers mistakes in java applications and to translate java program from High level representations to low level representation we need to compile java programs.

2.     To execute java programs, we need an interpreter inside JVM.

Multi-threaded:

A thread is like a separate program, executing concurrently. We can write Java programs that deal with many tasks at once by defining multiple threads. The main advantage of multi-threading is that it doesn’t occupy memory for each thread. It shares a common memory area. Threads are important for multi-media, Web applications etc.

 

High Performance:

Java is high performance programming language due to its rich set of features like platform independent, Arch Neutral, Portable, Robust, Dynamic etc.

 

 

Java Introduction

Introduction to java:

Java is a programming language created by James Gosling from Sun Microsystems  in 1991. The target of Java is to write a program once and then run this program on multiple operating systems. The first publicly available version of Java (Java 1.0) was released in 1996, Jan 23rd . Sun Microsystems was acquired by the Oracle Corporation in 2010. Oracle continues this project called Open  JDK.

Over the time new enhanced versions of Java have been released. The current version of Java is Java 1.8 which is also known as Java 8 which include the features like Lambda Expressions, Date time API, Updations on Collections, interface improvements.

Java Terminologies:

Java Virtual Machine (JVM):
This is generally referred as JVM. The different phases of program execution are as follows: we write the program, then we compile the program and at last we run the program.
i) Writing of the program is of course done by users.
ii) Compilation of program is done by javac compiler, javac is the primary java compiler included in java development kit (JDK). It takes java program as input and generates java bytecode as output.
iii) In third phase, JVM executes the bytecode generated by compiler. This is called program run phase. So, now that we understood that the primary function of JVM is to execute the bytecode produced by compiler. Each operating system has different JVM, however the output they produce after execution of bytecode is same across  all operating systems.

 

2) Bytecode:
Javac compiler of JDK compiles the java source code into bytecode so that it can be executed by JVM. The bytecode is saved in a .class file by compiler.

 

 

3) Java Development Kit(JDK):

JDK is defined as Java Development Kit. It physically exists. It contains JRE + development tools.

 

 

4) Java Runtime Environment(JRE)

JRE is an defined as Java Runtime Environment. It is used to provide runtime environment. It is the implementation of JVM. It physically exists. It contains set of libraries + other files that JVM uses at runtime.

 

 

abstract class in java

abstract class in java

Main motive to make the abstract class in java to make the standard . Standard always created by the developer and implemented by the programmer.

Let’s take an example:

class Bird
{
    public void flying();
}

Here we have created one standard with the name of flying but when we will make undefined function then function shouting…… either define me or declared as an abstract so we want to make standard then we will write abstract in front of the function.

class Bird
{
  abstract public void flying();
}

 

Now function don’t have any problem but normal class cannot contain undefined function or abstract function here class shouting either define the flying function or make class abstract.

  • Normal class cannot contain undefined function
  • Abstract class can contain defined and undefined function

Here you can see it would easily compile:

abstract class Bird
{
    abstract public void flying();
}

Also we can make defined function in the abstract class see here:

abstract class Bird
{

                abstract public void flying();
                public void breath()
                {
                                System.out.println("Birds Breathing");
                }

}

when we will compile the above program then no error will come see below screenshot:

abstract class in java

 

Implementation of the abstract class:

  • When we will make the standard in the java then programmer will implement the standard same here we will make another class there we will extend the abstract class and define the standard according to the requirement.

See in the example:

abstract class Bird
{
	abstract public void flying();
	
	public void breath()
	{
		System.out.println("Birds Breathing");
	}
}

class Sparrow extends Bird
{
	public void flying()
	{
		System.out.println("Sparrow is flying according to own strength");
	}
}

class Eagle extends Bird
{
	public void flying()
	{
		System.out.println("Eagle is flying according to own strength")
	}
}

In the Sparrow class we extend the Bird abstract class using the extends keyword in java. when we will extend the abstract class then there would be same scenario like normal Sparrow class cannot contain undefined function either We need to make Sparrow class the abstract class or need to define the abstract function and in the Sparrow class we have defined abstract function flying.

abstract class Bird
{
	abstract public void flying();
	
	public void breath()
	{
		System.out.println("Birds Breating");
	}
}

class Eagle extends Bird
{
	public void flying()
	{
		System.out.println("Eagle is flying according to own strength");
	}
	public static void main(String args[])
	{
		Eagle e1=new Eagle();
		e1.flying();
	}
	
}

Here above program will easily compile and execute:

Output of the above program: 

Eagle is flying according to own strength

  • We cannot instantiate the object of the abstract class 

In the above program 1 thing is missing Eagle class define the function and and we execute the flying function from the Eagle class object then what’s the benefit to make the abstract class here……

what exactly meaning of abstract class:

a) Developer will make the standard

b) Programmer will implement the standard 

c) After Developer will execute the standard

In the above example programmer implement the standard and programmer also execute the standard so we will make it simple.

See in this example:

abstract class Bird
{
	abstract public void flying();
	
	public void breath(Bird b)
	{
		b.flying();
	}
}

class Eagle extends Bird
{
	public void flying()
	{
		System.out.println("Eagle is flyig according to own strength");
	}
	public static void main(String args[])
	{
		Eagle e1=new Eagle();
		e1.breath(e1);
	}
	
}

Hope you like this tutorial and if you have any question then let me know!!!!!!!!!!! Thanks

Download PDF

ArrayList in java

ArrayList in java

ArrayList in java like a array in java but  size of ArrayList dynamic and arraylist store.

same type of data as well as different type data.

So we can say that arraylist overcome drawback of array in java

So firsto fall we need to understand  drawback of array.

Size of array is fix:

We know size of array is fix that means we can not enter any extra value in array

Example:

void x()

{

   int arr [] =new int [5]; // array declaration in java

  arr[0]=10; 

 arr[1]=11;

arr[2]=14;

arr[3]=16;

arr[4]=17;

}

now  if we want enter a value on like : arr[5] =20 ;then we will get a runtime exception

ArrayIndexOutOfBoundsException because 5th index is not available in array.

Store Only similar type of data:

array store only similar type of data that means if we will declare an integer type array

it will store only integer data we can not store any character,Boolean,float and String type of data.

 Example:

void x()

{

   int arr [] =new int [5]; // array declaration in java

  arr[0]=10; 

 arr[1]=10.6; // here we are putting decimal type of data so it will generate syntax error.  

arr[2]=14;

arr[3]=’c’ // here we are putting character type of data so it will generate syntax error.  

arr[4]=17;

}

so till now we are clear about drawbacks of java array.Those array drawbacks we can overcome

with help of java ArrayList class.

Syntax of ArrayList:

ArrayList it is a predefined class in java and available in java.util package and we know if

It is class then it is a non primitive data type.It is store data based on indexing same like array.

import java.util.ArrayList;      //  if we want use arraylist in our programme then we need to import it

ArrayList ar =new ArrayList();   // create a new object for arraylist class

ar.add(1;)    // with help of add() method we can put data in arraylist

System.out.println(ar.get(0)); // with help of get() method we can get data from arraylist

System.out.println(ar.size()); // with help of size() method we can get size of arraylist

 

 

Example:

 

import java.util.ArrayList;

class  ArrayListExample

   public static void main(String [] ar)

{

    ArrayList ar =new ArrayList();

    ar.add(1); //  here we are putting integer data

   System.out.println(ar.get(0));

   System.out.println(“size is::”+ar.size()); // currently arraylist size is 1

     ar.add(‘c’); //  here we are putting character data

      System.out.println(ar.get(1));

    ar.add(‘”abc”);  //  here we are putting string data

    System.out.println(ar.get(2));

    ar.add(10.10);  //  here we are putting decimal data

    System.out.println(ar.get(3));

    System.out.println(“now size is::”+ar.size()); // now arraylist size is 4

}

}

Output:

1

size is::1

c

abc

10.10

now size is::4

 

Hope so you like this article Thanks…….

 

 

 

 

 

 

 

 

 

for-each loop in java

for-each loop in java:

 

for-each loop in java basically design for traversing data from an array

we can use for-each with both type of array one –D array as well as two-D array.

But firsto fall we need to understand working and syntax of for-each loop .

 

Workflow diagram of for-each loop:

 

for-each loop syntax with One-D Array:

 

 

  for(data type variable name:One-D array)

  {

     //statement

  }

 

  Now time is to understand above syntax:

 

  First:          0   1  2

int [] arr={10,20,30};

  Second:

for(int i:)

this means data type of variable should be match with data type of array

  Third:

for(int i: arr)

  Fourth:
  for(int i: arr)

  {

    System.out.println("value of i is::"+i);

  }

this loop will run till (n-1) n=size of array and for this array size is 3

here i will print value of  index like [0]=10 ,[1]=20, [2]=30

 

  Example:

 

 

  class foreachwithOne_DArray

  {

    public static void main(String [] ar)

                {

      int [] arr={10,20,30};  //declaration of One-D Array

                 

                  for(int i:arr) //write for-each loop for traversing data from an One-D array

                  {

                   System.out.println("value of i is::"+i); // i will print value from array

                  }

                }

  }


  Output:

  value of i is::10

  value of i is::20

  value of i is::30

 

 

  for-each loop syntax with Two-D Array:

 

   for(data type  [ ]  name of One-D Array: Two-D Array)

    {

        for(data type variable name:One-D array)

         {

            //statement

          }

  }


  Now time is to understand above syntax:

 

We know that whenever we work on two d array then use nested loop first loop manage

row count and second loop manage column count.

 First:

int [] [] arr={{10,20,30}, {50,35,34}}; // Two-D Array declaration in java

(arr) Structure

012
 0102030
1503534

 

above array structure for two-d array.

Second:

for(data type  [ ]  name of One-D Array: Two-D Array)   // for(int [] arr1:arr) {  }

so in first iteration first row of array index (0) copy in  One-D array and this thing happen till

(n-1) here n is number of row count.

So structure of One-d array now is:

First Iteration:
012
0102030

 

Second Iteration:
012
0503534

 

Third:

for(data type variable name:One-D array) // for(int i:arr1) {  }

Example:

class foreachwithTwoDArray

                 {

    public static void main(String [] ar)

    {

            int [] [] arr={{10,20,30}, {50,35,34}};

          for(int [] arr1:arr)

            {

                 for(int k:arr1)

                 {

              System.out.print(k);

                  }                                                           

                   System.out.print("\n");

        }    } }


Output:

102030
503534

 

 

Hope so you like this article Thanks…

for loop in java

for loop in java:

for loop in java is more efficient loop as compared to while and do while loop.

 Because all necessary three steps for loop define in single line.

 For example we see in while loop like

int i=0; //1 step is initialization of loop

while(i<5) // condition of loop
{

      System.out.println(“value of i is::”+i);

      i++; i--; // increment or decrement
}

and in do while like this.

int i=0; //1 step is initialization of loop

do{

       System.out.println(“value of i is::”+i);

        i++; i--; // increment or decrement
 } while(i<5); // condition of loop

Now see same programme with for loop: but first to fall we need to understand

Syntax of for loop.

Workflow diagram of for loop:

 

you can see above basic flow diagram of for loop.

Working of for loop:

1.first initialization block like :

     for(int i=0;;)
2. Second block is condition block like:

      for(int i=0;i<5;)
3. Third block is increment or decrement block like:

     for(int i=0;i<5;i++)

all necessary three steps for loop define in a single line that is the
power of for loop.

 

for(int i=0;i<5;i++)
{
    //Statement
}

Now we need to understand working of for loop;

1 .First initialization block will run
2. After that conditional block will run then
3. if condition is true flow will go in body of loop and execute number of statement
those write with in loop body.
4. After that flow will go for increment or decrement block
5. After again flow will go for conditional block if condition is true then flow again will enter in body of loop.
6. if condition is false then flow exit from loop.
So that is working of for loop

Now we will solve above problem with help of for loop;

for(int i=1;i<=100;i++)
{
    System.out.println(i);
}

Output:

1
2
3
10
:
:
99
100

we make that programme with help of while loop ,do while loop and for loop
so we can see that most efficient way with for loop.

Infinite for loop:

if our condition never be false for loop then that loop will go in infinite state.

Example:

class test
{
public static void main(String [] ar)
{
    for(int i=0;i<5;) {
        System.out.println("test");
     }
}
}

Output:

test
test
test
test
till infinite time

Hope so you like this article Thanks…

do while loop in java

do while loop in java

Working of do while loop: do while loop is similar as while loop except that the condition is check after the statements are executed, so do while loop always execute at least one time either condition is true or false.

With while loop we can not enter in loop till condition is true.But in some cases we

Need to required enter in loop at least one time either condition is true or false.

Syntax of do-while loop:

do

{

code to be executed

Increment/decrement

} while(condition);

 

Or

 

do

{

Increment/decrement

code to be executed

} while(condition);

 

Workflow diagram for do while loop:

 

Example of do while loop:

class ExampleOfDoWhileLoop{

public static void main(String ar [])

{

System.out.println(“Before do while loop”);

int i=0;

 

do

{

System.out.println(“value of i is::”+i);

i++;

}

while(i<5);

System.out.println(“After do while loop”);

 

Output:  Before do while loop

value of i is::0

value of i is::1

value of i is::2

value of i is::3

value of i is::4

After do while loop

 

Example of while loop:

class ExampleOfDoWhileLoop1

{

public static void main(String ar [])

{

System.out.println(“Before do while loop”);

int i=0;

 

do

{

i++;

System.out.println(“value of i is::”+i);

 

}

while(i<5);

System.out.println(“After do while loop”);

 

Output:  Before do while loop

value of i is::1

value of i is::2

value of i is::3

value of i is::4

value of i is::5

After do while loop

 

Now we will solve above problem with help of do while loop;

int i=1;

do

{

System.out.println(i);

i++;

}

while(i<=100);

 

 

 

Output:

1

2

3

10

99

100

So now we can see with help of loop that programme complete in some statements

So this the power of looping in programming languages.

 

Infinite do while loop:    if our condition never be false for loop then that loop will go in infinite state.

 

Example :  int i=1;

do

{

System.out.println(i);

}

while(i<5);

Here we can see for this loop condition never be false so this programme will go in Infinite state.

 

Here we can see a another example of infinite do while loop:

int i=1;

do

{

System.out.println(i);

}

while (true);

while loop vs do while loop

The only time you should use do while loop is when you want to execute the statements

inside loop at least once time, either condition is true or false.

Otherwise it’s always better to use while loop.

 

while loop in java looks more cleaner than do while loop.

Hope so you like this article Thanks…

 

 

 

 

 

 

 

 

while loop in java

Working of while loop: with while loop first of all condition is check if condition is true then flow go to inside while loop and lines of code that write with in while loop  will execute line by line  that process happen again and again till condition is true.When condition return false then flow comes out of loop and jumps to the next statement after while loop.

Remember: We need to write increment or decrements statement with in while loop so that the loop variable value gets switch on each iteration, and some point of time condition returns false.So in that time execution of while loop is end otherwise loop would execute infinite time.

Syntax of while loop in java:

while(condition)

{

code to be executed

Increment/decrement

}

or

 

while(condition)

{

Increment/decrement

code to be executed

}

 

Workflow diagram for while loop:

 

 

Example of while loop:

class ExampleOfWhileLoop{

public static void main(String ar [])

{

int i=0;

System.out.println(“Before while loop”);

while(i<5)

{

i++;

System.out.println(“value of i is::”+i);

}

System.out.println(“After while loop”);

}

}

.

Output:  Before while loop

value of i is::1

value of i is::2

value of i is::3

value of i is::4

value of i is::5

After while loop

 

Example of while loop:

class ExampleOfWhileLoop1

{

public static void main(String ar [])

{

int i=0;

System.out.println(“Before while loop”);

while(i<5)

{

System.out.println(“value of i is::”+i);

i++;

}

System.out.println(“After while loop”);

}

}

Output:  Before while loop

value of i is::0

value of i is::1

value of i is::2

value of i is::3

value of i is::4

After while loop

 

Now we will solve above problem with help of while loop;

int i=1;

while(i<=100)

{

System.out.println(i);

i++;

}

Output:

1

2

3

.

10

..

99

100

So now we can see with help of loop that programme complete in some statements

So this the power of looping in programming languages.

 

infinite while loop:    if our condition never be false for loop then that loop will go

in   infinite state.

Example :  int i=1;

while(i<5)

{

System.out.println(i);

 

}

Here we can see for this loop condition never be false so this programme will go in

Infinite state.

Here we can see a another example of infinite while loop:

int i=1;

while (true)

{

System.out.println(i);

}

 

Above all example of while loop hope so you notice we can’t exit from loop till specify

Condition is false but in some cases we don’t need execute loop till condition is false.

Here an example: if we can say WAP for find a number from an array

While loop with One-D array :

import java.util.Scanner;

class ExampleOfWhileLoopWithArray

{

public static void main(String ar [])

{

Scanner sc=new Scanner(System.in);

int [] num={ 10,20,30,40,15 };

int i;   int i1=0;

System.out.println(“enter number for search”);

i=sc.nextInt();

int count=0;

while(i1< num.length)

{

if(num[i1]==i)

{

System.out.println(“number is find on index ::”+i1 + “and number is::”+i);       count++;      break;

}

i1++;

}

if(count==0)

{

System.out.println(“number is not find in array”);

}

}

}

so in this programme we can see whenever number will find then with help of break

keyword we will immediately out of loop. So we don’t need execute loop till condition is false.

Hope so you like this article Thanks….

 

 

 

Looping in java

Looping in java

Before we know about loop first to fall we need to understand which type of problem we will phase

If  we can imagine programming without loop.

Example: if we can say wap for print 1 to 100. And we don’t know about loops.

So what is our approach :

  1. System.out.print(“1 2 3 4 5……99 100”);
  2. And if we need output like this

1

2

3

99

100;

Then we will write System.out.println(“1”); System.out.println(“2”); System.out.println(“3”);

System.out.println(“99”); System.out.println(“100”);

So we can see if we don’t know about loop so our life in programming its so difficult whenever

We need to iteration in programme plus our time and efficiency of a programme both will effect.

So if you want overcome from this problem then one person is here for our help and that person

Name is loop.

What is loop: Looping in programming languages is a feature which facilitates the execution of a set of instructions/functions repeatedly while some condition evaluates to true. Java provides Four ways for executing the loops.

Following are- 

  1. While Loop
  2. Do While Loop
  3. For Loop
  4. For Each Loop

So now above  programme will make very easily with loops and complete with some statements.

Now next question is why java provide for way of looping?

Ans: all are use for looping purpose in java but way of working is totally different like

If i will say WAP for add two numbers

Then there is a different way to write this programme but output will be same.

First Way : int c=a+b;

System.out.println(“result of c is :”+c);

Second Way :   System.out.println(“output is this:”+a+b);

Third Way : System.out.println(“result is::”+10+20);

See output is same but way of working is different same if we will use looping in java then we have

Four ways but goal is same but we need to decide which way is better as per requirements.

Now first to fall we will solve above problem with help of while loop.

here is a link for that…

http://onlinetutorial.co.in/while-loop-in-java/

Now we will solve above problem with help of do while loop.

Top 10 programming languages of the future

Top 10 programming languages of the future

 

Programming Languages as this topic has been very influential as well as crucial in the IT industry. For helping many individuals to make the best language decision that accordingly fits your abilities so here are the suggestions hope you guys like it. 

Top 10 programming languages of the future

 

1. Java: Java is a language which has been a backbone in the world of computer programming about more than 20 years. Its popularity has been “write once, run anywhere”. Theoretically, which takes you to write Java program on any of the device, then compile it into low-level machine code, and then execute it with a Java Virtual Machine (JVM). This language is also favoured by nearly 90% of the phenomenon companies which uses to build the applications. A senior android developer has easy count on an average salary ranging from $74,000 to $130,000. So choosing java as your career option can really let you a fruitful life.

#Interesting Facts of Java:

  1. There are more than 10 million Java developer in the world.
  2. About 8 billion mobile phones are working in Java.
  3. More than 140 million TV sets.
  4. 95 percent of enterprises are using Java as their primary language.

 

2. Python: Python is considered as the most user friendly, versatile and clear programming language used by the developers. Python language has these features like syntax is clear, intuitive and which makes it a popular choice for beginners. To an average salary with the knowledge of Python one could easily earn up to $100,000. But with the predictions salary of the python developer can easily fluctuate between the 105,000 and higher.

#interesting Facts of Python:

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one– and preferably only one –obvious way to do it.
Although that way may not be obvious at first unless you’re Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea — let’s do more of those!

3. JavaScript:

JavaScript has been considered the most popular language by the developers. To a close degree 70% of the survey people have reported that they had been using only JavaScript in the past years. Developers still knows it will be still fore-and-after in the market as it is steadily in demand in many companies. A Senior JavaScript Developer, according to the predictions of market and compensation analysts, can easily count on an average salary of $92,000 as according to the study in the previous years it ranged within $90,000.

#Interesting Facts of Javascript:

  1. Web Development is dependent on the JavaScript.
  2. Backbone of the web Development.
  3. Object base Language
  4. Loved by hackers
  5. NULL is an Object
  6. NAN is a number

 

4. C/C++: C++/C is best known as an most streamlined and malleable language used for the creation of the desktop applications and server platforms. It is considered as the most popular and reliable. Knowledge of C++/c becomes as one of the main requirements in 7% of all job offers. To an average salary of an developer ranging reach at least $102,000 per year. To develop an android developer one should have the basics clear of these languages called c/c++ as these are the most basics of java, one should actually start learning these programming languages to choose java as your career option.

#Interesting Facts of C/C++:

  1. Initially C++ was called New C
  2. The first programming language for the computer was Plankalkul, but C language is seen as the first high-level programming language.
  3. C++ is a multi—paradigm language.

 

5. C# : This is basically pronounced as C Sharp, This language has become the popular due to programmers who uses tools developed by the Microsoft. C# 7.2 version was out in November which had new features like geared towards avoiding unnecessary copying. C#, is mostly like C++ which is basically used in video game development, C# is known for its simplicity and widespread use. To an average salary of a developer ranging reach at least to $89,000.

6. PHP: For the web developers the most preferred language which they use is the PHP. This is basically a server-side scripting language which powers to the great extent of 83% of website and is an back-end for Facebook, Wikipedia and Yahoo. PHP has become the most popular programming language. To an average salary of a developer ranging reach at least to $70,000.

7. Perl : Perl has been considered as the popular scripting language which is used for text manipulation and now also for the graphical programming, systems administration, and even more. It is used in a wide variety of projects. In 2017, due to the constant upward trend in earnings in the IT sector, developers in this language will earn no less than $100,000.

—————————————————————————————————————

array in java

array in java

An array is an indexed list of stored values . It stores homogeneous values in a continuous position.You can make an array of any type int, double, String, etc. All elements of an array must have the same type. In java, array gets memory at run-time because we create array using object (new keyword). The index starts at zero and ends at length-1.

array in java

Example:

int[ ] values = new int[5];

int values[ ]=new int[5]; // this will create object of proxy class, which is a temporary class

values[0] = 12; // CORRECT

values[4] = 12; // CORRECT

values[5] = 12; // WRONG!! compiles but

// throws an Exception

// at run-time

Have a demo with runtime exception

Arrays

An array is defined using TYPE[ ].

Arrays are just another type.

int[] values; // array of int , int[] is a type

int[][] values;// 2d array

 

Linear Arrays:

To create an array of a given size, use the operator new :

int[] values = new int[5];

or you may use a variable to specify the size:

int size = 12;

int[] values = new int[size];

 

Array Initialization:

Curly braces can be used to initialize an array.

It can ONLY be used when you declare the

variable.

int[ ] values = { 12, 24, -23, 47 };

Accessing Arrays:

To access the elements of an array, use the [] operator:

values[index]

Example:

int[] values = { 12, 24, -23, 47 };

values[3] = 18;// output will be 18 not 47 , as 47 is replaced by 18

int x = values[1] + 3; // {12,24,-23,18}

length variable : Each array has a length variable built-in that contains the length of the array.

int[] values =

int size = new int[12];

values.length; // 12

int[] values2 = {1,2,3,4,5}

int size2 =values2.length; // 5

String arrays:

public static void main (String[] arguments){

System.out.println(arguments.length);

System.out.println(arguments[0]);

System.out.println(arguments[1]);

}

Combining Loops and Arrays :

Looping through an array

Example 1:

int[] values = new int[5];

for (int i=0;i<values.length; i++)

{

values[i] = i;

int y = values[i] * values[i];

System.out.println(y);

}

//output

0

1

4

9

16

 

Looping through an array :

Example 2:

int[] values = new int[5];

int i = 0;

while (i < values.length) {

values[i] = i;

int y = values[i] * values[i];

System.out.println(y);  

i++;

} // output

0

1

4

9

16

Enhanced for loop is also used to retrieve elements from an array;

syntax :

for (datatype var : array)

{

// statements to be print

}

Example :

int ar[ ]={5,8,23,56,21};

for(int a : ar)

{

System.out.println(a);

}

//output :

5

8

23

56

21

Multidimensional Arrays:  It is defined as an array of array.

Example of 2D array:

datatype array_name[ ][ ]=new datatype[m][n];

Two subscript represents the 2 dimensional array where m represents the number of rows and n represents the number of columns in array. It will hold total m*n elements.

Example :

int data[ ][ ]=new int [3][2];

or

int data[ ][ ]={  {3,4,5},{6,3,5},{6,1,4}  };

345
635
614

Fetch elements using for-loop:

for(int i =0 ; i<data.length;i++)

{

for(int j=0;j<data[i].length;j++)

{

System.out.println(data[i][j]);

}

}

Using Enhanced for loop;

for(int s[ ] : data) // each element retrieve is an another linear array.

{

for(int t :  s)   //  each element retrieve is an integer.

{

System.out.println( t );

}

}

 

 

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.