Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

Unit - 1 - Part2 JAVA Introduction

The document discusses the course details of Web Technology. It covers 5 units that include topics like HTML, CSS, XML, JavaScript, JDBC, servlets, JSP and more. It also provides information about the faculty and contact details.

Uploaded by

meetalisingh00
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Unit - 1 - Part2 JAVA Introduction

The document discusses the course details of Web Technology. It covers 5 units that include topics like HTML, CSS, XML, JavaScript, JDBC, servlets, JSP and more. It also provides information about the faculty and contact details.

Uploaded by

meetalisingh00
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 74

Department of Applied Computational Science and Engineering

Course Code: KCS-602


Course Name: Web Technology
Faculty Name: Anuj Gupta
Email: anuj.gupta_acse@glbitm.ac.in
Syllabus
Unit-1
Introduction: Introduction and Web Development Strategies, History of Web and Internet, Protocols Governing Web, Writing Web Projects, Connecting to
Internet, Introduction to Internet services and tools, Introduction to client-server computing. Core Java: Introduction, Operator, Data type, Variable, Arrays,
Methods & Classes, Inheritance, Package and Interface, Exception Handling, Multithread programming, I/O, Java Applet, String handling, Event handling,
Introduction to AWT, AWT controls, Layout managers

Unit-2
Web Page Designing: HTML: List, Table, Images, Frames, forms, CSS, Document type definition, XML: DTD, XML schemes, Object Models, presenting and
using XML, Using XML Processors: DOM and SAX, Dynamic HTML

Unit-3
Scripting: Java script: Introduction, documents, forms, statements, functions, objects; introduction to AJAX, Networking : Internet Addressing, InetAddress,
Factory Methods, Instance Methods, TCP/IP Client Sockets, URL, URL Connection, TCP/IP Server Sockets, Datagram.

Unit-4
Enterprise Java Bean: Preparing a Class to be a JavaBeans, Creating a JavaBeans, JavaBeans Properties, Types of beans, Stateful Session bean, Stateless
Session bean, Entity bean
Java Database Connectivity (JDBC): Merging Data from Multiple Tables: Joining, Manipulating, Databases with JDBC, Prepared Statements,
Transaction Processing, Stored Procedures.

Unit-5
Servlets: Servlet Overview and Architecture, Interface Servlet and the Servlet Life Cycle, Handling HTTP get Requests, Handling HTTP post Requests,
Redirecting Requests to Other Resources, Session Tracking, Cookies, Session Tracking with Http Session
Java Server Pages (JSP): Introduction, Java Server Pages Overview, A First Java Server Page Example, Implicit Objects, Scripting, Standard Actions,
Directives, Custom Tag Libraries..

Subject:Web
Subject: Web Technology
Technology
JAVA Introduction

Phases:
• There are three execution phases of a program. These are written, compile and run.
• Writing a program is done by a java programmer like you and me.
• The compilation is done by the JAVAC compiler which is a primary Java compiler included in the Java
development kit (JDK). It takes Java program as input and generates bytecode as output.
• In the Run phase of a program, JVM executes the bytecode generated by the compiler.

Subject: Web Technology


JAVA Introduction

Subject: Web Technology


JAVA Terminology
1. Java Virtual Machine(JVM): We can understand that the function of Java Virtual Machine is
to execute the bytecode produced by the compiler. Every Operating System has a different
JVM but the output they produce after the execution of byte-code is the same across all the
operating systems.

2. Bytecode in the Development process: As discussed, the Javac compiler of JDK compiles the
java source code into bytecode so that it can be executed by JVM. It is saved as .class file by
the compiler.

3. Java Development Kit (JDK): As the name suggests, it is a complete Java Development Kit
that includes everything including compiler, Java Runtime Environment (JRE), java
debuggers, java docs, etc. For the program to execute in java, we need to install JDK on our
computer in order to create, compile and run the java program.

4. Java Runtime Environment (JRE): JDK includes JRE. JRE installation on our computers allows
the java program to run, however, we cannot compile it. JRE includes a browser, JVM, applet
supports, and plugins. For running the java program, a computer needs JRE.

Subject: Web Technology


JAVA Features

Subject: Web Technology


JAVA Features

Subject: Web Technology


JAVA Features

Subject: Web Technology


JAVA Features

Subject: Web Technology


JAVA Features

Subject: Web Technology


JAVA Features

Subject: Web Technology


C++ Vs JAVA
Comparison Index C++ Java
Platform- C++ is platform-dependent. Java is platform-independent.
independent
C++ is mainly used for system programming. Java is mainly used for application programming. It is widely used in
Mainly used for
window, web-based, enterprise and mobile applications.
C++ was designed for systems and applications It was designed with a goal of being easy to use and accessible to a
Design Goal programming. It was an extension of C programming broader audience.
language.
Goto C++ supports the goto statement. Java doesn't support the goto statement.
C++ supports multiple inheritance. Java doesn't support multiple inheritance through class.
Multiple inheritance
It can be achieved by interfaces in java.
Operator C++ supports operator overloading. Java doesn't support operator overloading.
Overloading
C++ supports pointers. You can write pointer program Java supports pointer internally. However, you can't write the pointer
Pointers
in C++. program in java. It means java has restricted pointer support in java.
C++ uses compiler only. C++ is compiled and run using Java uses compiler and interpreter both. Java source code is
Compiler and the compiler which converts source code into machine converted into bytecode at compilation time. The interpreter
Interpreter code so, C++ is platform dependent. executes this bytecode at runtime and produces output. Java is
interpreted that is why it is platform independent.

Subject: Web Technology


JAVA Introduction
Comparison Index C++ Java
Call by Value and C++ supports both call by value and call by reference. Java supports call by value only. There is no call by reference in java.
Call by reference
Structure and Union C++ supports structures and unions. Java doesn't support structures and unions.
C++ doesn't have built-in support for threads. It relies Java has built-in thread support.
Thread Support
on third-party libraries for thread support.
Virtual Keyword C++ supports virtual keyword so that we can Java has no virtual keyword. We can override all non-static
decide whether or not override a function. methods by default. In other words, non-static methods are virtual
by default.
Inheritance Tree C++ creates a new inheritance tree always. Java uses a single inheritance tree always because all classes are
the child of Object class in java. The object class is the root of
the inheritance tree in java.
Object-oriented C++ is an object-oriented language. However, in C Java is also an object-oriented language. However, everything
language, single root hierarchy is not possible. (except fundamental types) is an object in Java. It is a single root
hierarchy as everything gets derived from java.lang.Object.

Subject: Web Technology


Basic Syntax

Subject: Web Technology


JAVA Identifiers

Subject: Web Technology


JAVA Syntax

Subject: Web Technology


First JAVA Program

Subject: Web Technology


First JAVA Program

Subject: Web Technology


Installing JAVA

Subject: Web Technology


Installing JAVA

Subject: Web Technology


Installing JAVA- set JAVA_HOME & Path

Subject: Web Technology


Installing JAVA- set JAVA_HOME & Path

Subject: Web Technology


Installing JAVA- set JAVA_HOME & Path

Subject: Web Technology


Installing JAVA- set JAVA_HOME & Path

Subject: Web Technology


Installing JAVA- set JAVA_HOME & Path

Subject: Web Technology


Data Types

Data Types in Java

Subject: Web Technology


Data Types

Subject: Web Technology


Data Types
Primitive Data Types
Primitive data types are predefined by the language and named by a keyword. There are eight primitive
data types supported by Java.
– byte
– short
– int
– long
– Float
– Double
– Boolean
– character

Subject: Web Technology


Data Types

Subject: Web Technology


Data Types
Non-Primitive / Reference Data Types
 Reference variables are created using defined constructors of the classes.
 They are used to access objects.
 It is declared to be of a specific type that cannot be changed.
 Class objects and various types of array variables come under reference data type.
 The default value of any reference variable is null.
- Strings
- Class
- Arrays
- Interference

Subject: Web Technology


Operators in Java

Subject: Web Technology


Operator in Java

Operator in Java is a symbol that is used to perform operations. For example: +, -, *, / etc.
There are many types of operators in Java which are given below:
• Unary Operator - ++, --, ~,!
• Arithmetic Operator - >, +,-,%,/,*
• Shift Operator - <<,>>
• Relational Operator - <,>,<=,>=,==
• Bitwise Operator – bitwise OR(|): The bitwise | operator always checks both conditions whether the
first condition is true or false. Bitwise AND(&): The bitwise & operator always checks both conditions
whether the first condition is true or false.
• Logical Operator - &&(AND) operator doesn’t check the second condition if the first condition is false.
It checks the second condition only if the first one is true, ||(OR) operator doesn’t check the second
if the first condition is true. It checks the second condition only if the first one is false.

Subject: Web Technology


Operator in Java
• Ternary Operator - Java Ternary operator is used as one line replacement for if-then-else
statements and is used a lot in Java programming. It is the only conditional operator which takes
three operands. (a:b)
• Assignment Operator - Java assignment operator is one of the most common operators. It is used
to assign the value on its right to the operand on its left. (=)
Examples of operator:-
public class OperatorExample{
public static void main(String args[])
{
int x=10;
System.out.println(x++); //10 (11)
System.out.println(++x); //12
System.out.println(x--); //12 (11)
System.out.println(--x); //10
}
}

Subject: Web Technology


Access Modifiers

Subject: Web Technology


Access Modifiers
 In Java, Access modifiers help to restrict the scope of a class, constructor, variable, method, or data
member.
 It provides security, accessibility, etc to the user depending upon the access modifier used with the
element.
 The access modifiers in Java specifies the accessibility or scope of a field, method, constructor, or
class.
 We can change the access level of fields, constructors, methods, and class by applying the access
modifier on it.

Subject: Web Technology


Access Modifiers

Subject: Web Technology


Keywords in Java

Subject: Web Technology


Keywords
Java keywords are also known as reserved words.
Keywords are particular words that act as a key to a code.
These are predefined words by Java, so they cannot be used as a variable, object name, or class name.
Some keywords are:-
 Abstract,
 Int,
 Break,
 byte,
 Class,
 Continue,
 Catch,
 Char,
 Else,
 If,
 Do, For, While, etc.

Subject: Web Technology


Variables in Java

Subject: Web Technology


Variable in Java
 Variable is a data container that saves the data values during Java program execution.
 Every variable is assigned a data type that designates the type and quantity of value it can hold.
 A variable is a memory location name for the data.

 How to declare variables?

Name- Name given to the variable.


Type- Type of data that can be stored in this variable.
Value- It is the initial value stored in the variable.

Subject: Web Technology


Variable in Java(Cont.….)
A variable is the name of a reserved area allocated in memory. Its value can be changed.
Syntax: datatype variable_name

There are three types of variables in java


i. Local Variable
ii. Instance Variable
iii. Static Variable

• Local Variable:
A variable declared inside the body of the method is called a local variable.
Syntax: method() {
datatype variableName; // Local Variable
}
Subject: Web Technology
Variable in Java(Cont.….)
Static Variable:
A variable that is declared as static is called a static variable. Here “static” keywords is used to
declare a static variable.
Syntax: static datatype variableName; // Static variable

Instance Variable:
• A variable declared inside the class but outside the body of the method, is called an instance
variable. It is not declared static.
• It is called an instance variable because its value is instance-specific and is not shared among
instances.
• Every instance has its own copy of the instance variable.
• Syntax: class {
datatype variablename; // instance variable
}

Subject: Web Technology


Variable in Java(Cont.….)
Rules to Declare Variables in Java:-
• A variable name can consist of Capital letters A-Z, lowercase letters a-z digits 0-9, and
two special characters such as _ underscore and $ dollar sign.
• The first character must not be a digit.
• Blank spaces cannot be used in variable names.
• Java keywords cannot be used as variable names.
• Variable names are case-sensitive.
• There is no limit on the length of a variable name but by convention, it should be
between 4 to 15 chars.
• Variable names always should exist on the left-hand side of assignment operators.

Subject: Web Technology


Variable in Java(Cont.….)
// Example of Variable class ABC
{
public static void main(String[] args)
{
// Declaring all the
// possible combinations of
// variable format
int _a = 10; int $b
= 20; int C = 30; int
c = 40;

int result = _a + $b + C + c;
System.out.println("Result: " + result);
}
} //Output - 100

Subject: Web Technology


Comments in Java
Comments
Comments are descriptions of the aim and features of the program Comments. Increase the readability of
a program.

Three types of comments are there in Java:


• Single line comments: These comments start with //
Ex: // this is the comment line
• Multi-line comments: These comments start with /* and end with */
Ex: /* This is comment line*/
• Java documentation comments: These comments start with /** and end with */

These comments are useful to create an HTML file called API (application programming Interface) document.
This file contains a description of all the features of the software.

Subject: Web Technology


Control Structure in Java

Subject: Web Technology


Control Structure in Java
• The execution of a block of code based on a condition is known as a control structure.
// Here, Structures means a block of code
<<Condition>>
{

}
• In general, program execution starts with a main() method, and line-by-line execution of the program
tokens places a linear/Sequential flow of Execution.
PSV main()
{
line1 // Linear Sequential flow of execution
2
}

Subject: Web Technology


Control Structure in Java
• The execution of a block of code based on a condition is known as a control structure.
// Here, Structures means a block of code
<<Condition>>
{

}
• In general, program execution starts with a main() method, and line-by-line execution of the program
tokens places a linear/Sequential flow of Execution.
PSV main()
{
line1 // Linear Sequential flow of execution
2
}

Subject: Web Technology


Arrays in Java

Subject: Web Technology


Java Arrays
• An array is a collection of similar type of elements which has a contiguous memory location.
• Java array is an object which contains elements of a similar data type.
• Array is index-based,
the 1st element of the array is stored at the 0th index,
2nd element is stored on the 1st index, and so on.
• Types of Arrays in Java:
a) Single Dimensional Array
b) Multidimensional Array

Subject: Web Technology


Java Arrays (Cont.…)
A. Single-Dimensional Array in Java: This is the array in which rows are fixed but columns vary.
• Syntax to declare an array in java:
A. Datatype[] arrayName;
B. Datatype []arrayName;
C. Datatype arrayName[];
B. Multidimensional Array in Java: Data is stored in row and columns based index(also known as matrix
form).
• Syntax to Declare multidimensional array in java
A. Datatype[][] arrayName;
B. Datatype [][]arrayName;
C. Datatype arrayName[][];

Subject: Web Technology


Java Arrays (Cont.…)
Single-Dimensional Arrays:
• A one-dimensional array or single-dimensional array represents a row or a column of elements.

For example, the marks obtained by a student in 5 different subjects can be represented by a 1D array
We can declare a one-dimensional array and directly store elements at the time of its declaration, as:
int marks[] = {50, 60, 55, 67, 70};
We can create a 1D array by declaring the array first and then allocate memory for it by using a
new operator, as:
int marks[]; //declare marks array
marks = new int[5]; //allot memory for elements

These two statements also can be written as:


int marks [] = new int [5];

Subject: Web Technology


Java Arrays (Cont.…)
class Testarray
{
public static void main(String args[])
{
int a[]=new int[5];//declaration and instantiation
a[0]=10;//initialization
a[1]=20;
a[2]=70;
a[3]=40;
a[4]=50;
//traversing array
for(int i=0;i<a.length;i++)//length is the property of array
System.out.println(a[i]);
}
}

Subject: Web Technology


Classes & Object in Java

Subject: Web Technology


OOPs Concept

Subject: Web Technology


Classes & Object in Java

Subject: Web Technology


Class
Class
• Collection of objects is called class.
• It is a logical entity. It can't be physical.
• A class is a group of objects which have common
properties.
• A class can also be defined as a blueprint from which
you can create an individual object.
• Class doesn't consume any space.

A class in Java can contain: Syntax to declare a class:


o Fields AccessModifier class class_name
o Methods {
o Constructors method;
o Blocks constructor;
o Nested class and interface field;
}

Subject: Web Technology


Class in Java(Cont.…)
Examples of Class
Syntax to declare a class: class Student
{
access_modifier class<class_name> int id; // data member (also instance variable)
{ String name; // data member (also instance variable)
data member;
method; public static void main(String args[])
constructor; {
nested class; Student s1 = new Student();
interface; // creating an object for the Student
System.out.println(s1.id);
} System.out.println(s1.name);
}
}

Subject: Web Technology


Object
Object
• Object means a real-world entity such as a pen, chair,
table, computer, watch, etc.
• Any entity that has state and behaviour is known as an
object.
• It can be physical or logical.
• An Object can be defined as an instance of a class.
• An object contains an address and takes up some space in
memory.

Example: A dog is an object because it has states like color, name, breed, etc. as well as behaviours like wagging the
tail, barking, eating, etc.
In Java, the new keyword is used to create new objects.

There are three steps when creating an object from a class −


• Declaration − A variable declaration with a variable name with an object type.
• Instantiation − The 'new' keyword is used to create the object.
 New keyword in Java: The new keyword is used to allocate memory at runtime. All objects get memory in Heap
memory area.
• Initialization − The 'new' keyword is followed by a call to a constructor. This call initializes the new object.

Subject: Web Technology


Method in Java

Subject: Web Technology


Methods in Java
• A method is a block of code or collection of statements or a set of code grouped together to perform a
certain task or operation.
• It is used to achieve the reusability of code.
• We write a method once and use it many times.
• We do not require to write code again and again.
• It also provides the easy modification and readability of code, just by adding or removing a chunk of
code.

Subject: Web Technology


Methods in Java (Cont….)
Methods Declaration
The method declaration provides information about method attributes, such as visibility, return type,
name, and arguments.
• Method Signature: Every method has a method signature. It is a part of the method declaration. It
includes the method name and parameter list.
• Access Specifier: Access specifier or modifier is the access type of the method. It specifies the visibility
of the method. Java provides four types of access specifiers:
• Public: The method is accessible by all classes when we use a public specifier in our application.
• Private: When we use a private access specifier, the method is accessible only in the classes in which it is
defined.
• Protected: When we use a protected access specifier, the method is accessible within the same package
or subclasses in a different package.

Subject: Web Technology


Methods in Java (Cont….)
• Default: When we do not use any access specifier in the method declaration, Java uses the default
access specifier by default. It is visible only from the same package only.
• Return Type: The return type is a data type that the method returns. It may have a primitive data type,
object, collection, void, etc. If the method does not return anything, we use the void keyword.
• Method Name: It is a unique name that is used to define the name of a method. It must be
corresponding to the functionality of the method. Suppose, if we are creating a method for the
subtraction of two numbers, the method name must be subtraction(). A method is invoked by its name.
• Parameter List: It is the list of parameters separated by a comma and enclosed in a pair of parentheses.
It contains the data type and variable name. If the method has no parameter, left the parentheses blank.
• Method Body: It is a part of the method declaration. It contains all the actions to be performed. It is
enclosed within a pair of curly braces.

Subject: Web Technology


Methods in Java (Cont….)
Naming in Method
• Single-word method name: sum(), area()
• Multi-word method name: areaOfCircle(), stringComparision()

Types of Method
There are two types of methods in Java:
• Predefined Method
• User-defined Method

Subject: Web Technology


Methods in Java (Cont….)
Predefined Method
• In Java, predefined methods are the method that is already defined in the Java class libraries is known
as predefined methods.
• It is also known as the standard library method or built-in method. We can directly use these methods
just by calling them in the program at any point.
• Some pre-defined methods are length(), equals(), compareTo(), sqrt(), etc.
For Example:- public class Demo
{
public static void main(String[] args)
{
// using the max() method of Math class
System.out.print("The maximum number is: " + Math.max(9,7));
}
}

Subject: Web Technology


Methods in Java (Cont….)
User-defined Method
• The method written by the user or programmer is known as a user-defined method.
• These methods are modified according to the requirement.
For Examples:- //user defined method
public static void findEvenOdd(int num)
{
//method body
if(num%2==0)
System.out.println(num+" is even");
else
System.out.println(num+" is odd");
}

Subject: Web Technology


Methods in Java (Cont….)
• Reusability: Methods allow you to write code once and use it many times, making your code more
modular and easier to maintain.
• Abstraction: Methods allow you to abstract away complex logic and provide a simple interface for others
to use. This makes your code more readable and easier to understand.
• Improved readability: By breaking up your code into smaller, well-named methods, you can make your
code more readable and easier to understand.
• Encapsulation: Methods allow you to encapsulate complex logic and data, making it easier to manage
and maintain.
• Separation of concerns: By using methods, you can separate different parts of your code and assign
different responsibilities to different methods, improving the structure and organization of your code.
• Improved testability: By breaking up your code into smaller, more manageable units, you can make it
easier to test and debug your code.
• Improved performance: By organizing your code into well-structured methods, you can improve
performance by reducing the amount of code that needs to be executed and by making it easier to cache
and optimize your code.

Subject: Web Technology


Java User Input

Subject: Web Technology


Java User Input
• Taking input from users is a common requirement in Java programming.
• It enables interactive and dynamic functionality by allowing users to provide data
and interact with applications.
• In Java, there are multiple ways to take input, providing flexibility based on the
specific needs of your program.

Here are the different types of approaches how to take input from users in Java :
1. Using the Scanner Class
2. Using the BufferedReader Class
3. Using Command-Line Arguments

Subject: Web Technology


Java User Input
1. Using the Scanner Class:

Subject: Web Technology


Java User Input

Subject: Web Technology


Java User Input

Subject: Web Technology


Java User Input
2. Using the BufferedReader Class:
• The BufferedReader class, available in the java.io package, provides efficient reading of characters
from an input stream.
• It can be used to read user input by wrapping it around an InputStreamReader object.
Example:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class UserInputExample {
public static void main(String[] args) throws IOException
{ //InputStreamReader input = new InputStreamReader(System.in);
//BufferedReader reader = new BufferedReader(input);
//or
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter your age: ");
int age = Integer.parseInt(reader.readLine()); Output:
System.out.println("You are " + age + " years old.");
reader.close(); Enter your age: 25
}} You are 25 years old.

Subject: Web Technology


Java User Input
3. Using Command-Line Arguments:
• Java allows you to pass command-line arguments to a program when executing it.
• These arguments can be accessed using the args parameter in the main() method.
Example:
public class UserInputExample
{
public static void main(String[] args)
{
if (args.length > 0)
{
String name = args[0];
System.out.println("Hello, " + name + "!");
} else
{
System.out.println("Please provide your name as a command-line argument.");
}
} Output (when executed with the command-line argument "John")
}
Hello, John!

Subject: Web Technology

You might also like