Untitled 1

            The internet architecture can be broadly classified into three layers. The very first layer consists of Internet Backbones and very high speed network lines. The National ScienceFoundation (NSF) created the first high-speed backbone in 1987 called NSFNET, it was a T1 line that connected 170 smaller networks together and operated at 1.544 Mbps (million bitsper second). IBM, MCI and Merit worked with NSF to create the backbone and developed a T3 (45Mbps) backbone the following year. Backbones are typically fiber optic trunk lines.The trunk line has multiple fiber optic cables combined together to increase the capacity. Fiber optic cables are designated OC-48 can transmit 2,488 Mbps (2.488 Gbps). The nodes are known as Network Access Point (NAPs). The second layer is usually known as Internet Service Provider (ISP). The ISPs are connected to the Backbones at NAP’s with high speed lines. /-The end users which are part of third layer are connected to ISPs by dial up or leased lines and modems. The speed of communication is usually 1400 bps to 2048 kbps. /- In the real Internet, dozens of large Internet providers interconnect at NAPs ( Network Access Point) in various cities, and trillions of bytes of data flow between the individual networks at these points. The Internet is a collection of huge corporate networks interconnected with one other at the NAPs, backbones and routers to talk to each other. A message can leave one computer and travel halfway across the world through several different networks and arrive at another computer in a fraction of a second. /-The routers determine where to send information from one computer to another. Routers are specialized computers that send messages to their destinations along thousands of pathways. It joins two networks, passing information from one to the other.  /-There are different Protocols Used in Internet is Given Below- /-Transmission Control Protocol/Internet Protocol-/The TCP or IP Protocol is a collection of Protocol or a rule that governs the way data travels from one machine to another Machine across the network.This TCP or IP is an common Protocol that provides reliable transfer of data.This protocol is responsible for assembling data passedfrom higher layer application to standard packets. /-File Transfer Protocol-/This popularly Known as FTP file control Protocol is simply a method of transferring file on the internet using ftp,you can both(upload) and receive (download) files from ftp sites on the internet.-/File Transfer protocol is one of the basic services on the internet.This FTP simply means sending a file (not a message)from one computer to another.FTP is a part of TCP/IP protocol and it is very powerful .You can use ftp with ypur browser or you can use an FTP client program In either case ,an FTP address starts out with “ftp://” /-HTTP/-The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, and hypermedia information systems.[1] HTTP is the foundation of data communication for the World Wide Web. Hypertext is structured text that uses logical links (hyperlinks) between nodes containing text. HTTP is the protocol to exchange or transfer hypertext. Development of HTTP was initiated by Tim Berners-Lee at CERN in 1989.

Telnet is a protocol that allows you to connect to remote computers (called hosts) over a TCP/IP network (such as the internet). Using telnet client software on your computer, you can make a connection to a telnet server (i.e., the remote host). Once your telnet client establishes a connection to the remote host, your client becomes a virtual terminal, allowing you to communicate with the remote host from your computer. In most cases, you’ll need to log into the remote host, which requires that you have an account on that system. Occasionally, you can log in as guest or public without having an account.



Java Operator Types

A Java operator is a special symbol that performs specific operation on one, two, or three operands depending upon the type of the operator and returns a result. /-Java provides a rich set of operators that are classified on two bases. First, on the basis of number of operands an operator performs upon. Second, on the type or nature of operation an operator performs. /-By first classification, Java operators can be unarybinary, or ternary. Unary operators operate on one operand e.g., ++, and --. Binary operators operator on two operands. All arithmetic operators are example of binary operators. Third, special type operator is ternary operator. Ternary operator operates on three operands. Java has only one ternary operator, which is also called conditional operator. It is a combination of two symbols ? and :./-Java Operators Precedence and Associativity /-Java operators have two properties those are precedence, and associativity. Precedence is the priority order of an operator, if there are two or more operators in an expression then the operator of highest priority will be executed first then higher, and then high. For example, in expression 1 + 2 * 5, multiplication (*) operator will be processed first and then addition. It’s because multiplication has higher priority or precedence than addition.

PrecedenceOperatorDescriptionAssociativity
1[] 
() 
.
array index 
method call 
member access
Left -> Right
2++ 
— 
+ – 

!
pre or postfix increment 
pre or postfix decrement 
unary plus, minus 
bitwise NOT 
logical NOT 
Right -> Left
3(type cast) 
new
type cast 
object creation 
Right -> Left
4

%
multiplication
division
modulus (remainder)
Left -> Right
5+ – 
+
addition, subtraction 
string concatenation
Left -> Right
6<>
>> 
>>>
left shift 
signed right shift 
unsigned or zero-fill right shift
Left -> Right
7<>
<>

>= 
instanceof
less than 
less than or equal to 
greater than 
greater than or equal to 
reference test
Left -> Right
8== 
!=
equal to 
not equal to
Left -> Right
9
bitwise ANDLeft -> Right
10^bitwise XORLeft -> Right
11|bitwise ORLeft -> Right
12&&logical ANDLeft -> Right
13||logical ORLeft -> Right
14? :conditional (ternary)Right -> Left
15
+= 
-= 
*= 
/= 
%= 
&= 
^= 
|= 
<>
>>= 
>>>=
assignment and short hand assignment operatorsRight -> Le


Inheritance is an important pillar of OOP(Object Oriented Programming). It is the mechanism in java by which one class is allow to inherit the features(fields and methods) of another class.
Important terminology:

  • Super Class: The class whose features are inherited is known as super class(or a base class or a parent class).
  • Sub Class: The class that inherits the other class is known as sub class(or a derived class, extended class, or child class). The subclass can add its own fields and methods in addition to the superclass fields and methods.
  • Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to create a new class and there is already a class that includes some of the code that we want, we can derive our new class from the existing class. By doing this, we are reusing the fields and methods of the existing class. /-Types Of Inheritance :/-Here are the different types of inheritance in Java. Lets see each and every type with neat example./-Single Inheritance : /-Single inheritance is a simple and easy to understand. A class is created by extending an another class is called Single inheritance. /-On the above diagram Class B is extended from Class A, then this type of deriving is called single inheritance. Here class A is a parent class of class B. In other words, Class B is a child of Class A.

Exmple:

class A { /-public String meth() {
return "A's Method";
}
}
class B extends A {
public String meth() {
return "B's Method";
}
public String meth2() {
return "B's Method2";
}
}
public class SingleInheritanceDemo {
public static void main(String[] args) {
B b = new B();
System.out.println("B : " + b.meth());
}
}

Multiple Inheritance : /-Multiple Inheritance means A class created by deriving more than one super class is called as Multiple Inheritance.

 On the above diagram refers multiple inheritance: Here Class C is derived from Class A and Class B.

This is one of rarely used inheritance type in software development. Because it leads some unwanted complexity when further extending the classes. Because of this reason, some of the languages like Java, C# and Smalltalk doesn’t support the Multiple inheritance. /-Multilevel Inheritance /-:Multilevel Inheritance refers to when a class extends from another class which extends another class is called Multilevel inheritance. On the above diagram represents the multilevel inheritance, here Class C extended from Class B and Class B extended from the Class A, /-Hierarchical Inheritance :

When multiple classes are inherited from a single class is called Hierarchical inheritance.

On the above diagram Class B and Class C are inherited from a single class A, this represents the Hierarchical inheritance.

Example:

Hybrid Inheritance :

The Hybrid inheritance is the combination of both the Single and Multiple inheritances.

The hybrid inheritance is achieved with the interfaces in Java.



Introduction to Multithreading

A program can be divided into a number of small processes. Each small process can be addressed as a single thread (a lightweight process). You can think of a lightweight process as a virtual CPU that executes code or system calls. You usually do not need to concern yourself with lightweight processes to program with threads. Multithreaded programs contain two or more threads that can run concurrently and each thread defines a separate path of execution. This means that a single program can perform two or more tasks simultaneously. For example, one thread is writing content on a file at the same time another thread is performing spelling check.

In Java, the word thread means two different things.

  • An instance of Thread class.
  • or, A thread of execution./-An instance of Thread class is just an object, like any other object in java. But a thread of execution means an individual “lightweight” process that has its own call stack. In java each thread has its own call stack.

The main thread

When we run any java program, the program begins to execute its code starting from the main method. Therefore, the JVM creates a thread to start executing the code present in main method. This thread is called as main thread. Although the main thread is automatically created, you can control it by obtaining a reference to it by calling currentThread() method. /-Two important things to know about main thread are,

  • It is the thread from which other threads will be produced.
  • main thread must be always the last thread to finish execution.

Life cycle of a Thread

  1. New : A thread begins its life cycle in the new state. It remains in this state until the start() method is called on it.
  2. Runnable : After invocation of start() method on new thread, the thread becomes runnable.
  3. Running : A thread is in running state if the thread scheduler has selected it.
  4. Waiting : A thread is in waiting state if it waits for another thread to perform a task. In this stage the thread is still alive.
  5. Terminated : A thread enter the terminated state when it complete its task

Thread Priorities

Every thread has a priority that helps the operating system determine the order in which threads are scheduled for execution. In java thread priority ranges between 1 to 10,

  • MIN-PRIORITY (a constant of 1)
  • MAX-PRIORITY (a constant of 10) /-By default every thread is given a NORM-PRIORITY(5). The main thread always have NORM-PRIORITY./-Thread priorities cannot guarantee that a higher priority thread will always be executed first than the lower priority thread. The selection of the threads for execution depends upon the thread scheduler which is platform dependent


Layout means the arrangement of components within the container. In other way we can say that placing the components at a particular position within the container. The task of layouting the controls is done automatically by the Layout Manager. /-Layout Manager /-The layout manager automatically positions all the components within the container. If we do not use layout manager then also the components are positioned by the default layout manager. It is possible to layout the controls by hand but it becomes very difficult because of the following two reasons.

  • It is very tedious to handle a large number of controls within the container.

  • Oftenly the width and height information of a component is not given when we need to arrange them. /-Java provide us with various layout manager to position the controls. The properties like size,shape and arrangement varies from one layout manager to other layout manager. When the size of the applet or the application window changes the size, shape and arrangement of the components also changes in response i.e. the layout managers adapt to the dimensions of appletviewer or the application window./- The layout manager is associated with every Container object. Each layout manager is an object of the class that implements the LayoutManager interface. /-Following are the interfaces defining functionalities of Layout Managers.

Sr. No.Interface & Description
1

LayoutManager

The LayoutManager interface declares those methods which need to be implemented by the class whose object will act as a layout manager.

2

LayoutManager2

The LayoutManager2 is the sub-interface of the LayoutManager.This interface is for those classes that know how to layout containers based on layout constraint object.

AWT Layout Manager Classes: /-Following is the list of commonly used controls while designed GUI using AWT.

Sr. No.LayoutManager & Description
1

BorderLayout

The borderlayout arranges the components to fit in the five regions: east, west, north, south and center.

2

CardLayout

The CardLayout object treats each component in the container as a card. Only one card is visible at a time.

3

FlowLayout

The FlowLayout is the default layout.It layouts the components in a directional flow.

4

GridLayout

The GridLayout manages the components in form of a rectangular grid.

5

GridBagLayout

This is the most flexible layout manager class.The object of GridBagLayout aligns the component vertically,horizontally or along their baseline without requiring the components of same size.



Data type

Data type specifies the size and type of values that can be stored in an identifier. The Java language is rich in its data types. Different data types allow you to select the type appropriate to the needs of the application.

Data types in Java are classified into two types:

Primitive—which include Integer, Character, Boolean, and Floating Point.

Non-primitive—which include Classes, Interfaces, and Arrays.

Primitive Data Types

1. Integer

Integer types can hold whole numbers such as 123 and −96. The size of the values that can be stored depends on the integer type that we choose.

TypeSizeRange of values that can be stored
byte1 byte−128 to 127
short2 bytes−32768 to 32767
int4 bytes−2,147,483,648 to 2,147,483,647
long8 bytes9,223,372,036,854,775,808 to
9,223,372,036,854,755,807

The range of values is calculated as −(2n−1) to (2n−1)−1; where n is the number of bits required. For example, the

 byte data type requires 1 byte = 8 bits. Therefore, the range of

 values that can be stored in the byte data type is −(28−1) to (28−1)−1
= −27 to (27) -1

= −128 to 127

2. Floating Point

Floating point data types are used to represent numbers with a fractional part. Single precision floating point numbers occupy 4 bytes and Double precision floating point numbers occupy 8 bytes. There are two subtypes:

TypeSizeRange of values that can be stored
float4 bytes3.4e−038 to 3.4e+038
double8 bytes1.7e−308 to 1.7e+038

3. Character

It stores character constants in the memory. It assumes a size of 2 bytes, but basically it can hold only a single character because char stores unicode character sets. It has a minimum value of ‘u0000’ (or 0) and a maximum value of ‘uffff’ (or 65,535, inclusive).

4. Boolean

Boolean data types are used to store values with two states: true or false.



Packages are used in Java in order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations easier, etc.

Package can be defined as a grouping of related types (classes, interfaces, enumerations and annotations ) providing access protection and namespace management.

Some of the existing packages in Java are −

  • java.lang − bundles the fundamental classes

  • java.io − classes for input , output functions are bundled in this package /-Programmers can define their own packages to bundle group of classes/interfaces, etc. It is a good practice to group related classes implemented by you so that a programmer can easily determine that the classes, interfaces, enumerations, and annotations are related. /-Since the package creates a new namespace there won’t be any name conflicts with names in other packages. Using packages, it is easier to provide access control and it is also easier to locate the related classes.

Creating a Package

While creating a package, you should choose a name for the package and include a package statement along with that name at the top of every source file that contains the classes, interfaces, enumerations, and annotation types that you want to include in the package.

The package statement should be the first line in the source file. There can be only one package statement in each source file, and it applies to all types in the file. /-If a package statement is not used then the class, interfaces, enumerations, and annotation types will be placed in the current default package.

To compile the Java programs with package statements, you have to use -d option as shown below.

javac -d Destination_folder file_name.java

Then a folder with the given package name is created in the specified destination, and the compiled class files will be placed in that folder. /-Example /-Let us look at an example that creates a package called animals. It is a good practice to use names of packages with lower case letters to avoid any conflicts with the names of classes and interfaces.

Following package example contains interface named animals −

/* File name : Animal.java */
package animals;

interface Animal {
   public void eat();
   public void travel();
}


Interfaces in Java

Like a class, an interface can have methods and variables, but the methods declared in interface are by default abstract (only method signature, no body).  

  • Interfaces specify what a class must do and not how. It is the blueprint of the class.
  • An Interface is about capabilities like a Player may be an interface and any class implementing Player must be able to (or must implement) move(). So it specifies a set of methods that the class has to implement.
  • If a class implements an interface and does not provide method bodies for all functions specified in the interface, then class must be declared abstract.
  • A Java library example is, Comparator Interface. If a class implements this interface, then it can be used to sort a collection.

Syntax :

interface  {
    
    // declare constant fields
    // declare methods that abstract 
    // by default.
}

To declare an interface, use interface keyword. It is used to provide total abstraction. That means all the methods in interface are declared with empty body and are public and all fields are public, static and final by default. A class that implement interface must implement all the methods declared in the interface. To implement interface use implements keyword.

Why do we use interface ?

  • It is used to achieve total abstraction.
  • Since java does not support multiple inheritance in case of class, but by using interface it can achieve multiple inheritance .
  • It is also used to achieve loose coupling.
  • Interfaces are used to implement abstraction. So the question arises why use interfaces when we have abstract classes?


Swing is a set of program component s for Java programmers that provide the ability to create graphical user interface ( GUI ) components, such as buttons and scroll bars, that are independent of the windowing system for specific operating system . Swing components are used with the Java Foundation Classes ( JFC ).

Java Swing class Hierarchy Diagram

Creating GUI Components using Java Swing Tutorial

All components in swing are JComponent which can be added to container classes.
 What is a container class?

Container classes are classes that can have other components on it. So for creating a GUI, we need at least one container object. There are 3 types of containers.

  1. Panel: It is a pure container and is not a window in itself. The sole purpose of a Panel is to organize the components on to a window.
  2. Frame: It is a fully functioning window with its title and icons.
  3. Dialog: It can be thought of like a pop-up window that pops out when a message has to be displayed. It is not a fully functioning window like the Frame.


IO Stream

Java performs I/O through Streams. A Stream is linked to a physical layer by java I/O system to make input and output operation in java. In general, a stream means continuous flow of data. Streams are clean way to deal with input/output without having every part of your code understand the physical.

Java encapsulates Stream under java.io package. Java defines two types of streams. They are,

  1. Byte Stream : It provides a convenient means for handling input and output of byte.
  2. Character Stream : It provides a convenient means for handling input and output of characters. Character stream uses Unicode and therefore can be internationalized.

Nearly all programs require the ability to transfer data in and out of memory.
For example, data may be stored on disk or sent over a network.

The package java.io, part of the standard Java class library, provides a large number of classes designed for handling input and output to files, network connections, and other sources. These I/O classes are known as streams, and provide functionality for reading and writing data in various ways.

Java’s input and output classes:
• Input streams-and how to create, use, and detect the end of them-and filtered input streams, which can be nested to great effect.

• Output streams, which are mostly analogous to (but the inverse of) input streams