Professional Documents
Culture Documents
TECNOLOGY
Introduction
Here we are going to look on access protection in java package , within or outside the packages:
classes in the same package can access each other's package-private and protected members,
The java.io package contains all the classes required for input and output
operations,
Also lastly in proxy server networking is discussed, a client connects to the proxy server,
requesting some service, such as a file, connection, web page, or other resource available from a
different server and the proxy server evaluates the request as a way to simplify and control its
complexity. Proxies were invented to add structure and encapsulation to distributed systems.
Today, most proxies are web proxies, facilitating access to content on the World Wide Web and
providing anonymity.
Abstract
A Java package organizes Java classes into namespaces, providing a unique
namespace for each type it contains. Classes in the same package can access each
other's package-private and protected members, Java uses the concept of stream to
make I/O operation fast. The java.io package contains all the classes required for
input and output operations, java utilities Contains the collections framework,
legacy collection classes, event model, date and time facilities, internationalization,
and miscellaneous utility classes (a string tokenize, a random-number generator,
and a bit array). Also In proxy server networking , the proxies were invented to add
structure and encapsulation to distributed systems.
Content
Introduction..i
Abstraction. .ii
Content ii
1. Access protection in java...4
1.1 Class Member Access..5
1.2 Java Access Protection Example..6
2. Utilities in java .10
2.1 utility class .......................................................................10
2.3 package java.util.10
2.3 Java Code example.....11
3. Java - Documentation Comments.....12
3.1 Structure of a Javadoc comment.....12
3.2 Specifications are defined in comment lines...............................................13
3.3 Placement of comments...............................................................................14
4. Proxy sever........................................................................................................14
4.1 Types of proxy saver...16
a. Open proxies
b. Reverse proxies
5. Conclusion ...17
public
private
protected
Provides a variety of ways to produce many levels of access required by these categories, while
the access control mechanism of Java may seem complicated, we can simplify it as follows.
Anything declared as public can be accessed from anywhere.
Anything declared as private can't be seen outside of its class.
When a member doesn't have an explicit access specification, then it is visible to the subclasses
as well as to the other classes in the same package. This is the default access. And If you want to
allow an element to be seen outside your current package, but only to the classes that subclass
your class directly, then declare that element protected.
This table applies only to the members of classes. A non-nested class has only two possible
access levels i.e., default and public.
When a class is declared as public, then it is accessible by any other code. If a class has default
access, then it can only be accessed by the other code within its same package. When a class is
public, it must be only the public class declared in the file that must have the same name as the
class.
Each subsequent class in the following example will try to access the variables in an instance of
this class. The lines that will not compile due to the access restrictions are commented out.
Before each of these lines is a comment that listing the places from which this slevel of
protection would allow access.
The second class named Derived, is a subclass of Protection in the same package, pkg1. This
grants Derived access to every variable in the class Protection except for n_priv, the private
one. The third class named SamePackage, is not a subclass of the class Protection, but is in the
same package and also has access to all but not n_priv.
package pkg1;
public class Protection
{
int n = 1;
private intn_priv = 2;
protected intn_prot = 3;
public intn_publ = 4;
public Protection()
{
System.out.println("base constructor");
System.out.println("n = " + n);
System.out.println("n_priv = " + n_priv);
System.out.println("n_prot = " + n_prot);
System.out.println("n_publ = " + n_publ);
}
}
package pkg1;
class Derived extends Protection
{
Derived()
{
System.out.println("derived constructor");
System.out.println("n = " + n);
7
/* class only
* System.out.println("n_priv = "4 + n_priv); */
System.out.println("n_prot = " + n_prot);
System.out.println("n_publ = " +n_publ);s
}
}
package pkg1;
class SamePackage
{
SamePackage()
{
Protection pro = new Protection();
System.out.println("same package constructor");
System.out.println("n = " + pro.n);
/* class only
* System.out.println("n_priv = " + pro.n_priv); */
System.out.println("n_prot = " + pro.n_prot);
System.out.println("n_publ = " + pro.n_publ);
}
}
Following is the source code for the other package named pkg2. The two classes defined in the
package pkg2 cover the outer two conditions that are affected by the access control. The first
class named Protection2, is a subclass of pkg1.Protection. This grants access to all of pkg1.
Variables of the class Protection except for n_priv (because it is private) and n, the variable
declared with the default protection.
Always remember that the default only allows access from within the class or the package, not
extra-package subclasses. Finally, the class OtherPackage has access to n_publ only which was
declared as public.
package pkg2;
class Protection2 extends pkg1.Protection
{
Protection2()
8
{
System.out.println("derived other package constructor");
/* class or package only
* System.out.println("n = " + n); */
/* class only
* System.out.println("n_priv = " + n_priv); */
System.out.println("n_prot = " + n_prot);
System.out.println("n_publ = " + n_publ);
}
}
package pkg2;
class OtherPackage
{
OtherPackage()
{
pkg1.Protection pro = new pkg1.Protection();
System.out.println("other package constructor");
/* class or package only
* System.out.println("n = " + pro.n); */
/* class only
* System.out.println("n_priv = " + pro.n_priv); */
/* class, subclass or package only
* System.out.println("n_prot = " + pro.n_prot); */
System.out.println("n_publ = " + pro.n_publ);
}
}
2. Utilities in java
2.1 The package java.util
It contains a number of useful classes and interfaces. Although the name of the package might
imply that these are utility classes, they are really more important than that. In fact, Java depends
directly on several of the classes in this package, and many programs will find these classes
indispensable. The classes and interfaces in java.util include:
The StringTokenizer class for parsing strings into distinct tokens separated by delimiter
characters.
The Locale class in Java 1.1, which represents a particular locale for internationalization
purposes.
The Calendar and TimeZone classes in Java. These classes interpret the value of a Date
object in the context of a particular calendar system.
10
In computer programming, a utility class is a class that defines a set of methods that perform
common, often re-used functions. Most utility classes define these common methods under static
(see Static variable) scope. Examples of utility classes include
java.util.Collections, which provides several utility methods (such as sorting) on objects that
implement a Collection (java.util.Collection.
Class Collections
java.lang.Object
java.util.Collections
public class Collections
extends Object
This class consists exclusively of static methods that operate on or return collections. It contains
polymorphic algorithms that operate on collections, "wrappers", which return a new collection
backed by a specified collection, and a few other odds and ends.
The methods of this class all throw a NullPointerException if the collections or class objects
provided to them are null.
The Collections utility class consists exclusively of static methods that operate on or return
collections. It contains polymorphic algorithms that operate on collections, "wrappers", which
return a new collection backed by a specified collection,
Some useful method in Collections class:
Method Signature
Collections.sort(List myList)
Collections.sort(List, comparator c)
Collections.shuffle(List myList)
Collections.reverse(List myList)
Collections.binarySearch(List mlist, T key)
Collections.copy(List dest, List src)
Description
Sort the myList (implementation of any List
interface) provided an argument in natural
ordering.
Sort the myList(implementation of any List
interface) as per comparator c ordering (c class
should implement comparator interface)
Puts the elements of myList ((implementation
of any List interface)in random order
Reverses the elements of myList
((implementation of any List interface)
Searches the mlist (implementation of any List
interface) for the specified object using the
binary search algorithm.
Copy the source List into dest List.
11
Let's take the example of List sorting using Collection class. We can sort any Collection using
Collections utility class. i.e.; ArrayList of Strings can be sorted alphabetically using this utility
class. ArrayList class itself is not providing any methods to sort. We use Collections class static
methods to do this. Below program shows use of reverse(), shuffle(), frequency() methods as
well.
2.3 Java Code:
1. package utility;
2.
3. import java.util.Collections;
4. import java.util.ArrayList;
5. import java.util.List;
6.
7. public class CollectionsDemo {
8.
9.
10.
11.
studentList.add("Neeraj");
12.
studentList.add("Mahesh");
13.
studentList.add("Armaan");
14.
studentList.add("Preeti");
15.
studentList.add("Sanjay");
16.
studentList.add("Neeraj");
17.
studentList.add("Zahir");
18.
19.
20.
12
21.
Collections.sort(studentList);
22.
23.
24.
Collections.reverse(studentList);
25.
26.
Collections.shuffle(studentList);
27.
28.
29.
+ Collections.frequency(studentList, "Neeraj"));
30.
31.}
13
// import statements
/**
* @author
FirstnameLastname<address @ example.com>
* @version 1.6
(current version number of program)
* @since
1.2
(the version of the package this class was first added to)
*/
publicclassTest{
// class body
}
Comment
Description
/*text*/
//text
/**documentation*/
c. Proxy sever
In computer networks, a proxy server is a server (a computer system or an application) that acts
as an intermediary for requests from clients seeking resources from other servers. A client
connects to the proxy server, requesting some service, such as a file, connection, web page, or
other resource available from a different server and the proxy server evaluates the request as a
way to simplify and control its complexity. Proxies were invented to add structure and
encapsulation to distributed systems. Today, most proxies are web proxies, facilitating access to
content on the World Wide Web and providing anonymity.
15
A reverse proxy taking requests from the Internet and forwarding them to servers in an internal
network. Those making requests connect to the proxy and may not be aware of the internal
network.
Many schools block access to popular websites such as Face book. Students can use proxy
servers to circumvent this security. However, by connecting to proxy servers, they might be
opening themselves up to danger by passing sensitive information such as personal photos and
passwords through the proxy server. Some content filters block proxy servers in order to keep
users from using them to bypass the filter.
A proxy server may reside on the user's local computer, or at various points between the user's
computer and destination servers on the Internet.
3
A proxy server that passes requests and responses unmodified is usually called a gateway or
sometimes a tunneling proxy.
16
A forward proxy is an Internet-facing proxy used to retrieve from a wide range of sources (in
most cases anywhere on the Internet).
A reverse proxy is usually an internal-facing proxy used as a front-end to control and protect
access to a server on a private network. A reverse proxy commonly also performs tasks such
as load-balancing, authentication, decryption or caching.
Open proxies
no knowledge of the origin servers. Reverse proxies are installed in the neighborhood of one or
more web servers. All traffic coming from the Internet and with a destination of one of the
neighborhood's web servers goes through the proxy server. The use of "reverse" originates in its
counterpart "forward proxy" since the reverse proxy sits closer to the web server and serves only
a restricted set of websites
A reverse proxy taking requests from the Internet and forwarding them to servers in an internal
network Those making requests connect to the proxy and may not be aware of the internal
network.
Conclusion
Java security technology includes a large set of APIs, tools, and implementations of commonly
used security algorithms, mechanisms, and protocols. The Java security APIs span a wide range
of areas, including cryptography, public key infrastructure, secure communication,
authentication, and access control. Java security technology provides the developer with a
comprehensive security framework for writing applications, and also provides the user or
administrator with a set of tools to securely manage applications.
End
18
19