Saturday, March 4, 2017

Multilevel Inheritance Java

In Multilevel Inheritance the Subclass of one superclass is acting as a Superclass for another subclass. Hence the members of both superclass are present in the subclass.

Following code will illustrate the concept:

Code::
import java.util.*;
class A
{
    int a;
}
class B extends A
{
    int b;
}
class C extends B
{
    int c;
    void show()
    {
        System.out.println(a+b+c);                //a,b are members of superclass
    }
}
public class Multilevel
{

    public static void main(String[] nt)
    {   C ob=new C();
        Scanner in =new Scanner(System.in);
        System.out.print("Enter First Number:");
        ob.a=in.nextInt();
        System.out.print("Enter Second Number:");
        ob.b=in.nextInt();
        System.out.print("Enter Third Number:");
        ob.c=in.nextInt();
        System.out.print("Sum is: ");
        ob.show();
    }
   
}

Output::
Java Does not Support Multiple Inheritance Because in Multiple Inheritance if Two Classes have same members then its an ambiguity for Subclass to use which member.  So There is no Multiple Inheritance in Java. But we can achieve this with the help of Interfaces.

Single Inheritance Java

Inheritance is  a feature of reusing the code.Without starting from scratch we can create a new class(Child,Subclass) having all features of old(Parent,Superclass) in addition to its own features.

Syntax:  class Subclass name extends Superclass name
{

//body of sub class

}

Following Code will illustrate the concept:

Code::

class Super
{
    int a,b;
    void show()
    {
        System.out.println(a+b);
    }
}
class Sub extends Super
{
    int c;
    void display()
    {
        System.out.println(a+b+c);     // a,b are the members of superclass
    }
}
public class Inheritance
{

    public static void main(String[] nt)
    {
        Super ob=new Super();
        Sub ob2=new Sub();
        ob.a=50;
        ob.b=20;
        ob2.a=50;
        ob2.b=20;
        ob2.c=10;
        ob.show();
        ob2.display();
    }
}

Output::
Above example also illustrate the fact that we can use a superclass itself.

Tuesday, February 28, 2017

Linux Commands

Commands:

1.cd(Change Directory):
cd                               :for home directory
cd name of directory :will move the control to that directory
cd ..                            :move out of the current directory
cd ../..                         :move out two times of the current directory

2.ls:

ls                                :List the contents of current Directory
ls -a                            :List all the files including hidden files

Example of cd and ls:


3.pwd(Print Working Directory):

pwd                            :print the current working directory
Example:


4.man : command is used for getting details of any command

Example:
5. mkdir : command is used for making a directory/folder in the current directory

Example:
6.rm : command is used for deletion of a file
   rmdir: command is used for deletion of a directory/folder
   rm -r: command is used for deletion of a non empty folder/directory
Example:
7.history: command is used to check all the previous commands used
Example:

8.whoami: command is used to find username
9. uname: command reports basic information about computer hardware and software
Example:

10.top: top command is used to see the currently running  processes with ram usage
Example:

11.gedit:  gedit is used to create a file
Syntax : gedit file name
Example:
12.touch: this command is used to create an empty file
Syntax: touch filename
Example:
13.cat : cat command is used to show the comments of any file in terminal
Example:
this command can also be used to create a file

Syntax:  cat > file name   (Replace the previous contents)
              cat >> file name (append the file)
Example:
14.vi : this command is used to create a file in terminal using vi editor
Syntax: vi filename
Example:
In Vi Editor First Press i To Start Writing
Then For Ending Press ESC key the use any of following
:wq - for closing and saving file
:q!-   for closing without saving
:w-    for saving only

15.cp : command is used to copy file
Syntax: cp source file destination file
Example:
16.mv : command is used to move one file to another location
Syntax: mv source destination
 Can also be used for renaming a file
Example:
17.diff : this command is used to find difference between two files
Syntax: diff file1 file2
Example:



This command also tells how to make two files identical

c - change the contents
a - append the contents
d - delete the contents

18.more:  this command is used to view the contents of file
      Syntax: more filename

19.head :  this command is used to view the first 10 lines of file
       Syntax: head filename
Here we can also specify the no of lines required
            For ex: head -3 filename will print three first lines

20. tail  :   this command is used to view the last 10 lines of file

In this we can also specify the no of lines
            For ex: tail -3 filename   will view the last three lines

Example:
21. df  :  this command is used to view the memory available and used by various drives
            for ex : df -h
-h for Human readable format
we can also specify ant particular drive to get info about that only.

22. du : this command is used to get the memory occupied by a particular directory with a list of all subdirectories.

For ex :  du -sh Directory
Here s for simple only Directory no subdirectory listing,h for human readable

Example:
 23. lsblk: this command print all block devices all tell the type of device

Example:
 24. htop: htop command is used to view the currently running processes of the particular user

Example:

Monday, February 27, 2017

Transmission Media and Tools

Transmission Media:  Transmission media is the mean through which we send out data from one place to another.The first layer of connection networks,OSI seven layer model is dedicated to the transmission media.

1.Guided Transmission Media:
     
     a.Coaxial Cable:
     b.Twisted Pair Cable:
      c.Optical Fibre:
2.Unguided Transmission media:
        a.Radio Waves
        b.Micro waves
        c.Infrared


Tools:

Crimping Tool:
Connectors:

a.RJ 45 and RJ 11:
b.ST,SC,F and  LC:

Networking Devices

Networking Devices are components used to connect computers or other devices together so that they can share files or resources like printers .Devices may be used to setup a LAN network or in connecting different LAN Networks.


1.Network Interface Card(Lan Adapter):

2.Hub:

3.Switches:









4.Router:
5.Bridges:
6.Host:
7.Repeaters:
8.Modem:

Saturday, February 25, 2017

Pythagorean Triplets Java

A Pythagorean Triplet is a set of 3 values a, b and c such that the sum of squares of a and b is equal to  square of c.
(a*a) + (b*b)  = (c*c)
Following Program Displays the Pythagorean Triplets upto a user desired value.

import java.util.Scanner;
public class Triplets {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int a, b, c;
        System.out.println("Enter the value of n: ");
        int n = in.nextInt();
        System.out.println("Pythagorean Triplets upto " + n + " are:\n");
        for (a = 1; a <= n; a++) {
            for (b = a; b <= n; b++) {
                for (c = 1; c <= n; c++) {
                    if (a * a + b * b == c * c) {
                        System.out.print(a + ", " + b + ", " + c);
                        System.out.println();
                    }
                   
                    else
                        continue;                  
                }
            }
        }
    }
}




Friday, February 24, 2017

Inclusion Exclusion Principle

Inclusion Exclusion Principle is Used to Calculate Cardinality of Union or Intersection of Sets

For Example:
n(a or b)=n(a)+n(b)-n(a&b)

Following Code will calculate the Intersection of Sets Using Inclusion Exclusion Principle

Code:

//Program to Calculate Cardinality of Intersection of sets Using Inclusion Exclusion Principle
import java.util.*;
public class IncExcP 
{
    public static void main(String[] nt) 
    {
        Scanner in=new Scanner (System.in);
        System.out.print("Enter Number of sets: ");
        int n=in.nextInt();
        int [][] s=new int[n][];
        System.out.println("Enter Cardinality Type Wise (i.e:Singles,Pairs,Triples etc): ");
        for(int i=1;i<n;i++)
        {  s[i]=new int[choose(n,i)];
            for(int j=0;j<choose(n,i);j++)
            {
                s[i][j]=in.nextInt();
            }
            if(i==n-1)
            {
                break;
            }
            System.out.println("Enter Next Type");
        }
        System.out.print("Enter Value of Union:");
        int u=in.nextInt();
        int [] sum=new int[n];
        for(int i=1;i<n;i++)
        {
            for(int j=0;j<choose(n,i);j++)
            {
                sum[i]=sum[i]+s[i][j];
            }
        }
        int x=u;
        for(int i=1;i<n;i=i+2)
        {
            x=x-sum[i];
        }
        for(int i=2;i<n;i=i+2)
        {
            x=x+sum[i];
        }
        if(n%2==0)
        {
            x=-x;
        }
        System.out.println("Intersection: "+x);
    }
    public static int choose(int n,int i)
    {   int result=1;
        for(int j=1;j<=i;j++)
        {
            result=result*(n-j+1)/j;
        }
        return result;
    }
}

Output:
For example: