Java PPT Rss
Java PPT Rss
CORE JAVA
ADVANCE JAVA(JSP AND SERVLET)
MOBILE JAVA(ANDROID)
Method Method
Data
Method
Method
Object
Person
Name Data
BasicPay
Salary()
Methods
Tax()
Representation of an object
Property Inheritance
Rutvi Sheth (Lecturer Comp Dept.)
Polymorphism
Polymorphism is another important OOP concept.
Polymorphism means ability to take more than one form.
Shape
Draw()
Polymorphism
Hardware and
Programmer
Operating System
Programmer
JAVA COMPILER
(translator)
JAVA INTERPRETER
(one for each different system)
Core Classes
language
Utilities
Input/Output
Low-Level Networking
Abstract Graphical User Interface
Internet Classes
TCP/IP Networking
WWW and HTML
Distributed Programs
C++
C Java
Subset of C++
Rutvi Sheth (Lecturer Comp Dept.)
Java better than C++ ?
Typedefs, Defines, or Preprocessor
No Global Variables
?
No Goto statements
No Pointers
No Unsafe Structures
No Multiple Inheritance
No Operator Overloading
Stand-alone applications
Web applications (applets)
1 2 3 4 5
APPLET hello.class Create Accessing The browser
Development AT SUN’S Applet from creates
“hello.java” WEB tag in Unimelb.edu.au a new
AT SERVER HTML window and
SUN.COM document a new thread
and
then runs the
code
Hello Java
<app=
“Hello”> The Internet
Hello
Interactive WWW
Flashy animation instead of static web
pages
Applets react to users input and
dynamically change
Display of dynamic data
WWW with Java - more than a document
publishing medium
Concept Write once compile anywhere Write once run anywhere everywhere
Java Source
javadoc HTML Files
Code
javac
java jdb
Output
Rutvi Sheth (Lecturer Comp Dept.)
Let us Try Out
Compilation
# javac hello.java
results in HelloInternet.class
Execution
# java HelloInternet
Hello Internet
#
char
Two-byte unicode
Assignment with ‘ ‘
e.g. char c = ‘h’;
boolean
true or false
e.g. boolean x = true;
if (x){…};
Not equal to != if (y != 5) …
Format:
arrayname[position number]
size
int x = myString.length ();
equality / comparison
if (er.equals (”Stamp
Required”))
substring
p = s.substring (0,s.indexOf
(’-’));
concatenation
System.out.print (”Hello, “ +
name);
String s = null;
String t = “”;
String u = “The letter u.”;
String v = u;
Strings are immutable
StringBuffer is a modifiable
alternative
protected X X X
public X X X X
package X X
Rutvi Sheth (Lecturer Comp Dept.)
Initializing Objects
Initialization is a must every time an object is
created out of a class.
Java compiler will initialize all class members and
creating default constructors that initialize data
members as follows: 0 for primitive numeric types,
false for boolean, null for references.
Initialization mainly happened in the class
constructors.
A class could have more than one way
(constructor) of initialization.
Initializers are passed as arguments to constructor
Rutvi Sheth (Lecturer Comp Dept.)
Object Instantiating
Classes only describe data types. To put
then in use at runtime, objects have to be
created (instantiated) from them.
“new” keyword is used to instantiate an
object from a class. Example:
public Font myFnt = new
Font(“Arial”, Font.ITALIC, 12);
No objects can be instantiated from
Abstract classes. You can not use new
here.
Rutvi Sheth (Lecturer Comp Dept.)
Abstract Classes
Sometimes, a class that you define represents an abstract
concept and, as such, should not be instantiated.
For example, the Number class in the java.lang package
represents the abstract concept of numbers. Number class
makes sense only as a superclass to classes like Integer
or Float.
An abstract class is a class that can only be subclassed-- it
cannot be instantiated.
To declare that your class is an abstract class, use the
keyword abstract before the class keyword in your class
declaration:
abstract class Number { . . . }
Base Class
Java.awt.Dialog (or Parent Class
or Superclass)
Is-a relationship
Derived Class
Java.awt.FileDialog (or Child Class
or Subclass)
Is-a relationship
Method print_mailing_list
is polymorphic
types)
The binding of messages to method definitions is
instance-dependent, and it is known as dynamic
binding
It has to be resolved at run-time
Dynamic binding requires the virtual keyword in C+
+
Static binding requires the final keyword in Java
inheritance
A class may inherit multiple interfaces, but, in the
absence of implementations, the collision is irrelevant
Throwable classes
Catching exceptions
Throwing exceptions
Checked exceptions
Error handling
Finally
ClassCastException Object x =
new Integer(1);
String s = (String) x;
...
RuntimeException ...
Classes derived from Classes derived from
RuntimeException are ... Exception are used
used for ordinary system- for ordinary errors that a
generated errors, like program might want to
ArithmeticException catch and recover from
Rutvi Sheth (Lecturer Comp Dept.)
Outline
Throwable classes
Catching exceptions
Throwing exceptions
Checked exceptions
Error handling
Finally
stops…
…then y gets a chance ...
Throwable classes
Catching exceptions
Throwing exceptions
Checked exceptions
Error handling
Finally
System.out.print("1, ");
try {
throw new OutOfGas();
}
catch (OutOfGas e) {
System.out.print("2, ");
}
System.out.println("3");
try {
throw new OutOfGas("You have run out of gas.");
}
catch (OutOfGas e) {
System.out.println(e.getMessage());
}
Throwable classes
Catching exceptions
Throwing exceptions
Checked exceptions
Error handling
Finally
...
RuntimeException ...
...
or declare it throws it
too… ...
f’s activation
record
Throwable classes
Catching exceptions
Throwing exceptions
Checked exceptions
Error handling
Finally
if (s.hasMore()) x = s.pop();
else …
/**
* Reset the error flag. We set it to false.
*/
public void resetError() {
error = false;
}
Throwable classes
Catching exceptions
Throwing exceptions
Checked exceptions
Error handling
Finally
Farewell to Java
Client Interactive
Applet web, security, and client
Server
consistency
Slow to download, inconsistent VMs
(besides, flash won this war)
//HelloWorld.java
import java.applet.Applet;
import java.awt.*;
}
}
<HTML>
<TITLE>HELLO WORLD APPLET</TITLE>
<HEAD>THE HELLO WORLD APPLET</HEAD>
<APPLET CODE=“HelloWorld.class” width=500
height=500>
</APPLET>
</HTML>
Using AppletViewer
Using Browser