Default Package In Java

Default Package In Java

Default Package In Java


default package in java,java package does not exist,java package naming convention,creating packages in java,how to create package in java


Complete Packages in Java Program

Container of a classes and interfaces

Features

1. The class contained in package of other program can be easily released.
2. In package the class can be unique and compared with class in other package (ie) 2 class in 2 different package can have same name.
3. Package provide away of hiding classes and preventing them from other program or other package accessing that classes that meant for internal use.

Packages Types

1.Java application
2. User defined

commonly used packages in java
l -- lang
l -- awt
l -- io
l -- net
l -- applet
l -- util
l -- math

Syntax

package<package name>;
public class classname
{
body of class;
}

Step to create a package

1. Create a directory which has the same name as the package name.
2. Include package keyword as the 1st statement in program along with package name
3. Write class declaration and implementation save the file as lass name.java with in directory.
4. Compile using java complex.

Rules for creating package

1. While defining package the package keyword must followed by a package name and end with semicolon(i)
2. The class declared in package must be in public for to assesment anywhere.
3. The directory name as well as package name must same save file in form of class name.java.

Errors and Exception Handling

Errors are wrongs that can make a program go wrong or procedure an incorrect output or terminate the execution of a program. Sometimes it leads to system crash.

Types

1. Compile time error
2. Run time error

Compile time error

All syntax error will be detected and display by the java compile. Hence these errors are known as compile time error. Ex- Missing semicolon at end of termination. Variable declared next to processing statements.

Run time error

Sometimes a program may complie successfully and creates the class file but may not run properly such as programe may produce wrong results due to wrong logic on may terminates due to link errors. Eg When a no was divided by 0.

Exception Handling

An exception is a condition that is caused a run time error in program. If the exception object is not immovable and handled properly, the interpreter will show error messages. If we want to continue with exception at the remaining code the we should to try to catch thew exception object thrown by error condition. This task is called Exception Handling.

Java Common Exception

1. Arithematic Exception
2. Array Index Out of Bounds
3. Array Store Exception
4. File Not Found Exception
5. IO Exception etc.

An Applet is a window based java program used for internet applications. These can be run by using either web browser or with an applet viewer.
It supports animation advanced graphics.
These are 2 types
1. Local applet
2. Remote applet

Local applet are developed locally and stored in the local computer. To run a local applet there is no need for internet connection. At the runtime the system searches the applet code in the local hard disk.

Remote applets are developed by unknown person and stored in remote computers. To run a remote applet internet connection is needed. At run time the system searches the applet code in interest and its downloaded(web address).

Applet methods
1. init()
This method is used to initialize the variables.
2. start()
used to start applet. It must be called aiter stop() method.
3. stop()
used to stop the method.
4. Destroy()
used to deallocate the applet memory. It must be called after stop() methods.
5. paint(Graphics g)-used to display output to applet.
6. repaint() - used to refresh applet windows.

Restrictions

1. Applet cant read or write to file system.
2. They cant communicate with anyother server than in which they were stored originally.
3. They cant run any program on the system.

4. They cant contain main() function.

Post a Comment

0 Comments