Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Tuesday 31 October 2017

Introduction of C Programming Language


C Tutorial - C Programming Language

C Programming Language Tutorial

In this post, We will cover the complete introduction of c programming language like what is c, where c programming is used, and the complete history of c language.

This tutorial will provide you an easy way to learn c programming language with complete information.

This c tutorial is useful for both beginners and experienced.

Let's learn c programming step-by-step.


What is C Programming Language?

C is a general purpose and computer programming language which is used to develop system application software.

C is the most widely used computer programming language by using c language we can develop system software and operating system. 

C programming language is also known as mother language and base language of all programming language.

Most of the all modern programming languages use syntax of 'C' language e.g C++, Java, etc. C is a structured programming language.

C is a simple and easy programming language for learners.

C programming can be compiled on the variety of computer platforms.


Where C is used?

We can use c programming for developing..
  • Compilers
  • Operating Systems(OS)
  • Text Editors
  • Databases 
  • Assemblers
  • Language Interpreters
  • Utilities
  • Network Drivers
  • Word Processors 

C programming language is also used for developing useful or major part of web browsers like Mozilla Firefox, Chrome, etc.

Oracle and MySQL databases are also written in c programming language.

Almost device drivers and UNIX operating system are written in c language.


History of C Programming Language

Dennis M. Ritchie - Founder of C Programming

C programming language is originally developed by Dennis M. Ritchie in 1972 at the Bell laboratories AT&T(American Telephone & Telegraph) in U.S.A. 

C programming language is basically developed by Dennis M. Ritchie to develop the UNIX operating system. Unix operating system is fully written in c programming.

Before C language, There were some programming languages like 

(1) Algol - Algol programming language developed by Cambridge University in 1960.

(2) CPL - Combined programming language developed by Cambridge University in 1963

(3) BCPL - Basic combined programming language developed by Martin Richards in 1967.

(4) B - B programming language developed by Ken Thompson at Bell labs in 1969.

(5) C - C programming language is developed by Dennis M. Ritchie at bell laboratories in 1972.


In 1989, C programming language standardized by ANSI(American National Standard Institute) which is known as "ANSI - C" or "C89".

In 1990, 95, 99 - C programming language standardized by ISO which is known as "C90", "C95", "C99", respectively.

In 2011, C programming language standardized by ISO again which is known as "C11".

Here we learned so many things about c programming language e.g the complete introduction of c programming language, Where we can use c language for developing applications, and detailed history of c programming language e.g who is the founder of c language and which year it is developed and other languages which are developed before c language and their years of developing.








Share:

Monday 30 October 2017

Difference Between JSON and XML

JSON vs XML

What is the Difference Between JSON and XML

Here we are going to discuss the difference between JSON and XML with simple examples. In the last post, We have discussed some examples of json technology i.e what is JSON but here we will see JSON vs XML comparison.

Let's start, What is the difference between JSON and XML and what is the advantages of JSON over XML.


JSON

  • JSON stands for JavaScript Object Notation.
  • JSON is easy to learn in comparison to XML.
  • JSON  is easy to read and write.
  • JSON does not use any opening(<>) and closing(</>) tags. 
  • JSON is data-oriented technology.
  • JSON is less secured than XML.
  • JSON is light-weight in comparison of XML.
  • JSON supports arrays.
  • JSON supports text and number data types.
  • JSON is less verbose than XML so it is faster to write programs in json.


JSON Example

This is simple example of json where will take student data with the help of json's object and array.

{"students" : [
    {"name" : "shiv", "section"  : "A", "city" : "delhi"},
    {"name" : "john", "section"  : "B", "city" : "mumbai"},
    {"name" : "varun", "section" : "C", "city" : "keral"}
]
}

Now moving to XML


XML

  • XML stand for eXtensible Markup Language.
  • XML is not easy to learn in comparison of JSON.
  • XML is less easy to read and write than JSON.
  • XML uses opening(<>) and closing(</>) tags to define data.
  • XML is documented-oriented technology.
  • XML is more secured than JSON.
  • XML is not light-weight than JSON.
  • XML does not support arrays.
  • XML supports text, number, chart, images, data types.
  • XML is more verbose than JSON, so it is not faster to write programs than JSON.

XML Example

This is a simple example of XML where we will define some data of students in XML format. Let's convert above JSON example to XML.

For example:

<students>
  <student>
    <name>shiv</name>
    <section>A</section>
    <city>delhi</city>
  </student>
<student>
    <name>john</name>
    <section>B</section>
    <city>mumbai</city>
</student>
<student>
    <name>varun</name>
    <section>C</section>
    <city>keral</city>
</student>
</students>

This was the differences between json and xml. Now let's discuss some similarities between JSON and XML.


Similarities Between JSON and XML

There are some similarities between json and xml and these are given below.
  • JSON and XML both are open and simple technology.
  • JSON and XML both are language - independent.
  • JSON and XML both are self - describing i.e human readable.
  • Internationalization is supported by JSON and XML because of both support unicode system.

Share:

Saturday 28 October 2017

What is JSON with Examples

JSON Tutorial

JSON Tutorial - What is JSON?

This JSON tutorial is useful for both beginners and experienced. In this JSON tutorial you will find all the useful examples related to JSON technologies.

Here we will see the definition and simple JSON examples in detail.


What is JSON?

JavaScript object notation(JSON) is a light weight and data-interchange format. JSON objects are used for transferring a data between client and server.

JSON is language independent and it is easy for human to read and write.

JSON supports string, array, objects, number, value.

JSON uses JavaScript syntax but only in text format just like XML.

We can use JSON with other programming language e.g Java, Python, C#, C++, Perl, JavaScript, Ajax, JQuery, Ruby, etc.

JSON is text and we can convert any JavaScript object into JSON and send JSON to the server.


History of JSON

JSON technology was invented by Douglas Crockford. 

JSON is an alternative of an XML. 

JSON is simple and easy to learn in comparison of XML.


Syntax of JSON

  • JSON allows to write a data in key and value pairs.
  • JSON uses commas(":") to separate the data.
  • JSON uses curly("{") braces to store objects.
  • JSON uses square bracket( "[") to store the array.

Let's take simple look of JSON data

{"students":[
{"name":"anurag", "address":"f13"},
{"name":"anurag", "address":"g43"}
]}

JSON final must be save with .json extension.


JSON data types

Some data types are supported by JSON technology which are given below.
  • String
  • Array
  • Boolean
  • Value
  • Object
  • Number
  • Whitespace
  • null

We can create JSON example with the help of objects and arrays. Let's create examples of JSON one-by-one with objects and arrays.

(1) JSON Object Examples

This is the simple json object example. Here we will use curly braces and  key & value pairs to represents json object where keys are string and values are json types and use comma to separate the data.

{
     "student": {
     "name" : "sunny", 
     "roll no" : 56,
     "monitor" true
}
}

In the above example, "student" is an object and "name", "roll no" and monitor is a key with string, number and boolean type values for the keys.

Each object can have different - different data such as text, number, boolean, etc. 


JSON Object Example with String

To represents string values we use double quotes("").

{
    "student": {
    "name" : "karan",  "address": "anand vihar"
  }
}


JSON Object Example with Number

{
   "student" : {
   "Integer" : 56,
   "fraction" : 1.23
 }
}

JSON Object Example with boolean

{
    "student" : {

    "weak" : false,

    "strong" : true
  }
}


Nested JSON Object Example

{
    "student" : {
    "name" : "anu",
    "rollo no" : 45,
   "address" : {
   "city" : "delhi",
   "pincode" : "65"
 }
}


(2) JSON Array Examples

JSON array can contains multiple and it can contains number, string, boolean, and objects in an JSON array.

We have to use square bracket [ to represents json array and for separation of values use comma.

JSON Array Example of String, Number, and Boolean

Json array string example:

["red", "blue", "black", "pink"]

Json array number example:

[2, 4, 1, 5]

Json array boolean example

[true, false]


JSON Array of Objects Example

{
    "students" : [
    {"name" : "raj", "email" : "raj@33", "roll no" : 10},
    {"name" : "numan", "email" : "numan@66", "roll no" : 15},
    {"name" : "ravi", "email" : "ravi@11", "roll no" : 125}
 ]
}

this is json array object example with 4 objects.


XML Example

XML representation of above example.

/* Start */

<students>
 <student>
  <name>raj</name>
  <email>raj@33</email>
  <roll no>10</roll no>
</student>

<student>

  <name>naman</name>

  <email>naman@66</email>
  <roll no>15</roll no>
</student>
<student>

  <name>ravi</name>

  <email>ravi@11</email>
  <roll no>125</roll no>
</student>
</students>

/* End */

finally, we have learned what is json , json array object example, json object example.

Share:

Tuesday 24 October 2017

Interface Programming Interview Questions in Java

Java Interface Programming Interview Questions

Interface Programming in Java

Now, Here we are going to discuss some important interface programming interview questions in java. Java interface is also a most important topic and mostly asked in any core java interviews.

Let's see some questions related to interface in java programming which is frequently asked in java interviews.


(1) What is the output of following program?

interface My
{
void fun();
}
class My1 implements My
{
void fun()
{
System.out.println("hi");
}
public static void main(String args[])
{
My1 m = new My1();
m.fun();
}
}

Output: compile time error

Explanation: By default all the methods of an interface are public and abstract and when we will implement or override a method in a class which implements interface then we have to use public modifier with method e.g public void fun(){} in My1 class.


(2) What is the output of the following program?

interface Demo
{
void show()
{
System.out.println("hi, i am good");
}
void run();
}
class Test implements Demo
{
public void run()
{
System.out.println("run fast");
}
public static void main(String args[])
{
Test t = new Test();
t.run();
}
}

Output: compile time error

Explanation: We can't keep method with body in interface before java 8 version but it possible to keep method body in interface of java 8 by using 'default' keyword.


(3) Can you identify the error in below program?

interface Demo
{
private int b;
}

Output: Illegal modifier for field b

Explanation: By default all the fields of an interface is public, static and final. 


(4) What is the output of the following program?

interface First
{
void test();
}
class Second implements First
{
public void test()
{
System.out.println("pass");
}
public static void main(String args[])
{
First f = new First();
f.test();
}
}

Output: compile time error

Explanation: We can't instantiate interface in java.


(5) What is the output of following program?

interface First
{
First()
{
System.out.println("hello");
}
void show();
}
class Test implements First
{
public void show()
{
System.out.println("how are you");
}
public static void main(String args[])
{
Test t = new Test();
t.show();
}
}


Output: compile time error

Explanation: We can't keep constructor in an interface.


(6) What is the output of a below program?

interface My
{
int i = 10;
}
class My1 implements My
{
void change()
{
i = 40;
System.out.println(i);
}
public static void main(String args[])
{
My1 m = new My1();
m.change();
}
}

Output: compile time error


(7) What is the output of following program?

interface First
{
void show();
}
interface Second
{
void display();
}
class Test implements First,Second
{
public void show()
{
System.out.println("first interface");
}
public void display()
{
System.out.println("second interface");
}
public static void main(String args[])
{
Test t = new Test();
t.show();
t.display();
}
}

Output: first interface
             second interface


(8) Declaration of below code is correct or incorrect?

class A
{
//statements
}
interface B extends A
{}

Output: incorrect because interface cannot extend a class

(9) Declaration of below code is correct or incorrect?

interface A
{
//statements
}
interface B extends A
{}

Output: correct because an interface can extend one or multiple interface at a time.


(10) What is the output of a following program?


interface First

{

void show();

}
interface Second
{
void display();
}
class Test implements First,Second
{
public void show()
{
System.out.println("first interface");
}
public void display()
{
System.out.println("second interface");
}
public static void main(String args[])
{
First f = new Test();
f.show();
f.display();
}
}

Output: compile time error

Explanation: To run the above program you can create....

1) Test t = new Test();
     t.show();
     t.show();

2) First f = new Test();
    Second s = new Test();
    f.show();
    s.display();


You can check String programming interview questions and inheritance programming interview questions in java.

This is the basic and important java interface programming interview questions and answers.  
Share:

Monday 23 October 2017

Insertion Sort Program in Java

Java Program on Insertion Sort Algorithm

Insertion Sort Algorithm Java

In the last posts, We have learned some sorting algorithm like bubble sort algorithm and selection sort algorithm. Now here we are going to discuss another sorting algorithm which is insertion sort algorithm. Here we will see insertion sort program in java.

Let's start insertion sort algorithm java programs step-by-step.


What is insertion sort algorithm?

Java insertion sort algorithm is easy and simple algorithm like bubble sort algorithm. By the help of insertion sort we can easily sort any array elements. Insertion sort algorithm builds the final sorted array or list one item at a time.

Java insertion sort repeatedly takes the next element from the un-sorted section of an array and insert it into the sorted section at the right position.

Initially, insertion sort takes first element as a sorted element and then take the second element and compare it with first element and if the second element is less than first element then swap two number that means the second element comes to first and first comes to the second position in an array. Again compare the third element with second and again swap number and so on ...... until get sorted array.


Advantage of insertion sort

  • Insertion sort algorithm is simple algorithm in java like bubble sort.
  • Insertion sort is stable in nature i.e insertion sort does not change the relative order of an elements with equal keys.

Disadvantage of insertion sort

There are one draw back of insertion sort is it is not suitable for large data set. It is suitable only small data set.


Time complexity of insertion sort algorithm

  • worst case: O(n^2)
  • average case: O(n^2)
  • best case: O(n^2)
  • worst case space complexity: O(1)

Here is your  insertion sort code java program using for loop and while loop.

Insertion Sort Example

This is simple example of insertion sort in java sorting algorithm. Where we will sort array elements by inserting un-sorted elements at correct position.

public class InsertionSortDemo
{
public static int[] insertionSort(int array[])
{
int temp;
for(int i = 1; i < array.length; i++)
{
for(int j = i; j > 0; j--)
{
if(array[j] < array[j - 1])
{
       temp = array[j];
       array[j] = array[j - 1];
       array[j - 1] = temp;
     }
  }
}

      return array;
}

static void displayArray(int inputarray[])
{
for(int i : inputarray)
{
System.out.print(i);
System.out.print(",");
}
System.out.println();
}
public static void main(String args[])
{
int array[] = {5,15,20,9,1,7,27};
System.out.println("before sorting elements");
displayArray(array);

int array1[] = insertionSort(array);
System.out.println("after sorting elements");
displayArray(array);
}
}

Output: before sorting elements
             5,15,20,9,1,7,27,
             after sorting elements
             1,5,7,9,15,20,27,

All the java sorting algorithm e.g bubble sort, merge sort, selection sort, insertion sort, quick sort are quite important for java written and oral interviews.

In the next post, We will learn another important java sorting algorithm e.g merge sort algorithm a quick sort algorithm with example.

I hope above example of java insertion sort program will be useful to you. This is useful article for core java interviews like other sorting programs.

Share:

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate