: The lightweight Directory Access Protocol(LDAP) was
developed in the early 1990s as a standard directory protocol. LDAP is
now probably the most popular directory protocol & because JNDI can
access LADP.
"LDAP defines the mechanism by which clients should
be able access data on the server. It does not however, gives details
how the data should be stored on the server."
LADP uses the
hierarchical tree structure to organize the data, called a Directory
Information Tree(DIT). In DIT each leaf is an entry, and the first
entry is called root entry.
An entry contains a Distinguished(DN)
& attributes-value pairs related to it. The DN is a comprises the
information how it is related to rest of the DIT, same as the Pathname
shows how the file is related to rest of file system.
The path to a
file on a system root to file. A DN reads right to left for example:
uid=sujjain, oi=people, o=theweb.com The leftmost part of a DN is
called a Relative Distinguished Name(RDN) his example would be
uid=scarter.
LADP attributes often use mnemonics as their names.
If we want two Java applications executing within different virtual machines to communicate with each other there are a couple of other Java-based approaches that can be taken besides RMI :
RMI is different with JMS in such a way that the object stays local at one JVM, but in JMSthe object (message) pass through across the network from one JVM to another JVM.
REMOTE METHOD INVOCATION FIG...
Specifically, in RMI, the definition of a remote service is coded using a java interface. The implementation of the remote service is coded in a class. Therefore, the key to understanding RMI is to remember that interfces define behaviour and classes define implementation.
RMI system fig.
The RMI architecture is high-level of abstraction. It is constructed using three layer architecture. The layered architecture gives a transparency for application architecture, mean implementation gives flexibility.
- The Stub-Skeleton Layer : The responsibility of this layer is to intercept and redirect the client request for method calls to remote object.
- The remote Reference Layer : It inter-prates and manages between references, those are made by client to the remote object.
- Transport Layer : It provides the connectivity to machines.
Ans. (b) Java IDL : Java IDL (java Interface Definition Language) is a technology design for distributed objects; those are communicating with each other and running on different platform across the network. It is similar to RMI but with one advantage that interaction among the object written in any programming language like C, C++ etc. including Java.
IDL-Java Bridge Data Type Mapping : When data moves between IDL and a Java object, IDL automatically converts variable data types.
The java IDL, development Process are as know :
- Define the remote interface.
- Compile the remote interface.
- Implement the server.
- Implement the client.
- Start the applications.
Q.5. What are the progress indications? Explain. Wap implementing trees in JAVA. (20)
Ans. Progress indicators or progress bars are the new controls that gives the users some indications of the progress of an operation. They were originally developed to cheek the progress of installation processes but are now frequently used for all time-consuming operations. When we call JProgressBar, we can set the maximum and minimum value for the progress bar. The inheritance diagram for JProgressBar class is as follow :
Java.lang.Object
↓
Java.awt.Component
↓
Java.awt.Container
↓
Javax.swing.JComponent
↓
Javax.swing.JProgressBar
|
Fig : Inheritance diagram for J Progress Bar
Table : Fields of JProgressBar class
Table : Constructors of JProgressBar class
Wap to implement trees in Java :
import Java.awt.*;
import Javax.swing.*;
import Javax.swing.tree.*;
import Java.awt.event.*;
public class SimpleTree extends JFrame {
public static void main(string[] args) {
new simple tree();
public SimpleTree() {
super("Creating a Simple JTree") ;
WindowUtilities.setNativeLookAndFeel() ;
addWindowListener(new ExitListener()) ;
Container content = getContentPane() ;
Object[] hierarchy = {"1. CHAPTER 1",
new Object[] { "1.1 INTRODUCTION TO JAVA",
"1.1.1 History of JAVA",
"1.1.2 JAVA and Internet",
"1.1.3 JAVA Virtual Machine",
"1.1.4 JAVA's Magic : The Byte Code",
"1.1.5 Features of JAVA',
"1.1.6 JAVA Environment"},
new Object[]{ "1.2 DATA TYPES & OPERATORS"},
new Object[] { "1.3 ARRAYS",
"1.3.1 Declaration of Array Variables",
"1.3.2 Array Construction",
"1.3.3 Initialization of Array",
"1.3.4 Array Access",
"1.3.5 Arrays of Characters"},
new Object[] { "1.4 CONTROL STATEMENTS"},
new Object[] { "1.5 A SAMPLE PROGRAM IN JAVA"},
new Object[] { "1.6 CLASSES & METHODS",
"1.6.1 Constructor",
"1.6.2 Garbage Collection"},
new Object[] {"1.7 INHERITANCE",
"1.7.1 Single Inheritance",
"1.7.2 Multiple Inheritance",
"1.7.3 Multilevel Inheritance",
"1.7.4 Hybrid Inheritance",
new Object[] {"1.8 INTERFACE"},
new Object[] {"1.9 PACKAGES"},
new Object[] {"1.10 EXCEPTION HANDLING",
"1.10.1 try and catch with multiple catch clause,"
"1.10.2 throw and throws",
"1.10.3 finally"},
new Object[] {"1.11 MULTITHREADING",
"1.11.1 States of Thread"},
new Object[] {"1.12 COLLECTIONS"},
new Object[] {"1.13 I/O STREAMS",
"1.13.1 Working with InputStream and OutputStream",
"1.13.2 Working with Reader and Writer"},
new Object[] {"1.14 AWT"},
new Object[] {1.15 APPLET PROGRAMMING",
DefaultMutableTreeNode root = processHierarchy(hierarchy) ;
JTree tree = new JTree(root) ;
content.add(new JScrollPane(tree), BorderLayout.CENTER ;
setSize(275, 300) ;
setVisible(true) ;
}
private DefaultMutableTreeNode processHierarchy (object[] hierarchy) {
DefaultMutableTreeNode node = new
DefaultMutableTreeNode(hierarchy[0]) ;
DefaultMutableTreeNode child;
for(int i=1; i<hierarchy,length; i++) {
object nodeSpecifier = hierarchy[i] ;
if (nodSpecifier instanceofobject[]) // Ie node with children
child = processHierarchy((object[]) nodeSpecifier) ;
else
child = new DefaultMutableTreeNode(nodeSpecifier) ; // le Leaf
node.add(child) ;
}
return(node) ;
}}
import Javax.swing.*;
import Java.awt.;
public class WindowUtilities {
public static void setNativeLookAndFeel() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()) ;
} catch(Exception e) {
System.out.println(" Error setting native LAF : " +e) ;
} }
public static void setJavaLookAndFeel() {
try {
UIManager.setLookAndFeel(UIManager.getCross PlatformLookAndFeelClassName());
} catch(Exception e) {
system.out.println("Error setting Java LAF : "+e) ;
} }
public static void setMotifLookAndFeel() {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel") ;
} catch(Exception e) {
System.out.println("Error setting MotifLAF : "+e ) ;
}
}
public static JFrame openInJFrame(Container content, int Width, int height, String title, Color bgColor) {
JFrame frame = new JFrame(title) ;
frame.setBackground(bgColor) ;
content.setBackground(bgColor);
frame.setSize(width, height);
frame.setContentPane(content) ;
frame.addWindowListener(new ExitListener() ) ;
frame.setVisible(true) ;
return(frame) ;
}
public static JFrame openInJFrame(Container content, int width, int height, String title ;
{
return (openInJFrame( content, width, height, title, color.white ) ) ;
}
public static JFrame openInJFrame(Container content, int width, int height) {
return(openInJFrame(content, width, height, content.getClass().getName(), Color.white)) ;
}
}
import Java.awt.* ;
import Java.awt.event.* ;
public class ExitListner extends WindoAdapter {
public void windowClosing(WindowEvent event) {
System.exit(0) ;
}
}
The output interface would look like :
Figure here---------
Q.6.Explain the following :
(a) Transparency and compositions (20)
(b) Clipboard
Ans: (a) Transparency :- Java 2D allows you to give transparency value to drawing operations, so that the graphic to be drawn, partially shows that underlying images. AlphaComposite object has to create by Alphacomposite.getInstance to provide and set the transparency. The object of AlphaComposite will be passed to setComposite method of Graphics2D object. There are 8 built-in mixing rules, but the one normally used for drawing with transparency settings is AlphaComposite. SRC_OVER. Alpha values range from 0.0F (completely transparent) to 1.0F (completely opaque).
Example :
import Java.awt.AlphaComposite ;
import Java.awt.Color ;
import Java.awt.Graphics ;
import java.awt.Graphics2D ;
import Java.swing.JFrame ;
import Java.swing.JPanel ;
public class TransparentRectangles extends Jpanel {
public void paint(Graphics g) {
super.paint(g) ;
Graphics2D g2d = (Graphics2D) g ;
g2d.setColor(Color.BLUE) ;
for (int i = 1; i<= 10; i++) {
g2d.setComposite(AlphaComposite.getInstance ( AlphaComposite.SRC_OVER, i*0. If)) ;
g2d.fillRect (50*i, 20, 40, 40) ;
}
}
public static void main (String[] args) {
JFrame frame = new JFrame ("Transparent Rectangles") ;
frame.add(new TransparentRectangles() ) ;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
frame.setSize(590, 120) ;
frame.setLocationRelativeTo(null) ;
frame.setVisible(true) ;
}
}
Ans. (b) Clipboard : In Java, there are actually two kinds of Clipboard-system and local. The system clipboard corresponds to the usual idea of sharing data between otherwise independent applications running on the same computer. Local Clipboards are visible only with a single Java application. They are created by simply passing a name of the Clipboard constructor. A clipboard acts as a temporary staging area where application users store cut or copied information, including text, graphics, objects, and other data types. It is a heavily exploited data sharing facility. Therefore, when developing new applications, it makes sense to expend extra effort to support the clipboard, Netlecting clipboard functionallity can resulting in an application that gets complaints, requires new development, or-worst of all-never gets used.
Q.7. What are bean ? Explain the naming pattern for bean components with suitable example.
Ans. Java Bean is a softwear component written in Java, provides
portability, platform-independent component model, and re-usability.
You can add these components into applets, applications, or with other
bean components.
By nature, beans are dynamic like other software components; these can be changed or customized.
The
JavaBeans architecture was built through a collaborative industry
effort and enables developers to write reusable components in the Java
programming language.
With the Java Beans API you can create re useable, platform-independent components.
There are three types of benas:
- Visible Bean : A bean component that is visible to an end user, such as a button or any graphical component, that is used with GUI.
- Invisible Bean
: A bean that added with any application but not visible to the end
user on GUI, for example checking the spelling of a document.
- Container Bean
: A bean can contain another bean component, is called the container
bean for example a tree bean can contain another component like images,
labels, etc.
The bean is created by combining the following components:
-
Properties define the characteristics of the bean. It can be change at
design time or run time if it is not read only and some mutator methods
are given in its implementation.
- Events to momunicate with other beans.
- Methods can be called from other beans or from the environment or application in that it is added.
Advantages of beans : There are following advantages of Java Bean components:
- It supports or provide "write-once, run-anywhere" paradigm.
- Three component of the bean are exposed to an application builder tool.
- It has to run in different environment, so that, it is designed correctly.
- It's configuration setting is stored and helps to persist its state and can be used later.
- A Bean may receive events and can communicate with other by generating the events, if it is registered with events.
- States of Bean :
Bean is a resusable software component. So as software hs its
development life cycle similarly bean component has its own states.
These states defines its lifecycle, and are as following;
- Consturaction State : In this state, the bean is under coding phase. The developer busy in writing the code for it.
- Build State : Bean is in build state, where after construction, it is added with any application.
- Run State: As the container application runs, then bean is in run state.
Characteristics of bean :
- Communication :
One bean can communicate with other bean and application in that it is
build. By message passing to method, it do communication.
- Introspection : It is an automatic process to analyze the properties, evens and methods.
- Persistance :
A bean persists by storing and retrieving the properties from storage.
The state of component to be stored in a non-volatile place for later
retrieval.
- Customizers : Modifiying the appearance and behaviour at the time of building, and run time.
Example :
import Java.awt.Graphics;
import Java.beans.PropertyChangeListener;
import Java.beans.PropertyChangeSupport;
import Java.io.Serializable;
import Javax.swing.JComponent;
public class MyFirstBean extends JComponent implements Serializable
{
priavate String caption;
private final PropertyChangeSupport ob = new
PropertyChangeSupport( this );
public String getCaption()
{ return this.caption; }
public void setCaption ( String caption )
{
String oldcaption = this.caption;
this.caption = caption;
this.ob.firstPropertyChange( "caption", oldcaption, caption );
}
public void addPropertyChangeListener ( PropertyChngeListener listener )
{
this.ob.addPropertyChangeListener (listener);
}
public void removePropertyChangeListener ( PropertyChangeListener listener )
{
this.ob.removePropertyChangeListner (listnere);
}
protected void paintComponent ( Graphics g )
{
g.setColor ( getForeground() );
int height = g.getFontMetrics ().getHeight ();
paintString ( g, this.caption, height );
}
private void paintString ( Graphics g, String str, int height )
{ ( str != null )
g.drawString ( str, 0, height )
}
}
Q.8. Does Java has security constraints ? Explain byte code verification and code signing. (20)
Ans. Yes, Java has security constraints.
Byte code verification : When a class loader presents the bytecodes of a newly loaded Java platform class to the virtual machine, the bytecodes are first inspected by a verifier. All classes except system classes are verified. We can deactivate verification with the undocumented-noverify option. For exaple:
java -noverify NewProgram
The bytecode verifier traverses the bytecodes, constructs the type state information, and verifies the types of the parameters to all the bytecode instructions. The figure shows the flow of data and control from the source code to the class loader and bytecode verifier and finally on to the Java virtual machine, which contains the interpreter and runtime system. The bytecode verifier acts gatekeeper as it ensures that code passed to the Java interpreter is in a good state to be executed and can run without the fear of breaking the Java interpreter. Imported code is not allowed to execute by any means until after it has passed the verifier's tests.
Once the verifier is done, a number of important properties are known. Knowing these properties makes the Java interpreter much faster, because it doesn't have to check anything. There are no operand type checks and no stack overflow checks. The interpreter can thus function at full without compromising reliability. The properties are :
> There are no operand stack overflows or underflows.
> The type of the parameters of all bytecode instructions are known to always be correct. Object field accesses are known to be legal -- private, public or protected.
Flow of data and control.......fig.-----
The verifier permits only some bytecode sequences in valid programs and the verifier ensures that any given instruction operates on a fixed stack location that allows the JIT compiler to transform stack accesses into fixed register accesses. Due to this, the JVM does not imply a speed penalty for emulation on register-based architectures when using a JIT compiler. In the face of the code-verified JVM archetecture, it makes no difference to a JIT compiler whether it gets named imaginary registers or imaginary stack positions that need to be allocated to the target architecture's registers. Code verification makes the JVM different from a classic stack architecture whose efficient emulation with a JIT compiler is more complicated and is carried out by a slow interpreter.
The following verification checks are performed by the bytecode verifier. It verifies that
- > The byte stream is either truncated nor padded with extra bytes.
- > The class bytes adhere to the correct format for the class itself, methods, fields and other components.
- > There are no overflows of operands on the stack.
- > There are no underflows of operands on the stack.
- > The proper access specifiers of methods and field variables is defined.
- > final classes are not subclassed.
- > final methods are not overridden.
- > final variables are assigned an initial value and not modified.
- > methods are invoked with the correct number and types of arguments.
- > final variables of the class are assigned with values of the correct type.
- > no local variables is accessed before it has an assigned value.
- > the class has one superclass.
Code signing : One of the most important uses of authentication technology is signing executable programs. If a program is downloaded, then we are concerned about damage that a program can do. For example, the program could have been infected by a virus. If we know where the code comes from and that it has not been tempered then we can be comfortable in using the program. For this, we use authentication to verify where the code came from and then run the code with a security policy that enforces the permissions that you want to grant the program, depending on its origin. The most common use of code signing is to provide security when deploying. Almost every code signing implementation will provides some sort of digital signature mechanism to verify the identity of the author or build system, and a checksum to verify that the object has not been modified. Code signing is done on JAR files.
The Java Archive(JAR) file format enables you to pile multiple files into a single archive file. A JAR file contains the class files and auxiliary resources associated with applets and applications. The general steps involved with code signing process are :
- Compile the code to the signed into class files.
- Creates a JAR files.
- Sign the JAR file.
- Export a public key certificate.
The Java application that wants to accept the code only from a trusted source that has signed the code follows these steps :
- Import the certificate as a trusted certificate.
- Create a policy file indicating that such a principal should be trusted for certain permissions.
- Load the trusted code with your Java application.