博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java 基础知识 package 和 namespace
阅读量:2208 次
发布时间:2019-05-04

本文共 1591 字,大约阅读时间需要 5 分钟。

我是在学习Java 的时候,接触的这两个概念

package

我 们 把 相 关 的 或 者 属 于 一 类 的 c l a s s 放 到 一 个 p a c k a g e 中 \color{red}{我们把相关的或者属于一类的class 放到一个package 中 } classpackage

例如Java 的 java.lang

Oracle 的描述是这样的

Provides classes that are fundamental to the design of the Java programming language.

The most important classes are Object
which is the root of the class hierarchy, and Class, instances of which represent classes at run time.
Frequently it is necessary to represent a value of primitive type as if it were an object. The wrapper classes Boolean, Character, Integer, Long, Float, and Double serve this purpose.

这是对Java language 极其重要的一个包

包含了Object 和基本数据类型int、double 等等


再来说namespace

在 不 同 的 p a c k a g e 中 , 则 是 不 同 的 n a m e s p a c e \color{red}{在不同的package 中,则是不同的namespace} packagenamespace

来看一个例子:

使用List 时,会要求你导入包

Eclipse 的提示项中有:

import ‘List’ (java.util)

import ‘List’ (java.awt)

相信大家都遇到过这样的情况

在不同的包中存在名字相同的List 类

那么区分它们的一个手段就是namespace(命名空间)

相 同 名 字 的 类 , 利 用 不 同 的 命 名 空 间 区 分 开 来 \color{blue}{相同名字的类,利用不同的命名空间区分开来}


下面再给大家提供一些维基百科上的介绍

Namespaces are commonly structured as hierarchies to allow reuse of names in different contexts

a given set of objects have unique names so that they can be easily identified.

In computer programming, namespaces are typically employed for the purpose of grouping symbols and identifiers around a particular functionality and to avoid name collisions between multiple identifiers that share the same name.

In networking, the Domain Name System organizes websites (and other resources) into hierarchical namespaces.

转载地址:http://qoiyb.baihongyu.com/

你可能感兴趣的文章
分布式系统理论基础3: 时间、时钟和事件顺序
查看>>
分布式系统理论基础4:Paxos
查看>>
分布式系统理论基础5:选举、多数派和租约
查看>>
分布式系统理论基础6:Raft、Zab
查看>>
分布式系统理论进阶7:Paxos变种和优化
查看>>
分布式系统理论基础8:zookeeper分布式协调服务
查看>>
搞懂分布式技术1:分布式系统的一些基本概念
查看>>
搞懂分布式技术2:分布式一致性协议与Paxos,Raft算法
查看>>
搞懂分布式技术3:初探分布式协调服务zookeeper
查看>>
搞懂分布式技术4:ZAB协议概述与选主流程详解
查看>>
搞懂分布式技术5:Zookeeper的配置与集群管理实战
查看>>
搞懂分布式技术6:Zookeeper典型应用场景及实践
查看>>
搞懂分布式技术10:LVS实现负载均衡的原理与实践
查看>>
搞懂分布式技术11:分布式session解决方案与一致性hash
查看>>
搞懂分布式技术12:分布式ID生成方案
查看>>
搞懂分布式技术13:缓存的那些事
查看>>
搞懂分布式技术14:Spring Boot使用注解集成Redis缓存
查看>>
搞懂分布式技术15:缓存更新的套路
查看>>
搞懂分布式技术16:浅谈分布式锁的几种方案
查看>>
搞懂分布式技术17:浅析分布式事务
查看>>