These are the primitive data types for Java.
| Type | Contains | Default | Size | Min Value | Max Value |
|---|---|---|---|---|---|
| boolean | true or false | false | 1 bit | N/A | N/A |
| char | Unicode character | /u0000 | 16 bits | /u0000 | /uFFFF |
| byte | signed integer | 0 | 8 bits | -128 | 127 |
| short | signed integer | 0 | 16 bits | -32768 | 32767 |
| int | signed integer | 0 | 32 bits | -2147483648 | 2147483647 |
| long | signed integer | 0 | 64 bits | -9223372036854775808 | -9223372036854775807 |
| float | IEEE 754 floating-point | 32 bits | 0.0 | 1.40239846E-45 | 3.40282347E+38 |
| double | IEEE754 floating-point | 0.0 | 64 bits | 4.94065645841246544E-324 | 1.79769313486231570E+308 |
Basic operators for the language.
| Operator | Operand type(s) | Performs |
|---|---|---|
| ++ | arithmetic | pre- or post- increment |
| -- | arithmetic | pre- or post- decrement |
| +, - | arithmetic | plus, minus |
| ~ | integral | bitwise complement |
| ! | boolean | logical complement |
| ( type ) | any | cast |
| *, /, % | arithmetic | multiply, divide, remainder |
| +, - | arithmetic | addition, subtraction |
| + | string | concatenation |
| << | integral | left shift |
| >> | integral | right shift |
| >>> | integral | right shift with zero extension |
| <, <= | arithmetic | less than, less than or equal |
| >, >= | arithmetic | greater than, greater than or equal |
| instanceof | object, type | type comparison |
| == | primitive | equals (have identical values) |
| != | primitive | not equal (have different values) |
| == | object | refers to the same object |
| != | object | does not refer to the same object |
| & | integral | bitwise AND |
| & | boolean | boolean AND |
| ^ | integral | bitwise XOR |
| ^ | boolean | boolean XOR |
| | | integral | bitsize OR |
| && | boolean | conditional AND |
| || | boolean | conditional OR |
| ? : | boolean, any, any | conditional operator |
| = | variable, any | assignment |
+=, /=, %=, *=, -=, <<=, >>=, >>>=, &=, ^=, |= |
variable, any | assignment with operations |
This list contains the various command line tools you use for the various Java related programming functions.
Each of these commands has a variety of parameters you can enter to modify the behavior of the command.
Full documentation is available in the Java Documentation in the section titled "Tool Documentation".
| Command | Description |
|---|---|
| java | runs a program contained in a class file |
| javac | compiles a .java file into a .class file |
| appletviewer | used for testing applets |
| javadoc | generate source code documentation |
| jar | command used to build jar files |
| javap | dis-assemble a Java program to source code |
| jdb | Java debugger |
When you install the Java language, you are giving yourself access to dozens of class libraries to use code that has already been written.
The documentation for each of these classes contains a list of the methods and properties of the method, as well as reference to the class's superclasses and all of its inherited methods and properties.
Some of the packages are listed below. For a complete list, look at the Java Documentation in the section titled "Java 2 Platform API Specification".
| Class | Contents |
|---|---|
| java.applet | Provides the classes necessary to create an applet and the classes an applet uses to communicate with its applet context. |
| java.awt | Contains all of the classes for creating user interfaces and for painting graphics and images. |
| java.beans | Contains classes related to Java Beans development. |
| java.io | Provides for system input and output through data streams, serialization and the file system. |
| java.lang | Provides classes that are fundamental to the design of the Java programming language. |
| java.math | Provides classes for performing arbitrary-precision integer arithmetic (BigInteger) and arbitrary-precision decimal arithmetic (BigDecimal). |
| java.net | Provides the classes for implementing networking applications. |
| java.sql | Provides the API for accessing and processing data in a data source using the JavaTM programming language. |
| java.text | Provides classes and interfaces for handling text, dates, numbers, and messages in a manner independent of natural languages. |
| 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). |
| javax.swing | Provides a set of "lightweight" (all-Java language) components that, to the maximum degree possible, work the same on all platforms. |
| org.omg.CORBA | Provides the mapping of the OMG CORBA APIs to the JavaTM programming language, including the class ORB, which is implemented so that a programmer can use it as a fully-functional Object Request Broker (ORB). |
The java.lang package contains all of the basic data objects we will use for writing programs.
The table below contains a list of the objects in java.lang and a short description of each.
| Class | Description |
|---|---|
| Boolean | The Boolean class wraps a value of the primitive type boolean in an object. |
| Byte | The Byte class is the standard wrapper for byte values. |
| Character | The Character class wraps a value of the primitive type char in an object. |
| Character.Subset | Instances of this class represent particular subsets of the Unicode character set. |
| Character.UnicodeBlock | A family of character subsets representing the character blocks defined by the Unicode 2.0 specification. |
| Class | Instances of the class Class represent classes and interfaces in a running Java application. |
| ClassLoader | The class ClassLoader is an abstract class. |
| Compiler | The Compiler class is provided to support Java-to-native-code compilers and related services. |
| Double | The Double class wraps a value of the primitive type double in an object. |
| Float | The Float class wraps a value of primitive type float in an object. |
| InheritableThreadLocal | This class extends ThreadLocal to provide inheritance of values from parent Thread to child Thread: when a child thread is created, the child receives initial values for all InheritableThreadLocals for which the parent has values. |
| Integer | The Integer class wraps a value of the primitive type int in an object. |
| Long | The Long class wraps a value of the primitive type long in an object. |
| Math | The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. |
| Number | The abstract class Number is the superclass of classes Byte, Double, Float, Integer, Long, and Short. |
| Object | Class Object is the root of the class hierarchy. |
| Package | Package objects contain version information about the implementation and specification of a Java package. |
| Process | The Runtime.exec methods create a native process and return an instance of a subclass of Process that can be used to control the process and obtain information about it. |
| Runtime | Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. |
| RuntimePermission | This class is for runtime permissions. |
| SecurityManager | The security manager is a class that allows applications to implement a security policy. |
| Short | The Short class is the standard wrapper for short values. |
| StrictMath | The class StrictMath contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. |
| String | The String class represents character strings. |
| StringBuffer | A string buffer implements a mutable sequence of characters. |
| System | The System class contains several useful class fields and methods. |
| Thread | A thread is a thread of execution in a program. |
| ThreadGroup | A thread group represents a set of threads. |
| ThreadLocal | This class provides ThreadLocal variables. |
| Throwable | The Throwable class is the superclass of all errors and exceptions in the Java language. |
| Void | The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void. |
The following shows a general skeleton for a Java program.
// package declaration (optional)
package sample;
// import other classes (optional)
import java.awt.*;
import java.lang.*;
// class definition
[public] [abstract|final] class SampleOne
[extends JFrame] [implements Runnable] {
// class variables, instance variables, constants
[public|private|protected] [final] [static] [primtype]
varOne [= value];
[public|private|protected] [final] [static] [primtype]
varTwo [= new String();];
[public|private|protected] [final] [static] [primtype]
varThree [= new String("abc");];
// class method definitions?
static {
...code...
}
// constructors for the current class
[public|private|protected] SampleOne(parameters)
{
...code...
}
// class and instance methods
[public|private|protected] [synchronized]
[abstract|final|static|native]
[return type] myFirstMethod(parameters)
{
...code...
return valOrVoid;
}
}
|