List Headline Image
Updated by Santosh Sahu on Dec 24, 2021
 REPORT
Santosh Sahu Santosh Sahu
Owner
41 items   1 followers   48 votes   22 views

Java Tutorial

Java is a high level, robust, object-oriented, class-based, concurrent, secured and general-purpose programming language. The syntax Java is very much similar to C and C++. It is used to create window-based applications, mobile applications, web applications and enterprise applications. Applications developed in Java are also called WORA (Write Once Run Anywhere). This implies that a complied Java application is expected to run on any other Java-enabled system without any adjustment. As of now, Java is one of the most popular programming languages in use particularly for client-server web applications.

This tutorial is intended for students or professionals interested in studying basic and advanced concepts of Java. This tutorial covers all topics of Java which includes data types, operators, arrays, strings, control statements, functions, classes, object-oriented programming, constructor, inheritance, polymorphism, encapsulation, exception handling & File IO.

Source: https://www.alphacodingskills.com/java/java-tutorial.php

Java.util package provides a vector class which models and implements vector data structure. A vector is a sequence container implementing array that can change in size. Unlike array, the size of a vector changes automatically when elements are appended or deleted. It is similar to ArrayList, but with two differences:

  • Vector is synchronized.
  • Vector contains many legacy methods that are not part of the collections framework.

Java.util package provides a Hashtable class which implements hash table and maps keys to value. Any non-null object can be used as a key or as a value. To successfully store and retrieve objects from a hashtable, the objects used as keys must implement the hashCode method and the equals method. If many entries are to be made into a Hashtable, creating it with a sufficiently large capacity may allow the entries to be inserted more efficiently than letting it perform automatic rehashing as needed to grow the table.

Java.util package provides a LinkedList class which has Doubly-linked list implementation of the List and Deque interfaces. The class has all optional list operations, and permits all elements (including null). Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index.

Java.util package provides a BitSet class which implements a vector of bits that grows as needed. Each component of the bit set has a boolean value. The bits of a BitSet are indexed by nonnegative integers. By default, all bits in the set initially have the value false. One BitSet may be used to modify the contents of another BitSet through logical AND, logical inclusive OR, and logical exclusive OR operations.

Passing a null parameter to any of the methods in a BitSet will result in a NullPointerException.

A BitSet is not safe for multithreaded use without external synchronization.

Java.util package provides a EnumMap class which is a specialized Map implementation for use with enum type keys. All of the keys in an enum map must come from a single enum type that is specified, explicitly or implicitly, when the map is created. Enum maps are maintained in the natural order of their keys (the order in which the enum constants are declared). Null keys are not permitted. Attempts to insert a null key will throw NullPointerException. Null values are permitted.
EnumMap is not synchronized. If multiple threads access an enum map concurrently, and at least one of the threads modifies the map, it should be synchronized externally.

Java.util package provides a Dictionary class which is the abstract parent of any class, such as Hashtable, which maps keys to values. Every key and every value is an object. In any one Dictionary object, every key is associated with at most one value. Given a Dictionary and a key, the associated element can be looked up. Any non-null object can be used as a key and as a value.

Java.util package provides a Arrays class which contains a static factory that allows arrays to be viewed as lists. The class contains various methods for manipulating arrays like sorting and searching. The methods in this class throw a NullPointerException, if the specified array reference is null.

A Hashtable models and implements the Map interface. This implementation provides all of the optional map operations, and permits null values and the null key. A HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. This class makes no guarantees as to the order of the map. It does not guarantee that the order will remain constant over time.

Java.util package provides an ArrayDeque class which provides resizable-array implementation of the Deque interface. An Array deque has no capacity restrictions and grows as necessary to support usage. It is not thread-safe; in the absence of external synchronization. It do not support concurrent access by multiple threads. Null elements are prohibited in ArrayDeque. It is likely to be faster than Stack when used as a stack, and faster than LinkedList when used as a queue.

Java.util package provides an ArrayList class which provides resizable-array implementation of the list interface. It implements all optional list operations and permits all elements including null. Along with this, the class provides methods to manipulate the size of the array that is used internally to store the list. This class is almost equivalent to Vector class except the implementation is not synchronized.

Java.util package provides a Collections class which 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. The methods of this class all throw a NullPointerException if the collections or class objects provided to them are null.

Java.util package provides a Date class which represents a specific instant in time, with millisecond precision. Prior to JDK 1.1, the class Date had two additional functions. It allowed the interpretation of dates as year, month, day, hour, minute, and second values. It also allowed the formatting and parsing of date strings. Unfortunately, the API for these functions was not amenable to internationalization. As of JDK 1.1, the Calendar class should be used to convert between dates and time fields and the DateFormat class should be used to format and parse date strings. The corresponding methods in Date are deprecated.

Java.util package provides a EnumSet class which is a specialized Set implementation for use with enum types. All of the elements in an enum set must come from a single enum type that is specified, explicitly or implicitly, when the set is created. Enum sets are represented internally as bit vectors. This representation is extremely compact and efficient. Null elements are not permitted. Attempts to insert a null element will throw NullPointerException.

A HashSet class implements the Set interface, backed by the a Hashtable interface (actually a HashMap instance). This class makes no guarantees as to the iteration order of the set. It does not guarantee that the order will remain constant over time. The class permits the null element.

Java.util package provides a PriorityQueue class where an unbounded priority queue based on a priority heap. The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used. A priority queue does not permit null elements. A priority queue relying on natural ordering also does not permit insertion of non-comparable objects.

Java.util package provides a Scanner class. A simple text scanner parse primitive types and strings using regular expressions. A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods.

A scanning operation may block waiting for input and not safe for multi-threaded use without external synchronization.

Java.util package provides a stack class which models and implements stack data structure. A stack is a linear dynamic data structure that follows Last-In/First-Out (LIFO) principle. In a stack, addition of a new element and deletion of an element occurs at the same end which implies that the element which is added last in the stack will be the first to be removed from the stack.

Java.util package has a Timer class which provides a facility for threads to schedule tasks for future execution in a background thread. Tasks may be scheduled for one-time execution, or for repeated execution at regular intervals. It is thread-safe class, i.e, multiple threads can share a single Timer object without the need for external synchronization. Internally, it uses a binary heap to represent its task queue, so the cost to schedule a task is O(log n), where n is the number of concurrently scheduled tasks.

Java.util package provides a UUID class which represents an immutable universally unique identifier (UUID). A UUID represents a 128-bit value. It is used for for creating random file names, session id in web application, transaction id etc. There are four different basic types of UUIDs: time-based, DCE security, name-based, and randomly generated UUIDs.

A constructor is a special method of a class which automatically executed when a new object of the class is created. It allows the class to initialize object attributes and allocate memory.

The constructor function is declared just like a regular method except the class name and method name should be same without any return type.

When a constructor is not specified in a class, compiler generates a default constructor and inserts it into the code. However, it does not initialize object attributes.

Java.util package provides a Random class. An instance of this class is used to generate a stream of pseudorandom numbers. The class uses a 48-bit seed, which is modified using a linear congruential formula. The algorithms implemented by class Random use a protected utility method that on each invocation can supply up to 32 pseudorandomly generated bits.

Java.util package provides a GregorianCalendar class which is a concrete subclass of Calendar and provides the standard calendar system used by most of the world. GregorianCalendar is a hybrid calendar that supports both the Julian and Gregorian calendar systems with the support of a single discontinuity, which corresponds by default to the Gregorian date when the Gregorian calendar was instituted. The only difference between the Gregorian and the Julian calendar is the leap year rule. The Julian calendar specifies leap years every four years, whereas the Gregorian calendar omits century years which are not divisible by 400.

Java.util package provides a Calendar class which represents a specific instant in time, with millisecond precision.

Java.util package provides a TimeZone class which represents a time zone offset, and also figures out daylight savings. It takes into consideration various time zone. Through the method used under this class a program running in any country, gets a TimeZone object based on that particular country's time zone.

Java.util package provides a TreeMap class which is the Red-Black tree based NavigableMap implementation of the Map interface. The Map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used. The class guarantees that the Map will be in ascending key order.