Java Overview

1.JAVA Overview

Java is high level server side programming language which is based on object oriented programming model. Java was originally developed by James Gosling at Sun Microsystems (which has since been acquired by Oracle Corporation) and released in 1995 as a core component of Sun Microsystems’ Java platform. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.
Orientation means perspective or way of thinking, object orientation is way of thinking in terms of objects. On the basis of this thinking a programming model is defining by the object orientation programming structure to simplify development and maintenance of software’s. Fundamental concept of this model are: –

* Object
* Classification
* Generalization and Inheritance
* Data encapsulation
* Polymorphism
1.1) Object is discrete identity which has well defined attribute and behavior’s. It can be a physical thing as well as be an abstract.
1.2) Classification is the process of grouping objects having common attribute and behavior into logical units called classes.
1.3) Generalization and Inheritance Concept of generalization simplifies management of classes and inheritance is the implementation of generalization. Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object.
1.4) Data encapsulation deals with the prevention of accidental and unintentional corruption of data by the programmer.
1.5) Polymorphism in the context of programming concept of polymorphism state that a behavior can have multiple manifestation behavior are implemented as method which need to be named. Concept of polymorphism has following two aspects:
1.5.1) Object manifest behavior in different ways. This aspect is implemented with the help of overloading.
1.5.2) Different objects manifest the same behavior in different ways. This aspect is implemented with the help of overriding.


2.1) Java Virtual machine (JVM) is the virtual machine that run the Java bytecodes. The JVM doesn’t understand Java source code, that’s why you compile your *.java files to obtain *.class files that contain the bytecodes understandable by the JVM. It’s also the entity that allows Java to be a “portable language” (write once, run anywhere). Indeed there are specific implementations of the JVM for different systems (Windows, Linux, MacOS), the aim is that with the same bytecodes they all give the same results.
2.2) Java Runtime Environment (JRE) provides the libraries, the Java Virtual Machine, and other components to run applets and applications written in the Java programming language. In addition, two key deployment technologies are part of the JRE: Java Plug-in, which enables applets to run in popular browsers; and Java Web Start, which deploys standalone applications over a network. It is also the foundation for the technologies in the Java 2 Platform, Enterprise Edition (J2EE) for enterprise software development and deployment. The JRE does not contain tools and utilities such as compilers or debuggers for developing applets and applications.
2.3) Java Development Kit (JDK) is a superset of the JRE, and contains everything that is in the JRE, plus tools such as the compilers and debuggers necessary for developing applets and applications.

3.Why JAVA?

Java has following two main features as compared to other programming languages:
3.1) Platform Independent: Portability v/s platform independency. If source code of a language can be executed on different platform without making any modification in it than the language is said to be portable across these platforms.
A language is platform independent if it does not have any dependency on a platform. Conventionally programming language used to have following dependency on the platform:
* Dependency of compilation
* Dependency of execution
* Dependency of resources
In Java
* It is compiled in platform neutral manner
* It provides its own runtime environment for the execution of its application
* It provides a comprehensive library so that application programmers can use system resources without any instruction to the O/S
3.2) Security: Java is secure in comparison of other language.
To make the execution of java application secured by microsystem defined different security for different execution environment. This security policy represents authorization. To implements these security policy executions of this application was made interpreted. So that security can be checked for each instruction before execution. The drawback of this model was degradation of execution speed which was improved by replacing the interpreter by just in time compiler in subsequent releases.
Just in time compiler means compile one time and run on any computer architecture where JRE installed.

4.Simple Java Program

Class is a definition, while object is an instance of the class created. Class is a blue print while objects are actual objects existing in real world. Example: we have class CAR which has attributes and methods like Speed, Brakes, Type of Car etc.
4.1) Naming convention in java
* For class: First letter of each word of class is capitalized.
Example: String, StringBuilder, ArrayIndex
* For method: First letter of each word except the first word of method is capitalized (Camel Case).
Example: printf() ,getPriority() ,getMethodName()
4.2) Example of Java Program
public class FirstExample {
public static void main(String args[]) {
System.out.println(“Hello World”);
In above example public is access modifier which defines the scope and accessibility of this class.
Class is keyword which followed by a space, and then by the fully qualified name of the class
FirstExample is the identifier or name of class.
The static keyword denotes that a member variable, or method, can be accessed without requiring an instantiation of the class to which it belongs. In simple terms, it means that you can call a method, even if you’ve never created the object to which it belongs.The main method is always static because it called by JRE and the class object is not created at that time.
Void is method return type means this method is return which type of value.void represents nothing means this method return nothing.
String args[] this agrs is an array of arguments or parameters of String tye(String is predefined class in java).
The key line with System.out.println() prints the text “Hello, World” in the terminal window.

5.Advanced Features & API’s

5.1) Exception Handling: An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception occurs the normal flow of the program is disrupted and the program/Application terminates abnormally, which is not recommended, therefore these exceptions are to be handled.
5.2) Multithreading: Multithreading is the ability of a program or an operating system process to manage its use by more than one user at a time and to even manage multiple requests by the same user without having to have multiple copies of the programming running in the computer.
5.3) Input/Output: Reading and writing data from files, network, input output devices Stream is defined in java.
5.4) Reflection: Java Reflection is a process of examining or modifying the run time behavior of a class at run time. The java.lang.Class class provides many methods that can be used to get metadata, examine and change the run time behavior of a class. The java.lang and java.lang.reflect packages provide classes for java reflection.
5.5) Networking: The package provides support for common network protocols TCP. TCP stands for Transmission Control Protocol, which allows for reliable communication between two applications. TCP is typically used over the Internet Protocol, which is referred to as TCP/IP.
5.6) Collection: A collection is an object that can hold references to other objects. The collection interfaces declare the operations that can be performed on each type of collection. The classes and interfaces of the collections framework are in package java.util.
5.7) JDBC: Java Database Connectivity (JDBC) is an application programming interface (API) for the programming language Java, which defines how a client may access a database. It is part of the Java Standard Edition platform, from Oracle Corporation.


HTML Overview


 HTML Tags
 HTML Elements
 HTML Attributes

HTML Forms
 Form Attributes
 Text Input Controls

HTML – Style Sheet
 External Style Sheet
 Internal Style Sheet
 Inline Style Sheet

HTML – JavaScript
 External JavaScript

HTML: Introduction
HTML stands for Hyper Text Markup Language, which is the most widely used language on Web to develop web pages.
• Hypertext refers to the way in which Web pages (HTML documents) are linked together. Thus, the link available on a webpage is called Hypertext.
• As its name suggests, HTML is a Markup Language which means you use HTML to simply “mark-up” a text document with tags that tell a Web browser how to structure it to display.
• HTML describes the structure of Web pages using markup.
• HTML elements are the building blocks of HTML pages.
• HTML elements are represented by tags.
• HTML tags label pieces of content such as “heading”, “paragraph”, “table”, and so on.
• Browsers do not display the HTML tags, but use them to render the content of the page.
Originally, HTML was developed with the intent of defining the structure of documents like headings, paragraphs, lists, and so forth to facilitate the sharing of scientific information between researchers.
Now, HTML is being widely used to format web pages with the help of different tags available in HTML language.

Description of HTML Example
DOCTYPE: It defines the document type.
html: Text between html tag describes the web document.
body: Text between body tag describes the body content of the page that is visible to the end
h1 : Text between h1 tag describes the heading of the webpage.
p : Text between p tag describes the paragraph of the webpage.
HTML Tags:
HTML tags contain three main parts: opening tag, content and closing tag. But some HTML tags are unclosed tags.
When a web browser reads an HTML document, browser reads it from top to bottom and left to right. HTML tags are used to create HTML documents and render their properties. Each HTML tags have different properties.
<tag> content </tag>

HTML Tag Reference and Tag Description
<html> Defines the root of an HTML document
<head> A container for all the head elements (title, scripts, styles, meta information, and more)
<body> Defines the document’s body
<h1> to <h6> Defines HTML headings
<hr> Defines a thematic change in the content

The <html> Tag
 The <html> tag tells the browser that this is an HTML document.
 The <html> tag represents the root of an HTML document.
 The <html> tag is the container for all other HTML elements (except for the <!DOCTYPE> tag).
The <head> Tag
 The <head> element is a container for all the head elements.
 The <head> element can include a title for the document, scripts, styles, meta information, and more.

The <body> Tag
 The <body> tag defines the document’s body.
 The <body> element contains all the contents of an HTML document, such as text, hyperlinks, images, tables, lists, etc.

The <h1> to <h6> Tag
 The <h1> to <h6> tags are used to define HTML headings.
 <h1> defines the most important heading. <h6> defines the least important heading.

The <hr> Tag
 The <hr> tag defines a thematic break in an HTML page (e.g. a shift of topic).
 The <hr> element is used to separate content (or define a change) in an HTML page.
 HTML Elements:
 An HTML element is defined by a starting tag. If the element contains other content, it ends with a closing tag, where the element name is preceded by a forward slash as shown below with few tags –
Start Tag Content End Tag
<p> This is paragraph content </p>
<h1> This is heading content. </h1>

This is division content.

<br> Produces a line break in text. </br>

 HTML elements with no content are called empty elements. Empty elements do not have an end tag, such as the <br> element (which indicates a line break).
 So here <p>….</p> is an HTML element, <h1>…</h1> is another HTML element. There are some HTML elements which don’t need to be closed, such as <img…/>, <hr /> and <br />
 elements. These are known as void elements.

 HTML documents consists of a tree of these elements and they specify how HTML documents should be built, and what kind of content should be placed in what part of an HTML document.

 Nested HTML Elements
 HTML elements can be nested (elements can contain elements).
 All HTML documents consist of nested HTML elements.
 This example contains four HTML elements:
HTML Attributes:
An attribute is used to define the characteristics of an HTML element and is placed inside the element’s opening tag. All attributes are made up of two parts − a name and a value
 The name is the property you want to set. For example, the paragraph <p> element in the example carries an attribute whose name is align, which you can use to indicate the alignment of paragraph on the page.

 The value is what you want the value of the property to be set and always put within quotations. The below example shows three possible values of align attribute: left, center and right.

 All HTML elements can have attributes

 Attributes provide additional information about an element

 Attributes are always specified in the start tag

 Attributes usually come in name/value pairs like: name=”value”

Core Attribute
The four core attributes that can be used on the majority of HTML elements (although not all) are −
 Id
 Title
 Class
 Style

The Id Attribute
The id attribute of an HTML tag can be used to uniquely identify any element within an HTML page. There are two primary reasons that you might want to use an id attribute on an element −
 If an element carries an id attribute as a unique identifier, it is possible to identify just that element and its content.

 If you have two elements of the same name within a Web page (or style sheet), you can use the id attribute to distinguish between elements that have the same name.

The title Attribute
The title attribute gives a suggested title for the element. They syntax for the title attribute is similar as explained for id attribute −
The behavior of this attribute will depend upon the element that carries it, although it is often displayed as a tooltip when cursor comes over the element or while the element is loading.

The class Atrribute
The class attribute is used to associate an element with a style sheet, and specifies the class of element. You will learn more about the use of the class attribute when you will learn Cascading Style Sheet (CSS). So for now you can avoid it.

The Style Attribute
The style attribute allows you to specify Cascading Style Sheet (CSS) rules within the element.


 HTML Forms are required, when you want to collect some data from the site visitor. For example, during user registration you would like to collect information such as name, email address, credit card, etc.

 A form will take input from the site visitor and then will post it to a back-end application such as CGI, ASP Script or PHP script etc. The back-end application will perform required processing on the passed data based on defined business logic inside the application.
 There are various form elements available like text fields, textarea fields, drop-down menus, radio buttons, checkboxes, etc.

The HTML <form> tag is used to create an HTML form and it has following syntax –

<form action = “Script URL” method = “GET|POST”>
form elements like input, textarea etc.

From Attributes:

following is a list of the most frequently used form attributes –

action: Backend script ready to process your passed data.
method: Method to be used to upload data. The most frequently used are GET and POST methods.
target: Specify the target window or frame where the result of the script will be displayed. It takes values like _blank, _self, _parent etc.
enctype: You can use the enctype attribute to specify how the browser encodes the data before it sends it to the server. Possible values are –
application/x-www-form-urlencoded − This is the standard method most forms use in simple scenarios.
mutlipart/form-data − This is used when you want to upload binary data in the form of files like image, word file etc.
Text input Controls:
 The <input> tag specifies an input field where the user can enter data.

 <input> elements are used within a <form> element to declare input controls that allow users to input data.

An input field can vary in many ways, depending on the type attribute.
There are three types of text input used on forms –
 Single-line text input controls − This control is used for items that require only one line of user input, such as search boxes or names. They are created using HTML <input> tag.
 Password input controls − This is also a single-line text input but it masks the character as soon as a user enters it. They are also created using HTMl <input> tag.
 Multi-line text input controls − This is used when the user is required to give details that may be longer than a single sentence. Multi-line input controls are created using HTML <textarea> tag.
 CSS stands for Cascading Style Sheets.

 CSS describes how HTML elements are to be displayed on screen, paper, or in other media.

 CSS saves a lot of work. It can control the layout of multiple web pages all at once.

 Cascading Style Sheets (CSS) provide easy and effective alternatives to specify various attributes for the HTML tags. Using CSS, you can specify a number of style properties for a given HTML element. Each property has a name and a value, separated by a colon (:). Each property declaration is separated by a semi-colon (;).
CSS can be added to HTML elements in 3 ways:
• External Style Sheet − Define style sheet rules in a separate .css file and then include that file in your HTML document using HTML <link> tag.
• Internal Style Sheet − Define style sheet rules in header section of the HTML document using <style> tag.
• Inline Style Sheet − Define style sheet rules directly along-with the HTML elements using style attribute.

External Style Sheet
• An external style sheet is used to define the style for many HTML pages.
• With an external style sheet, you can change the look of an entire web site, by changing one file!
• To use an external style sheet, add a link to it in the <head> section of the HTML page:
• A cascading style sheet file will have extension as .css and it will be included in HTML files using <link> tag.

Internal Style Sheet
• An internal CSS is used to define a style for a single HTML page.
• An internal CSS is defined in the <head> section of an HTML page, within a <style> element:
• Rules defined in internal style sheet overrides the rules defined in an external CSS file.

Inline Style Sheet
• An inline CSS is used to apply a unique style to a single HTML element.
• An inline CSS uses the style attribute of an HTML element.
• Rules defined inline with the element overrides the rules defined in an external CSS file as well as the rules defined in <style> element.

HTML – JavaScript
• JavaScript is a lightweight, interpreted programming language. It is designed for creating network-centric applications. It is complimentary to and integrated with Java. JavaScript is very easy to implement because it is integrated with HTML. It is open and cross-platform.
• Javascript is a dynamic computer programming language. It is lightweight and most commonly used as a part of web pages, whose implementations allow client-side script to interact with the user and make dynamic pages. It is an interpreted programming language with object-oriented capabilities.

• JavaScript was first known as LiveScript, but Netscape changed its name to JavaScript, possibly because of the excitement being generated by Java. JavaScript made its first appearance in Netscape 2.0 in 1995 with the name LiveScript. The general-purpose core of the language has been embedded in Netscape, Internet Explorer, and other web browsers.

The ECMA-262 Specification defined a standard version of the core JavaScript language
 JavaScript is a lightweight, interpreted programming language.
 Designed for creating network-centric applications.
 Complementary to and integrated with Java.
 Complementary to and integrated with HTML.
 Open and cross-platform

External JavaScript
 We can create external JavaScript file and embed it in many html page.
 It provides code re usability because single JavaScript file can be used in several html pages.
 An external JavaScript file must be saved by .js extension. It is recommended to embed all JavaScript files into a single file. It increases the speed of the webpage.

 As you begin to work more extensively with JavaScript, you will be likely to find that there are cases where you are reusing identical JavaScript code on multiple pages of a site.
 You are not restricted to be maintaining identical code in multiple HTML files. The script tag provides a mechanism to allow you to store JavaScript in an external file and then include it into your HTML files.



Java Collections

What is Java Collections Framework?
Collection Framework provides a platform to save and edit group of objects .

Objects inside Collections are managed with help of interfaces(Set,List,Queue etc) and classes(ArrayList,LinkedList,HashMap,HashSet etc).

ArrayList Class:It uses dynamic Array to store elements .ArrayList contains duplicate elements and maintains order of the elements . It is not synchronized .
ArrayList class extends Abstract Class which implements List Interface .

Declaration of ArrayList
public class ArrayList extends AbstractList implements List, RandomAccess, Cloneable, Serializable .

LinkedList Class:Java LinkedList class uses doubly linked list to store the elements. It provides a linked-list data structure. It inherits the AbstractList class and implements List and Deque interfaces.
LinkedList contains duplicate elements and maintains order of the elements . It is not synchronized .Manipulation of Linkedlist is faster then ArrayList .
Declaration of LinkedList
public class LinkedList extends AbstractSequentialList implements List, Deque, Cloneable, Serializable.

List Interface:List Interface is the subinterface of Collection.It contains methods to insert and delete elements in index basis.It is a factory of ListIterator interface.

Set Interface:Stores unique elements.It allows one null element.This interface is inherited by HashSet and TreeSet .

HashSet Class:Stores unique elements into this collection.This is not synchronized . This allows null object to store however only one null object is stored as it doent allow duplicates .

HashMap Class:It stores elements in the form of key value pairs .It doesnt allow duplicate Keys. One Null key value pair can be stored .Order of the elements stored is not maintained . This is not synchronized .
There is a TreeMap which is synchronized and equals to HashMap.
HashMap and TreeMap implements Map interface

Setting Java Environment Variables

Windows 8/10
1)In Search, search for : System (Control Panel)
2)Click the Advanced system settings link.
3)Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
4)In the new opened window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
5)Run your java code.

Windows 7
1)Right click the Computer icon from the desktop.
2)Select Properties.
3)Click on Advanced system settings.
4)Click Environment Variables. Inside section System Variables, find the path environment variable and select it. Click Edit. If the path environment variable does not exist, click New.
5)In the opened window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
6)Reopen Command prompt window, and run your java code.

JDK Installation

1)Download installation file of JDK by clicking Here

2)After download open installation wizard by double clicking the file

3)Click Next in Installation Wizard

4)With the installation package we get 3 features which will get installed

Development Tools

Source Code

Public JRE

5)For the public JRE there will be default installation directory selected which is inside Program Files .

6)Click on Next

7) Public JRE is the one which can be used by any java file to run .

8)After completion of installation click Close .