Java utils как добавить

java util Package — java.util Package in Java

The java.util package provides Java collections framework classes, internationalization support classes, a service loader, properties, random number generation, string parsing and scanning classes, base64 encoding and decoding, a bit array, and several miscellaneous utility classes. This package also contains legacy collection classes and legacy date and time classes.

Package java.util

Package java.util contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array).

What is java.util Package ?

The java.util package is a Java package like other packages in Java. Like java.lang package, Java util package also a package which contains Java collections framework classes. Assuming you mean the packages that include the class libraries like java.lang.* and java.util.*, these live in the «lib» directory under wherever your Java Runtime Environment (JRE) is installed.

What is import java.util.* in Java ?

The import is a java keyword which is used for importing a Java class or entire Java package. For example import java.util.Calendar; means you are importing a single Calendar class. If you want to import all the classes from any Java package, your import statement must be like this import java.util.* that means you are importing entire java.util package.

java.util Package Import Statement Example

What does import java.util.* do in Java ?

Java util ( java.util.* ) package contains collection framework . Java collections framework contains collection classes , classes related to date and time , event model , internationalization , and miscellaneous utility classes . On importing this ( java.util ) package , you can do access all these classes and methods .

What is the use of java.util Package in Java ?

The use of java.util package is as follows

  1. It can be use for Java collections.
  2. It can be use for internationalization support by using the internationalization supported classes from java.util package.
  3. It can be use for random number generation.
  4. It can be use for string parsing.
  5. It can be use for base64 encoding and decoding.

java util Package - java.util Package in Java, java.util package provides Java collections framework, internationalization, service loader, properties, random number generation, string parsing and scanning., Complete Tutorial on java.util Package.

What is Collections Framework in Java ?

A collection sometimes called a container is simply an object that groups multiple elements into a single unit. Collections are used to store, retrieve, manipulate, and communicate aggregate data in Java .

  • A collection is the same as the intuitive, mathematical concept of a set. A set is just a group of unique items, meaning that the group contains no duplicates.
  • Java Collections Framework provides a set of interfaces and classes for storing and manipulating groups of data as a single unit, a collection.
  • The framework provides a convenient API to many of the abstract data types maps, sets, lists, trees, arrays, hashtables, and other collections.
  • Because of their object-oriented design, the Java classes in the Collections Framework encapsulate both the data structures and the algorithms associated with these abstractions.
  • With the Java Collections Framework the programmer easily define higher level data abstractions, such as stacks, queues, and thread safe collections.
Читайте также:  Python try except error code

java.util package contains Java Collections Framework classes as follows.

Java Collections Framework Classes

AbstractCollection

The AbstractCollection class provides a skeletal implementation of the Collection interface, to minimize the effort required to implement this interface.

AbstractList

The AbstractList class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a «random access» data store (such as an array).

AbstractMap

The AbstractMap class provides a skeletal implementation of the Map interface, to minimize the effort required to implement this interface.

AbstractQueue

The AbstractQueue class provides skeletal implementations of some Queue operations.

AbstractSequentialList

The AbstractSequentialList class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a «sequential access» data store (such as a linked list).

AbstractSet

The AbstractSet class provides a skeletal implementation of the Set interface to minimize the effort required to implement this interface..

ArrayDeque

The ArrayDeque class Resizable-array implementation of the Deque interface.

ArrayList

The ArrayList class Resizable-array implementation of the List interface.

Arrays

The Arrays class contains various methods for manipulating arrays (such as sorting and searching).

Collections

The Collections class consists exclusively of static methods that operate on or return collections.

EnumMap

The EnumMap class A specialized Map implementation for use with enum type keys.

EnumSet

The EnumSet class A specialized Set implementation for use with enum types.

HashMap

The HashMap class Hash table based implementation of the Map interface.

HashSet

The HashSet class implements the Set interface, backed by a hash table (actually a HashMap instance).

HashTable

The HashTable class implements a hash table, which maps keys to values.

IdentityHashMap

The IdentityHashMap class implements the Map interface with a hash table, using reference-equality in place of object-equality when comparing keys (and values).

LinkedHashMap

The LinkedHashMap class Hash table and linked list implementation of the Map interface, with predictable iteration order.

LinkedHashSet

The LinkedHashSet class Hash table and linked list implementation of the Set interface, with predictable iteration order.

LinkedList

The LinkedList class Doubly-linked list implementation of the List and Deque interfaces.

PriorityQueue

The PriorityQueue class An unbounded priority queue based on a priority heap.

Читайте также:  Python read text file one line

TreeMap

The TreeMap class A Red-Black tree based NavigableMap implementation.

TreeSet

The TreeSet class A NavigableSet implementation based on a TreeMap.

Vector

The Vector class implements a growable array of objects.

WeakHashMap

The WeakHashMap class Hash table based implementation of the Map interface, with weak keys.

Internationalization I18N Supported Classes in Java

Create application that can be adapted to different languages and regions is known as Internationalization I18N. Which provides support for various countries, various languages and various currency formates without performing any change in the application.

Internationalization is also abbreviated as I18N because there are total 18 characters between the first letter ‘I’ and the last letter ‘N’.

Internationalization I18N Supported Classes in Java as follows.

  1. Locale : A Java Locale class represents a specific geographical, political, or cultural region.
  2. Locale.Builder : Builder is used to build instances of Locale from values configured by the setters.
  3. ResourceBundle : Resource bundles contain locale-specific objects.

ServiceLoader Class in Java

A facility to load implementations of a service. A service is a well-known interface or class for which zero, one, or many service providers exist. A service provider (or just provider) is a class that implements or subclasses the well-known interface or class.

Properties Class in Java

The Properties class represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream. Each key and its corresponding value in the property list is a string.

Java double Array Happy Father Java Basics what is coronavirus covid-19 Java Arrays Father 9 Best Father’s Day 2023 Gifts Python Data Types HTML5 Tutorial How to store byte array in SQL Server using Java The Python Tutorial Java Collections Framework Python Keywords How to store byte array in MySQL using Java HTML5 Tags Tutorial Java byte Array Java JDBC Tutorial - Java Database Connectivity

© 2010 — 2023 HudaTutorials.com All Rights Reserved.

Источник

Introduction to java.util Package

Hello all👋 I hope you are doing well. This is going to be a short introductory article about the most useful package in Java i.e., java.util package.

Let’s begin.

Let’s first understand package

What is a package?

In short a Java package is collection of similar type of classes.

A Package can be defined as a collection of similar types of classes, interfaces and sub-packages in the form of directory structure. You can read more about packages in one of my article here.

java.util

The basic utility classes required to a programmer are present in this package. It contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array). To use any class you have to import java.util package at top of the program:-

import java.util.Class_name; 

To make it easy let’s take an example, let’s suppose you want to print date and time in your program you will need to import java.util package.

import java.util.Date; //or //import java.util.*; public class Demo  public static void main(String[] args)  Date date = new Date(); System.out.println("The date is : " + date); > > 

java.util.png

You can run your code online here

What is use of java.util package?

  • For Java collections.
  • For random number generation.
  • For Calendar.
  • For string parsing.
  • For internationalization support by using the internationalization supported classes from java.util package (Locale).

Some important and generally used classes

Some important and generally used classes and interfaces which are present inside the java.util package are:-

  • Arrays :- This class contains various methods for manipulating arrays.
  • ArrayList :- This class is resizable-array implementation of the List interface.
  • Collections :- This class consists exclusively of static methods that operate on or return collections.
  • Date :- This class represents a specific instant in time, with millisecond precision.
  • EventObject :- This class is the root class from which all event state objects shall be derived.
  • Formatter :- An interpreter for printf-style format strings.
  • HashMap :- The HashMap class Hash table based implementation of the Map interface.
  • HashSet :- The HashSet class implements the Set interface, backed by a hash table (actually a HashMap instance).
  • HashTable :- The HashTable class implements a hash table, which maps keys to values.
  • LinkedList :- The LinkedList class Doubly-linked list implementation of the List and Deque interfaces.
  • Locale :- A Locale object represents a specific geographical, political, or cultural region.
  • Objects :- This class consists of static utility methods for operating on objects.
  • Random :- An instance of this class is used to generate a stream of pseudorandom numbers.
  • Scanner :- A simple text scanner which can parse primitive types and strings using regular expressions. (Read more)
  • StringTokenizer :- The string tokenizer class allows an application to break a string into tokens.
  • Timer :- A facility for threads to schedule tasks for future execution in a background thread.
  • TimerTask :- A task that can be scheduled for one-time or repeated execution by a Timer.
  • TreeMap :- The TreeMap class A Red-Black tree based NavigableMap implementation.
  • TreeSet :- The TreeSet class A NavigableSet implementation based on a TreeMap.

Источник

Импорт пакетов в Java

Если вспомнить, что пакеты предлагают эффективный механизм изоляции раз­личных классов друг от друга, то становится понятно, почему все встроенные классы Java хранятся в пакетах.

Ни один из основных классов Java не хранится в неимено­ванном пакете, используемом по умолчанию. Все стандартные классы непременно хранятся в каком-нибудь именованном пакете.

А поскольку в самих пакетах классы должны полностью определяться по именам их пакетов, то длинное, разделяемое точками имя пути к пакету каждого используемого класса может оказаться слишком громоздким.

Импорт пакетов в Java

Следовательно, чтобы отдельные классы или весь пакет можно было сде­лать доступными, в Java внедрен оператор import.

После того как класс импортиро­ван, на него можно ссылаться непосредственно, используя только его имя.

Оператор import служит только для удобства программирования и не является обязательным с формальной точки зрения для создания завершенной программы нa java.

Но если в прикладном коде приходится ссылаться на несколько десятков классов, то оператор import значительно сокращает объем вводимого исходного кода.

В исходном файле программы нa java операторы import должны следовать не­посредственно за оператором package (если таковой имеется) и перед любыми определениями классов.

Оператор import имеет следующую общую форму:

Источник

Оцените статью