2. INTRODUCTION
7/15/2017SURBHI SAROHA(Asst.Professor)
2
Java was initially designed to support the
creation of small, portable programs.
Originally, these programs took the form of
applets.
Recall that applets run on the local machine,
inside the browser, and servlets execute on
the server.
Applet is a small java application that run on
browser.
Applet class always be public.
In client side we have Applet and server side
servlet.
11. Applet and Security
7/15/2017SURBHI SAROHA(Asst.Professor)
11
1.Applet can show pictures ,play sounds and
they can send user input back to the server
from which it was loaded(it cannot
communicate with other servers).
2.Applets can not access the local file system or
run local programs.
3.Applets can not find out the user’s name and
so on.
4.Applets can be equipped with a certificate
identifying where they are coming from . This
“trusted ” applets can be given more privileges
by the browser.
12. Abstract Window Toolkit(AWT)
7/15/2017SURBHI SAROHA(Asst.Professor)
12
A class library is provided by the Java
programming language which is known as
AWT.
Has Container , which is an abstract subclass
of components and includes two subclasses:
Panel
Window
24. The GridLayout Manager
7/15/2017SURBHI SAROHA(Asst.Professor)
24
Components are added from left to right and
from top to bottom.
All regions are sized equally.
The Constructor specifies rows and coloums.
26. String Handling
7/15/2017SURBHI SAROHA(Asst.Professor)
26
The String class supports several
constructors. To create an empty String,
you call the default constructor. For example
String s = new String();
will create an instance of String with no
characters in it.
27. Construct one String from
another.
7/15/2017SURBHI SAROHA(Asst.Professor)
27
class MakeString {
public static void main(String args[]) {
char c[ ] = {'J', 'a', 'v', 'a'};
String s1 = new String(c);
String s2 = new String(s1);
System.out.println(s1);
System.out.println(s2);
}
}
The output from this program is as follows:
Java
Java
28. Main functions of String
handling
7/15/2017SURBHI SAROHA(Asst.Professor)
28
1.String Length
The length of a string is the number of characters
that it contains. To obtain this value, call the
length( ) method, shown here:
int length( )
The following fragment prints “3”, since there are
three characters in the string s:
char chars[] = { 'a', 'b', 'c' };
String s = new String(chars);
System.out.println(s.length());
29. Cont….
7/15/2017SURBHI SAROHA(Asst.Professor)
29
2.String Concatenation
In general, Java does not allow operators to be
applied to String objects.
The one exception to this rule is the + operator,
which concatenates two strings, producing a
String object as the result. This allows you to chain
together a series of + operations. For example, the
following fragment concatenates three strings:
String age = "9";
String s = "He is " + age + " years old.";
System.out.println(s);
This displays the string “He is 9 years old.”
30. Cont….
7/15/2017SURBHI SAROHA(Asst.Professor)
30
3.String Comparison
The String class includes several methods that compare
strings or substrings within strings.
4.replace( )
The replace( ) method has two forms. The first replaces
all occurrences of one character in the invoking string with
another character. It has the following general form:
String replace(char original, char replacement)
Here, original specifies the character to be replaced by the
character specified by replacement.
The resulting string is returned. For example,
String s = "Hello".replace('l', 'w');
puts the string “Hewwo” into s.
31. Cont….
7/15/2017SURBHI SAROHA(Asst.Professor)
31
5.trim( )
The trim( ) method returns a copy of the
invoking string from which any leading and
trailing whitespace has been removed. It has
this general form:
String trim( )
Here is an example:
String s = " Hello World ".trim();
This puts the string “Hello World” into s.