Home > Java > javaTutorial > body text

Summary of exceptions and packages during java development

Y2J
Release: 2017-05-05 15:11:56
Original
1959 people have browsed it

This article mainly introduces exceptions and packages in the basics of java. Friends in need can refer to it

1 Exceptions

Exception system

• Throwable

Error

# Usually major problems occur, such as: the running class does not exist or memory overflows, etc.

Do not write code to handle it

Exception

Occurs at runtime In this case, you can use try catch finally

The subclass names of Exception and Error are suffixed with the parent class name.

1.1 Methods in Throwable

##1.2 throws and throw

1.3 Exception handling

try
{
需要检测的代码;
}
catch(异常类
变量)
{
异常处理代码;
}
finally
{
一定会执行的代码;
}
Copy after login

Finally code block will not be executed in only one case. It was System.exit(0) that was executed before.

1.4 Custom exception

Custom class

Inherit Exception or its subclasses.

Define exception information through

constructor .

Example:

Class DemoException extends Exception
{
  DemoException(String message)
  {
    super(message);
  }
}
Copy after login

Throw a custom exception through throw.


1.5 Exception details

##2 Package


Category management of class files.


Provide multiple layers of

namespaces

to classes.
is written on the first line of the program file.


The full name of the class name is package name.class name.


Package is also a form of encapsulation.


2.1 Access between packages

The class permissions in the accessed package must be public.


Member permissions in a class: public or protected


protected is a permission provided to subclasses in other packages


Routine


2.2 Four types of permissions

##3 import

4 Jar package

4.1 Operation of Jar package

Through jar. The operation of jar by exe tool.

Create jar package

jar -cvf mypack.jar packa packb

View jar package

jar -tvf mypack.jar [>Directed file]

Decompression

jar -xvf mypack.jar

Manifest file of custom jar package

jar –cvfm mypack.jar mf.txt packa packb

【Related recommendations】

1.

Java Free Video Tutorial

2. YMP Online Manual

3. Comprehensive analysis of Java annotations

The above is the detailed content of Summary of exceptions and packages during java development. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!