Advanced Programming-2 (1)
Advanced Programming-2 (1)
ADMAS UNIVERSITY
INSTITUTE OF TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE
CHAPTER-ONE
Example
while (condition) {
statement1; int x = 10;
… while( x < =20 )
statement n; { System.out.print("valu
} e of x : " + x ); x++;
}
do…while loop
A do-while loop is similar to while loop except the
condition is at the end of the loop.
As a result, the loop always executed at least once,
regardless of whether the condition is true or not.
do { int x = 10;
Statements; do{
} System.out.print("value
of x : " + x ); x++;
while(Boolean_expr
}while( x < =20 ) ;
ession);
The for loop
The for statement (also called for loop) is similar to the
while statement, but has two additional components: an
expression which is evaluated only once before everything
else, and an expression which is evaluated once at the end
of each iteration.
Syntax:
CHAPTER 2
JAVA APPLET
By Habtamu K.
Java applet
Typically embedded inside a web page and runs in the
context of a browser.
Applet class provides the standard interface between
the applet and the browser environment.
The Applet class is contained in the java.applet
package.
All applets run in a window, it is necessary to include
support for that window by importing java.awt package.
Applets are not executed by the console-based Java
run-time interpreter.
Java applet…
Executed by either a Web browser or an applet viewer.
Execution of an applet does not begin at main( ).
Output to your applet’s window is not performed by
System.out.println( ).
Rather, it is handled with various AWT methods, such
as drawString( )
Once an applet has been compiled, it is included in an
HTML file using the APPLET tag.
The applet will be executed by a Java-enabled web
browser when it encounters the APPLET tag within the
Methods in applet class
setBackground(Color): Sets the background
color.
setFont(Font): Sets the font of the component.
setForeground(Color): Sets the foreground color.
show(): Shows the component.
setColor(Color): sets the color for the image to
be drawn.
Applet Initialization and Termination
The Applet class give the framework to build any applet:
init( ), start( ), stop( ), and destroy()
When an applet begins, the AWT calls the following
methods, in this sequence: 1. init( ) 2. start( ) 3. paint( )
When an applet is terminated, the following sequence of
method calls takes place: 1. stop( ) 2. destroy( )
…
init():-
the first method to be called;
used to initialize variables.
start():-
called after init( ).
It is also called to restart an applet after it has been stopped(i.e start() method is called
every time, the applet resumes execution).
paint():-
The paint() method contains Graphics parameter.
Used to redraw the applet output.
stop():-
called when the applet is stopped(i.e for example ,when the applet is minimized the stop
method is called).
destroy():-
called when the applet is about to terminate(the applet is completely removed from
memory).
Java Applet vs Java Application
Do not need to extend any class unless Must extend java.applet.Applet class
required
Can execute codes from the local system cannot do so
Has access to all the resources available in Has access only to the browser-specific
your system services
Chapter 3
hbox.setSpacing(10);
Add all the created nodes to the layout. E.g.
JAVAFX layout components
UI Controls
JavaFX controls are JavaFX components which provide some kind
of control functionality inside a JavaFX application.
For instance, a button, radio button, table, tree etc.
2. Background Events:
doesn't require the user's interaction with the application.
mainly occurred to the operating system interrupts, failure,
Event handler
JavaFX facilitates us to use the Event Handlers to handle
the events generated by:-
Keyboard Actions,
{ //handling code
} });
….
Shapes
The Shape class provides definitions of common properties for objects
that represent some form of geometric shape.
These properties include: The Paint to be applied to the fillable interior
of the shape. The Paint to be applied to stroke the outline of the
shape.
The decorative properties of the stroke, including:
The width of the border stroke.
Whether the border is drawn as an exterior padding to the edges of the
shape, as an interior edging that follows the inside of the border, or as a
wide path that follows along the border straddling it equally both inside and
outside.
Decoration styles for the joins between path segments and the unclosed
ends of paths.
….
Color
In JavaFX, we can fill the shapes with colors.
To apply colors to an application, JavaFX provides various
classes in the package javafx.scene.paint package.
This package contains an abstract class called Paint and it
is the base class of all the classes that are used to apply
colors.
These classes are:-
Color
ImagePattern
LinearGradient
RadialGradient
JavaFX Text
Color
JavaFX library provides a class named
javafx.scene.text.Text for this purpose.
This class provides various methods to alter various
properties of the text.
We just need to instantiate this class to implement text
in our application.
The properties of JavaFX Text are described in the table
below.
Chapter 4
Streams and File I/O
Introduction
Data stored in variables and arrays is temporary.
When the variable lost/the program terminates, the data
will lost too.
Computers store files on secondary storage devices.
Data maintained in files is exists beyond the duration of
program execution.
Input output streams
Stream refers to the transfer of data either to or from
a storage medium.
Input refers to the flow of data from a file means we
can read the contents from a file with the help of Java
program.
(read data from source )
Output refers giving some text in the java’s program
and this will write the data into the file which is
specified.
(write data to a destination).
Stream Classes
The java.io package provides us the large number of
stream classes to perform input and output (I/O) in
Java.
All these streams classes represent an input source and
an output destination.
These classes are divided into groups.
1) Byte Stream Classes -- For handling the operation on
files at the byte level.
2) Character Stream Classes – For handling the operation
on files at the character level. And this Stream uses
16-bit character codes.
InputStream Classes
used to read bytes from a file, memory or console
Some of the subclasses of InputStream class are :
FileInputStream.
DataInputStream.
BufferedInputStream.
StringBufferInputStream and many more.
What is SQL?
Annotations.
…..
Demonstration
remember what we discussed in the class
regarding to java database connectivity
Chapter 8
Introduction
servlet
Java servlet
Runs on web/application server
Act as middle layer b/n :
request(from a web browser) and
applications/database on server
For details, read the
attached pdf file