Java-Programming-and-Dynamic-WebPage-Design (1)
Java-Programming-and-Dynamic-WebPage-Design (1)
and
Web Page Design
Prepared by:
Prashant Srivastava,
Dept. of Comp. Applications
UIET, CSJM University.
Unit 1
•Data types,
•Control structure,
•Arrays, Strings, and Vector,
•Classes(inheritance, package, exception
handling)
•Multithreaded programming.
Inception of Java
• Java is an object oriented language, based on C+
+, which itself is a direct descendant of C.
• Java was developed at Sun Microsystems by
James Gosling, Patrick Naughton in 1991 and
initially named as Oak.
• Surprisingly, development of Java was targeted
at consumer electronics.
• Being architecture neutral/platform independent
was the most powerful feature of Java.
Inception of Java
• Evolved into write once run anywhere.
• Later it was integrated into web browsers and
thus became language of internet.
• Now every six months, a new release of Java
takes place.
• General purpose libraries released, known as
Java API
• Portability and security are other two most
important features of Java.
Java is Easy
• Syntax of Java is similar to C and C++
• Case sensitive language.
• Java is a strictly typed language.
• Emphasis was on keeping the language simple
and user friendly.
• So complex and unsafe features of C++ like
operator overloading, pointer, multiple
inheritance etc were omitted from Java.
Basic Definitions
• Some buzzword of Java are as follows.
• Architecture-neutral
• Bytecode
• Simple
• Secure
• Portable
• Object-oriented
• Robust
• Multithreaded
• Interpreted
• High performance
• Distributed
• Dynamic
References and Primitive Data Types
• Java distinguishes two kinds of entities
• Primitive types
• Objects
• Primitive-type data is stored in primitive-type
variables.
• Reference variables store the address of an
object.
Primitive Data Types
• Eight primitive types of data are available in Java.
• They represent numbers, characters, boolean values.
• Integers: byte, short, int, and long
• Real numbers: float and double
• Characters: char
• Boolean: boolean (a special type for representing
true/false values.)
Variables
• Variables: (Gen. Syntax: type name = value; )
• Type
• Name
• Value
• Naming Convention:
• May contain numbers, underscore, dollar sign or letters
• Can not start with number
• Can be any length
• Reserved keywords can’t be used
• Case sensitive
Operators
• Operators in Java can be broadly divided in 4 major
groups
Arithmetic +, -, *, /, %, ++, +=, -=, *=, /=, %=. --
• Increment
• i++ is equivalent to i = i + 1;
• Can also do ++i, which uses i before
incrementing it.
• Can also do i++, which uses i after
incrementing it.
• Likewise for Decrementing
Relational Operators
• == equality
• != inequality
• > greater than
• < less than
• >= greater than or equal to
• <= less than or equal to
First Application
/*
Hello World, first application.
*/
class demo{
public static void main (String [] args)
{
System.out.println(“Hello World”);
} //end main
}//end class
Compiling and Executing
• Create a Java file (having .java ext.) in any
editor
• Text in demo.java file (reason behind name)
• To compile:
• javac demo.java
• To execute:
• java demo
Java Control Statements
• A group of statements executed in order is
written
{ stmt1; stmt2; ...; stmtN; }
• The statements execute in the order 1, 2, ..., N
• Control statements alter this sequential flow
of execution
Switch/Case
• Switch(variable)
{
case(1): something;
break;
case(2): something;
break;
default: something;
}
Classes and Objects
• The class is the unit of programming
• A Java program is a collection of classes
• Each class definition (usually) in its own .java file
• The file name must match the class name of the main class
• A class describes objects (instances)
• Describes their common characteristics: map/blueprint
• Thus all the instances have these same characteristics
• An Object has these characteristics :
• Data fields for each object
• Method (operation) that perform on the objects.
Referencing and Creating Objects
• You can declare reference variables
– They reference objects of specified types
• Two reference variables can reference the same
object
• The new operator creates an instance of a class
• A constructor executes when a new object is
created
• Gen. Syntax: class object = new constructor;
• Demo ob = new Demo();
Referencing and Creating Objects
• Class_name ob=new Class_name();
• It can be broken into two parts,
i) Class_name ob;
Ii) ob=new Class_name ();
• In the first line a reference variable is created.
• In the second line the reference variable
referring to the newly constructed object.
A Recap
• Java is CASE SENSITIVE.
• Whitespace is ignored by compiler
• Whitespaces and comments makes things
easier to read
• File name has to be the same as class name
having main()
• Need to import necessary class definitions