SlideShare a Scribd company logo
JAVA Quick Reference
Java Primitive Data Types
Arrays
Class
Methods
Variables
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Comments
Some Scanner Class Methods
Converting Strings to Numbers
Compile and Run
Flow Control
Java Statements
Program Structure
Key Words
Operator Precedence
Wrapper Classes
Access Modifiers & Their Visibility
Character Escape Sequence
Class Member Accessibility
Converting Strings to Numbers
Alphabetical list of some event listeners
Swing components: Registering methods
Selected methods that respond to events
Some JComboBox class methods
Some Java Layout Managers
Examples: User actions & event registering
Events listeners and handlers methods
MouseListener methods
Some useful MouseEvent methods
Some useful MouseEvent fields
Useful event class methods
Java Packages
Java Extension Packages
Home
Java Primitive Data Types
Type Contains Default Size bit(s) Range
boolea
n
True or false false 1 NA
char Unicode Character u0000 16 u0000 to uFFFF
byte Signed Integer 0 8 -128 to 127
short Signed Integer 0 16 -32768 to 32767
int Signed Integer 0 32 -214483648 to 2147483647
long Signed Integer 0 64 -263 to (263 – 1)
float IEEE 754 floating point 0.0 32 1.4e-45 to 3.4e+38
float IEEE 754 floating point 0.0 64 5e-324 to 1.8e+308
8 bits = 1 byte
Wrapper Classes
Primitive
Types
Reference
Types
Methods to get primitive values
boolean Boolean booleanValue()
char Character charValue()
byte Byte byteValue(), shortValue(), longValue(), floatValue(), doubleValue()
short Short byteValue(), shortValue(), longValue(), floatValue(), doubleValue()
int Integer byteValue(), shortValue(), longValue(), floatValue(), doubleValue()
long Long byteValue(), shortValue(), longValue(), floatValue(), doubleValue()
float Float byteValue(), shortValue(), longValue(), floatValue(), doubleValue()
double Double byteValue(), shortValue(), longValue(), floatValue(), doubleValue()
Class Member Accessibility
Accessible to Public Protected Default Private
Defining class Yes Yes Yes Yes
Class in same package Yes Yes Yes No
Subclass in different package Yes Yes No No
Non subclass different package Yes No No No
Home
Access Modifiers and their visibility
Modifier Visibility
package-private The default package-private limits access from within the package
private The private method is accessible from within its class
The private data member is accessible from within its class. It can be
indirectly accessed through methods (i.e., getter and setter methods)
protected The protected method is accessible from within its package, and also
from outside its package by subclasses of the class containing the
method.
The protected data member is accessible within its package and also
from outside its package by subclasses of the class containing the data
member
prefix The public modifier allows access from anywhere, even outside of the
package in which it was declared. Note that interfaces are public by
default
Arrays
int array_name[ ];
array_name = new int[100 ];
declare an integer array and allocate 100 elements of
memory.
int array_name[ ] = new int
[100];
int array_name [ ] = {1,2,3,4};
declare and allocate an integer array in one statement.
int array_name[] = new
int[10][20];
multidimensional array.
Null
For reference type (class, array).
Class
{public|final|abstract} class name
{ [class_variable_declarations]
public static void main {String[] args)
{
Statements
}
[methods]
}
this, super
Home
Methods
{public|private } [static] {type|void} name(arg, …, arg) {statements}
Variable
{public |private} [static] type name [=expression];
Arithmetic Operators
+, -, *, / Addition, subtraction, multiplication, division
%, ++, -- Modulus, increment, decrement.
Relational Operators
=, !=, >, <, Equal, not equal, greater, less,
>=, <= Greater or equal, less or equal.
Logical Operators
&, |, !, ^, ||, &&, AND, OR, NOT, XOR, short-circuit OR, AND
Bitwise Operators
&, |, ~, ^, AND, OR, NOT, XOR
>>, >>>, << Shift right, shift right zero fill, shift left.
Comments
// rest of line
/* multiline comment*/
/**documentation comment*/
Compile and Run
javac nameOfFile.java
java nameOfFile
CLASSPATH must set correctly.
(The name of the file has to match exactly the name of the
class)
Home
Character Escape Sequence
Name Sequence Decimal Unicode
Backspace b 8 u0008
Horizontal tab t 9 u0009
Line feed n 10 u000A
Form feed f 12 u000C
Carriage return r 13 u000D
Double quote ” 34 u0022
Single quote ’ 39 u0027
Backslash 
Java Statements
Statement Purpose Syntax
expression side effects var = expr; expr++; method(); new
Type();
compound group statements { statements }
empty do nothing ;
labeled name a statement label: statement
variable declare a variable [final] type name [=value] [,
name[=value]] - ;
if conditional if (expr) statement [ else statement]
switch conditional switch (expr) {[ case expr: statement] –
[ default; statements] }
while loop while (expr ) statement
do loop do statement while (expr);
for simplified loop for (init; test; increment) statement
foreach collection iteration for (variable: iterable) statement
break exit block break [ label ];
continue restart loop continue [ label ] ;
return end method return [ label ] ;
synchronized critical section synchronized ( expr ) { statements }
throw throw exception throw expr;
try handle exception try { statements } [ catch ( type name) {
statements } ] … { finally {statements}]
assert verify invariant assert invariant [ : error];
Flow Control
if (Boolean-expression) statement1; [else ststement2;]
while loop
[initialization]
while (termination-clause)
{
body;
[iteration;]
}
do while loop
do
{
body;
[iteration;]
}
while (termination-clause);
for loop
for (initialization; termination-clause; iteration)
body;
Home
Program Structure
class className
{
public static void main (String[] args)
{
statements;
}
method definition1
….
method definition
}
Key Words
abstract const float int protected throw
boolean continue for interface public throws
break default future long rest transient
byte do generic native return true
byvalue double goto new short try
case else if null static var
cast extends implements operator super void
catch false import outer switch volatile
char final inner package synchronized while
class finally instanceof private this
Home
The Operator precedence (for common Java operators)
Precedence Operator(s) Symbol(s)
Highest Logical NOT !
Intermediate Multiplication, division, modulus  / %
Addition, subtraction + -
Relational  <= <=
Equality == !=
Logical AND &&
Logical OR ||
Conditional ?:
Lowest Assignment =
Home
Some Scanner Class Methods
Method Example & Description
nextByte byte x;
Scanner keyboard = new Scanner(System.in);
System.out.print(“Enter a byte value: “);
x = keyboard.nextByte();
Description: Returns input as a byte
nextDouble double number;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a double value: ");
number = keyboard.nextDouble();
Description: Returns input as a double.
nextFloat float number;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a float value: ");
number = keyboard.nextFloat();
Description: Returns input as a float.
nextInt int number;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter an integer value: ");
number = keyboard.nextInt();
Description: Returns input as an int.
nextLine String name;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter your name: ");
name = keyboard.nextLine();
Description: Returns input as a String.
nextLong long number;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a long value: ");
number = keyboard.nextLong();
Description: Returns input as a long.
nextShort short number;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a short value: ");
number = keyboard.nextShort();
Description: Returns input as a short.
Home
Converting Strings to Numbers
Method
Byte.parseByte Convert a String to a byte byte num;
num = Byte,parseByte(str);
Double.parseDouble Convert a String to a double double num;
num = Double.parseDouble(str);
Float.parseFloat Convert a String to a float float num;
num = Float.parseFloat(str)
Integer.parseInt Convert a String to an int int num;
num = Integer.parseInt(str);
Long.parseLong Convert a String to a long long num;
num = Long.parseLong(str)
Short.parseShort Convert a String to a short short num;
num = Short.parseShort(str);
Selected methods that respond to events
Listener Method
ActionListener actionPerformed(ActionEvent)
AdjustmentListener adjustmentValueChanged(AdjustmentEvent)
FocusListener focusGained(FocusEvent) and focusLost (FocusEvent
ItemListener itemStateChanged(ItemEvent)
Alphabetical list of some event listeners
Listener Type of Events Example
ActionListener Action events Button clicks
AdjustmentListener Adjustment events Scroll bar moves
ChangeListener Change events Slider is repositioned
FocusListener Keyboard focus events Text field gains or loses focus
ItemListener Item events Check box changes status
KeyListener Keyboard events Text is entered
MouseListener Mouse events Mouse clicks
MouseMotionListener Mouse movements events Mouse rolls
WindowListener Window events Window closes
Some Swing components and their associated registering methods
Component(s) Associated Listener Registering Method(s)
JButton, JCheckBox, JComboBox,
JTextField, and JRadioButton
addActionListener()
JScrollBar addAdjustmentListener()
All Swing components addFocusListener(), addKeyListener(),
addMouseListener(), and
addMouseMotionListener()
JButton, JCheckBox, JComboBox, and
JRadioButton
addItemListener()
All JWindow and JFrame components addWindowListener()
JSlider and JCheckBox addChangeListener()
Home
Some JComboBox class methods
Method Purpose
void addItem(object) Adds an item to the list
Void removeItem(Object) Removes an item from the list
Void removeAllItems() Removes all items from the list
Object getItemAt(int) Returns the listed item at the index position specified
by the integer argument.
Int getItemCount() Returns the number of items in the list
Int getSelectedIndex() Returns the position of the currently selected item
Object getSelectedItem() Returns the currently selected item
Object[] getSelectedObjects() Returns an array containing selected Objects
Void setMaximumRowCount(int) Sets the number of rows in the combo box that can be
displayed at one time
Void setSelectedIndex(int) Sets the index at the position indicated by the
argument
Void setSelectedItem(Object) Sets the selected item in the combo box display area
to be the Object aargument.
Some Java Layout Managers
Layout Manager When to Use
BorderLayout Use when you add components to a maximum of five sections
arranged in north, south, east, west, and center positions.
FlowLayout Use when you need to add components from left to right;
FlowLayout automatically moves to the next row when needed, and
each component takes its preferred size
GridLayout Use when you need to add components into a grid of rows and
columns; each components is the same size.
CardLayout Use when you need to add components that are displayed one at a
time
BoxLayout Use when you need to add components into a single row or a single
column
GridBagLayout Use when you need to set size, placement, and alignment
constraints for every component that you add.
Home
Examples of user actions and their resulting event types
User Action Resulting Event Type
Click a button ActionEvent
Click a component MouseEvent
Click an item in a list box ItemEvent
Click an item in a check box ItemEvent
Change text in a text field TextEvent
Open a window WindowEvent
Iconify a window WindowEvent
Press a key KeyEvent
Home
Events with their related listeners and handlers
Events Listeners(s) Handler(s)
ActionEvent ActionListener actionPerformed(ActionEvent)
ItemEvent ItemListener itemStateChanged(ItemEvent)
TextEvent TextListener textValueChanged(TextEvent)
AdjustmentEvent AdjustmentListener adjustmentValueChanged
(AdjustmentEvent)
ContainerEvent ContainerListener componentAdded(CoontainerEvent)
componentRemoved(ContainerEvent)
ComponentEvent ComponentListener componentMoved(ComponentEvent)
componentHidden(ComponentEvent)
componentResized(ComponentEvent)
componentShown(ComponentEvent)
FocusEvent FocusListener focusGained(FocusEvent)
focusLost(FocusEvent)
MouseEvent MouseListener
MouseMotionListener
mousePressed(MouseEvent)
mouseReleased(MouseEvent)
mouseEntered(MouseEvent)
mouseExited(MouseEvent)
mouseClicked(MouseEvent)
mouseDragged(MouseEvent)
mouseMoved(MouseEvent)
KeyEvent KeyListener keyPressed(KeyEvent)
keyTyped(KeyEvent)
keyReleased(KeyEvent)
WindowEvent WindowListener windowActivated
windowClosing
windowClosed
windowDeiconified
windowIconified
windowOpened
MouseWheelEvent MouseWheelListener mouseWheelMoved(MouseWheelEvent)
MouseMotionListener methods
Method Description
Void mouseDragged(MouseEvent e) Invoked when a mouse button is pressed on a
component and then dragged
Void mouseMoved(MouseEvent e) Invoked when the mouse pointer has been moved
onto a component but no buttons have been pressed
Home
MouseListener methods
Method Description
void mouseClicked(MouseEvent e) Invoked when the mouse button has been
clicked
(pressed and released) on a component
void mouseEntered(MouseEvent e) Invoked when the mouse pointer enters a
component
void mouseExited(MouseEvent e) Invoked when the mouse pointer exits a
component
void mousePressed(MouseEvent e) Invoked when a mouse button has been
pressed on a component
void mouseReleased(MouseEvent e) Invoked when a mouse button has been
released on a component
Some useful MouseEvent methods
Method Description
Int getButton Returns which, if any, of the mouse buttons has changed
state; uses fields NOBUTTON, BUTTON1, BUTTON2, and
BUTTON3
Int getClickCount Returns the number of mouse clicks associated with the
current event
Int getX() Returns the horizontal x-position of the event relative to the
source component
Int getY() Returns the vertical y-position of the event relative to the
source component
Home
Some useful MouseEvent fields
Field Description
Static int BUTTON1 Indicates mouse button #1; used by getButton()
Static int BUTTON2 Indicates mouse button #2; used by getButton()
Static int BUTTON3 Indicates mouse button #3; used by getButton()
Static int NOBUTTON Indicates no mouse buttons; used by getButton()
Static int MOUSE_CLICKED The “mouse clicked” event
Static int MOUSE_DRAGGED The “mouse dragged” event
Static int MOUSE_ENTERED The “mouse entered” event
Static int MOUSE_EXITED The “mouse exited” event
Home
Useful event class methods
Class Method Purpose
EventObject Object getSource() Returns the Object involved in the
event
ComponentEvent Component getComponent() Returns the Component involved in
the event.
WindowEvent Window getWindow() Returns the window involved in the
event
ItemEvent Object getItem() Returns the Object that was selected
or deselected
ItemEvent Int get StateChange() Returns an integer named
ItemEvent . SELECTED or
ItemEvent . DESELECTED
InputEvent Int get Modifiers() Returns an integer to indicate which
mouse button was clicked
InputEvent Int get When() Returns a time indicating when the
event occurred
InputEvent Boolean isAltDown() Returns whether the Alt key was
pressed when the event occurred
InputEvent Boolean isControlDown() Returns whether the Ctrl key was
pressed when the event occurred
InputEvent Boolean isShiftDown() Returns whether the Shift key was
pressed when the event occurred
KeyEvent Int getKeyChar() Returns the Unicode character
entered from the keyboard
MouseEvent Int getClickCount() Returns the number of mouse clicks;
lets you identify the users double-
clicks
MouseEvent Int getX() Returns the x-coordinate of the
mouse pointer
MouseEvent Int getY() Returns the y-coordinate of the
mouse pointer
MouseEvent Point getPoint Returns the Point Object that
contains the x- and y- coordinates of
the mouse location
Home
Java Packages
java.applet Provides the classes necessary to create an applet and the classes
an applet uses to communicate its applet context.
java.awt Contains all of the classes for creating user interfaces and for
painting graphics and images.
java.awt.color Provides classes for color spaces
java.awt.datatransfer Provides interfaces and classes for transferring data between and
within applications
java.awt.dnd Drag and Drop is a direct manipulation gesture found in many
Graphical User Interface systems that provides a mechanism to
transfer information between two entities logically associated with
presentation elements in the GUI
java.awt.event Provides interfaces and classes for dealing with different types of
events fired by AWT components
java.awt.font Provides classes and interfaces relating to fonts.
java.awt.geom Provides the Java 2D classes for defining and performing
operations on objects related to two dimensional geometry.
java.awt.im Provides classes and interfaces for the input method framework.
java.awt.im.spi Provides interfaces that enable the development of input methods
that can be used with any Java runtime environment.
java.awt.image Provides classes for creating and modifying images.
Java.awt.image.rendera
ble
Provides classes and interfaces for producing rendering-
independent images.
java.awt.print Provides classes and interfaces for a general printing API
java.beans Contains classes related to developing beans – components based
on the JavaBeans™ architecture.
java.beans,beans.conte
xt
Provides classes and interfaces relating to beans context
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.lang.ref Provides reference-object classes, which support a limited degree
of instruction with the garbage collector
java.lang.reflect Provides classes and interfaces for obtaining reflective information
about classes and objects.
java.math Provide classes for performing arbitrary-precision integer arithmetic
(BigInteger) and arbitrary-precision decimal arithmetic (BigDecimal)
java.net Provides the classes for implementing networking applications
java.nio Defines buffers, which are containers for data, and provides an
overview of the other NIO packages
java.nio.channels Defines channels, which represent connections to entities that are
capable of performing I/O operation, such as files and sockets,
defines, selectors, for multiplexed, non-blocking I/O operations
java.nio.channels.spi Service provider classes for the java.nio.channels package
java.nio.charset Defines charsets, decoders and encoders for translating between
byte and Unicode characters
java.nio.charset.api Service provider classes for the java.nio.charset package
java.rmi Provides the RMI package
java.rmi.activation Provides support for RMI Object Activation
java.rmi.dgc Provides classes and interfaces for the RMI registry
java.rmi.registry Provides classes and interfaces for supporting the server side of
RMI
java.security Provides classes and interfaces for the security framework.
java.security.aci The classes and interfaces in the package have been superseded
by classes in the java.security package
java.security.cert Provides classes and interfaces for parsing and managing
certificates, certificate revocation lists (CRLs) and certification paths
java.security.interfaces Provides interfaces for generating RSA (Rivest, Shamir and
Adleman Asymmetric Cipher algorithm) as defined in the RSA
Laboratory Technical Note PKCS#1. And DSA (Digital Signature
Algorithm) keys as defined in NIST’s FIPS-186
java.security.spec Provides classes and interfaces for key specifications and algorithm
parameter specifications
java.sql Provides the API for accessing and processing data stored in a data
source (usual a relational database) using the Java 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).
java.util.jar Provides classes for reading and writing the JAR (Java™ Archive)
file format, which is based on the standard ZIP file format with an
optional manifest file.
java.util.logging Provides the classes and interfaces of the Java™ 2 platform’s core
logging facilities.
java.util.prefs This package allows applications to store and retrieve user and
system preference and configuration data.
java.util.reges Classes for matching character sequences against patterns
specified by regular expressions.
java.util.zip Provides classes for reading and writing the standard ZIP and GZIP
file formats.
Java Extension Packages
javax.accessibility Defines a contract between user-interface components and
an assistive technology that provides access to those
components.
javax.crypto Provides the classes and interface for cryptographic
operations.
javax.crypto.interfaces Provides interfaces for Diffie-Hellman keys as defined in
RSA Laboratories’’ PKCS #3.
javax.crypto.spec Provides classes and interfaces for key specifications and
algorithm parameter specifications.
javax.imageio The main package of the Java Image I/O API.
javax.imageio.event A package of the Java I/O API dealing with synchronous
notification of events during the reading and writing of
images.
javax.imageio.metadata A package of the Java Image I/O API dealing with reading
and writing metadata.
javax.imageio.plugins.jpeg Classes supporting the built-in JPEG plug-in.
javax.imageio.spi A package of the Java Image I/O API containing the plug-
in interfaces for readers, writers, transcoders, and streams,
and a runtime registry.
javax.imageio.stream A package of the Java Image I/O API dealing with low-level
I/O from files and streams.
javax.naming Provides the classes and interfaces for accessing naming
services.
javax.naming.directory Extends the java, naming package to provide functionality
for accessing directory services.
javax.naming.event Provides support for event notification when accessing
naming and directory services.
javax.naming.Idap Provides support for LDAPv3 extended operations and
controls.
javax.naming.spi Provides the means for dynamically plugging in support for
accessing naming and directory services through the
javax.naming and related packages.
javax.net Provides classes for networking applications.
javax.net.ssl Provides classes for the secure socket package.
javax.print Provides the principal classes and interfaces for the
JavaTM Print Service API.
javax.print.attribute Provides classes and interfaces that describe the type of
JavaTM Print Service attributes and how they can be
collected into attribute sets.
javax.print.attribute.standard Package javax.print.attribute.standard contains classes for
specific printing attributes.
java.print.event Packages javax.print.event contains event classes and
listener interfaces.
javax.rml Contains user APIs for RMI-IIOP.
javax.rmi.CORBA Contains portability APIs for RMI-IIOP.
javax.security.auth This package provides a framework for authentication and
authorization.
javax.security.authen.callback This package provides the classes necessary for services
to interact with applications I order to retrieve information
(authentication data including usernames or passwords, for
example) or to display information (error and warning
messages, for example).
javax.security.auth.kerberos This package contains utility classes related to the
Kerberos network authentication protocol.
javax.security.auth.login This package provides a pluggable authentication
framework.
javax.security.auth.spi This package provides the interface to be used for
implementing pluggable authentication modules.
javax.security.auth.x500 This package contains the classes that should be used to
store X500 Principal and X500 Private Credentials in a
Subject.
javax.security.cert Provides classes for public key certificates.
javax.sound.midi Provides interfaces and classes for I/O, sequencing, and
synthesis of MIDI (Musical Instrument Digital Interface)
data.
javax.sound.midi.spi Supplies interfaces for service providers to implement
when offering new MIDI devices, MIDI file readers and
writers, or sound bank readers.
javax.sound.sampled Provides interfaces and classes for capture, processing,
and playback of sampled audio data.
javax.sound.sampled.spi Supplies abstract classes for service providers to subclass
when offering new audio devices, sound file readers and
writers, or audio format converters.
javax.sql Provides the API for server side data source access and
processing from the JavaTM programming language.
javax.sql.swing Provides a set of “lightweight” (all-Java language)
components that, to the maximum degree possible, work
the same on all platforms
javax.swing.border Provides classes and interface for drawing specialized
borders around a Swing component.
javax.swing.colorchooser Contains classes and interfaces used by the
JColorChooser component.
javax.swing.event Provides for events fired by Swing components.
javax.swing.filechooser Contains classes and interfaces used by the JFileChooser
component.
javax.swing.plaf Provides one interface and many abstract classes that
Swing uses to provide its pluggable look-and-feel
capabilities.
javax.swing.plaf.basic Provides user interface objects built according to the Basic
look and feel
javax.swing.plaf.metal Provides user interface objects built according to the Java
look and feel (once codenamed Metal), which is the default
look and feel.
javax.swing.plaf.multi Provides user interface objects that combine two or more
look and feels.
javax.swing.table Provides classes and interfaces for dealing with
javax.swing.JTable.
javax.swing.text Provides classes and interfaces that deal with editable and
noneditable text components.
javax.swing.text.html Provides the class HTMLEditorKit and supporting classes
for creating HTML text editors.
javax.swing.text.html.parser Provides the default HTML parser, along with support
classes.
javax.swing.text.rtf Provides a class (RTFEditorKit) for creating Rich-Text-
Format text editors.
javax.swing.tree Provides classes and interfaces for dealing with
javax.swing.JTree.
javax.swing.undo Allows developers to provide support for undo/redo in
applications such as text editors.
javax.transaction Contains three exceptions thrown by the ORB machinery
during unmarshalling.
javax.transaction.xa Provides the API that defines the contract between the
transaction manager and the resource manager, which
allows the transaction manager to enlist and delist
resource objects (supplied by the resource manager driver)
in JTA transactions.
javax.xml.parsers Provides classes allowing the processing of XML
documents
javax.xml.transform This package defines the generic APIs for processing
transformation instruction, and performing a transformation
from source to result.
javax.xml.transform.dom This package implements DOM-specific transformation
APIs.
javax.xml.transform.sax This package implements SAX2-specific transformation
APIs.
javax.xml.transform.stream This package implements stream-and URI-specific
transformation APIs.
Home
All efforts have been made to ensure correct information here. Users should use it at their own discretion as no liability is hereby
implied. Please do kindly call my attention to any errors that need to be corrected or any vital and latest additions that ought to be
added to this reference. Thank you.
Christopher Akinlade, 2016
Acknowledgements
Java Programming 8th
Edition, © 2016, Joyce Farrell, Cengage Learning
Starting Out with Java 6th
Edition, © 2016 Tony Gaddis, Pearson Education, Inc.
Java in a Nutshell 6th
Edition, © 2015 Benjamin J. Evans & David Flanagan, O’Reilly Media Inc
Java 8 Pocket Guide, ©2014 Robert Liguori and Patricia Liguori, Gliesian, LLC., O’Reilly Books
Jialong He, Jialong_he@bigfoot.coms; http://www.bigfoot.com/~jialong_he
Home
Ad

More Related Content

What's hot (20)

Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
Ram132
 
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Codemotion
 
Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
manish kumar
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
Kevlin Henney
 
Generic Programming in java
Generic Programming in javaGeneric Programming in java
Generic Programming in java
Garik Kalashyan
 
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
Jérôme Rocheteau
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
Ramrao Desai
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
Ganesh Samarthyam
 
Why we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingWhy we cannot ignore Functional Programming
Why we cannot ignore Functional Programming
Mario Fusco
 
Python Workshop. LUG Maniapl
Python Workshop. LUG ManiaplPython Workshop. LUG Maniapl
Python Workshop. LUG Maniapl
Ankur Shrivastava
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
น้องน๊อต อยากเหยียบดวงจันทร์
 
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Ranel Padon
 
Java ppt
Java pptJava ppt
Java ppt
Rohan Gajre
 
Bad Smell in Codes - Part 1
Bad Smell in Codes - Part 1Bad Smell in Codes - Part 1
Bad Smell in Codes - Part 1
Shaer Hassan
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
Jussi Pohjolainen
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
Lorna Mitchell
 
Java best practices
Java best practicesJava best practices
Java best practices
Ray Toal
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
Praveen M Jigajinni
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
Julie Iskander
 
Core java concepts
Core java concepts Core java concepts
Core java concepts
javeed_mhd
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
Ram132
 
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Codemotion
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
Kevlin Henney
 
Generic Programming in java
Generic Programming in javaGeneric Programming in java
Generic Programming in java
Garik Kalashyan
 
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
Jérôme Rocheteau
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
Ramrao Desai
 
Why we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingWhy we cannot ignore Functional Programming
Why we cannot ignore Functional Programming
Mario Fusco
 
Python Workshop. LUG Maniapl
Python Workshop. LUG ManiaplPython Workshop. LUG Maniapl
Python Workshop. LUG Maniapl
Ankur Shrivastava
 
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Ranel Padon
 
Bad Smell in Codes - Part 1
Bad Smell in Codes - Part 1Bad Smell in Codes - Part 1
Bad Smell in Codes - Part 1
Shaer Hassan
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
Lorna Mitchell
 
Java best practices
Java best practicesJava best practices
Java best practices
Ray Toal
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
Julie Iskander
 
Core java concepts
Core java concepts Core java concepts
Core java concepts
javeed_mhd
 

Similar to Java q ref 2018 (20)

core java
 core java core java
core java
dssreenath
 
Core java
Core javaCore java
Core java
kasaragaddaslide
 
02basics
02basics02basics
02basics
Waheed Warraich
 
Lecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptxLecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptx
SaqlainYaqub1
 
Procedures functions structures in VB.Net
Procedures  functions  structures in VB.NetProcedures  functions  structures in VB.Net
Procedures functions structures in VB.Net
tjunicornfx
 
DOC-20240812-WA0000 array string and.pptx
DOC-20240812-WA0000 array string and.pptxDOC-20240812-WA0000 array string and.pptx
DOC-20240812-WA0000 array string and.pptx
PanjatcharamVg
 
First fare 2010 java-introduction
First fare 2010 java-introductionFirst fare 2010 java-introduction
First fare 2010 java-introduction
Oregon FIRST Robotics
 
Java 5 Features
Java 5 FeaturesJava 5 Features
Java 5 Features
sholavanalli
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2
Todor Kolev
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2
Todor Kolev
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
vekariyakashyap
 
Java Basic Elements Lecture on Computer Science
Java Basic Elements Lecture on Computer ScienceJava Basic Elements Lecture on Computer Science
Java Basic Elements Lecture on Computer Science
AnezkaJaved
 
Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
Rakesh Madugula
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptx
ssuserb1a18d
 
Ppt on java basics1
Ppt on java basics1Ppt on java basics1
Ppt on java basics1
Mavoori Soshmitha
 
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
JAVA CLASS PPT FOR ENGINEERING STUDENTS  BBBBBBBBBBBBBBBBBBBJAVA CLASS PPT FOR ENGINEERING STUDENTS  BBBBBBBBBBBBBBBBBBB
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
NagarathnaRajur2
 
VHDL lecture 2.ppt
VHDL lecture 2.pptVHDL lecture 2.ppt
VHDL lecture 2.ppt
seemasylvester
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
guest5c8bd1
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
Vijay A Raj
 
Java tut1
Java tut1Java tut1
Java tut1
Ajmal Khan
 
Lecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptxLecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptx
SaqlainYaqub1
 
Procedures functions structures in VB.Net
Procedures  functions  structures in VB.NetProcedures  functions  structures in VB.Net
Procedures functions structures in VB.Net
tjunicornfx
 
DOC-20240812-WA0000 array string and.pptx
DOC-20240812-WA0000 array string and.pptxDOC-20240812-WA0000 array string and.pptx
DOC-20240812-WA0000 array string and.pptx
PanjatcharamVg
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2
Todor Kolev
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2
Todor Kolev
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
vekariyakashyap
 
Java Basic Elements Lecture on Computer Science
Java Basic Elements Lecture on Computer ScienceJava Basic Elements Lecture on Computer Science
Java Basic Elements Lecture on Computer Science
AnezkaJaved
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptx
ssuserb1a18d
 
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
JAVA CLASS PPT FOR ENGINEERING STUDENTS  BBBBBBBBBBBBBBBBBBBJAVA CLASS PPT FOR ENGINEERING STUDENTS  BBBBBBBBBBBBBBBBBBB
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
NagarathnaRajur2
 
Ad

More from Christopher Akinlade (7)

Calculating Meter Factor for HT-400 Pumps.pdf
Calculating Meter Factor for HT-400 Pumps.pdfCalculating Meter Factor for HT-400 Pumps.pdf
Calculating Meter Factor for HT-400 Pumps.pdf
Christopher Akinlade
 
Java small steps - 2019
Java   small steps - 2019Java   small steps - 2019
Java small steps - 2019
Christopher Akinlade
 
Pragmatic Approaches to Project Costs Estimation
Pragmatic Approaches to Project Costs EstimationPragmatic Approaches to Project Costs Estimation
Pragmatic Approaches to Project Costs Estimation
Christopher Akinlade
 
Basic photography workshop
Basic photography workshopBasic photography workshop
Basic photography workshop
Christopher Akinlade
 
Now, That You're the PM What Comes Next?
Now, That You're the PM What Comes Next?Now, That You're the PM What Comes Next?
Now, That You're the PM What Comes Next?
Christopher Akinlade
 
Java quick reference v2
Java quick reference v2Java quick reference v2
Java quick reference v2
Christopher Akinlade
 
Plc basics
Plc   basicsPlc   basics
Plc basics
Christopher Akinlade
 
Ad

Recently uploaded (20)

Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Implementing promises with typescripts, step by step
Implementing promises with typescripts, step by stepImplementing promises with typescripts, step by step
Implementing promises with typescripts, step by step
Ran Wahle
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Innovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at allInnovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at all
ayeshakanwal75
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
DVDFab Crack FREE Download Latest Version 2025
DVDFab Crack FREE Download Latest Version 2025DVDFab Crack FREE Download Latest Version 2025
DVDFab Crack FREE Download Latest Version 2025
younisnoman75
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
Lionel Briand
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Microsoft Excel Core Points Training.pptx
Microsoft Excel Core Points Training.pptxMicrosoft Excel Core Points Training.pptx
Microsoft Excel Core Points Training.pptx
Mekonnen
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Top 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdfTop 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdf
AffinityCore
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Implementing promises with typescripts, step by step
Implementing promises with typescripts, step by stepImplementing promises with typescripts, step by step
Implementing promises with typescripts, step by step
Ran Wahle
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Innovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at allInnovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at all
ayeshakanwal75
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
DVDFab Crack FREE Download Latest Version 2025
DVDFab Crack FREE Download Latest Version 2025DVDFab Crack FREE Download Latest Version 2025
DVDFab Crack FREE Download Latest Version 2025
younisnoman75
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
Lionel Briand
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Microsoft Excel Core Points Training.pptx
Microsoft Excel Core Points Training.pptxMicrosoft Excel Core Points Training.pptx
Microsoft Excel Core Points Training.pptx
Mekonnen
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Top 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdfTop 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdf
AffinityCore
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 

Java q ref 2018

  • 1. JAVA Quick Reference Java Primitive Data Types Arrays Class Methods Variables Arithmetic Operators Relational Operators Logical Operators Bitwise Operators Comments Some Scanner Class Methods Converting Strings to Numbers Compile and Run Flow Control Java Statements Program Structure Key Words Operator Precedence Wrapper Classes Access Modifiers & Their Visibility Character Escape Sequence Class Member Accessibility Converting Strings to Numbers Alphabetical list of some event listeners Swing components: Registering methods Selected methods that respond to events Some JComboBox class methods Some Java Layout Managers Examples: User actions & event registering Events listeners and handlers methods MouseListener methods Some useful MouseEvent methods Some useful MouseEvent fields Useful event class methods Java Packages Java Extension Packages
  • 2. Home Java Primitive Data Types Type Contains Default Size bit(s) Range boolea n True or false false 1 NA char Unicode Character u0000 16 u0000 to uFFFF byte Signed Integer 0 8 -128 to 127 short Signed Integer 0 16 -32768 to 32767 int Signed Integer 0 32 -214483648 to 2147483647 long Signed Integer 0 64 -263 to (263 – 1) float IEEE 754 floating point 0.0 32 1.4e-45 to 3.4e+38 float IEEE 754 floating point 0.0 64 5e-324 to 1.8e+308 8 bits = 1 byte Wrapper Classes Primitive Types Reference Types Methods to get primitive values boolean Boolean booleanValue() char Character charValue() byte Byte byteValue(), shortValue(), longValue(), floatValue(), doubleValue() short Short byteValue(), shortValue(), longValue(), floatValue(), doubleValue() int Integer byteValue(), shortValue(), longValue(), floatValue(), doubleValue() long Long byteValue(), shortValue(), longValue(), floatValue(), doubleValue() float Float byteValue(), shortValue(), longValue(), floatValue(), doubleValue() double Double byteValue(), shortValue(), longValue(), floatValue(), doubleValue() Class Member Accessibility Accessible to Public Protected Default Private Defining class Yes Yes Yes Yes Class in same package Yes Yes Yes No Subclass in different package Yes Yes No No Non subclass different package Yes No No No Home
  • 3. Access Modifiers and their visibility Modifier Visibility package-private The default package-private limits access from within the package private The private method is accessible from within its class The private data member is accessible from within its class. It can be indirectly accessed through methods (i.e., getter and setter methods) protected The protected method is accessible from within its package, and also from outside its package by subclasses of the class containing the method. The protected data member is accessible within its package and also from outside its package by subclasses of the class containing the data member prefix The public modifier allows access from anywhere, even outside of the package in which it was declared. Note that interfaces are public by default Arrays int array_name[ ]; array_name = new int[100 ]; declare an integer array and allocate 100 elements of memory. int array_name[ ] = new int [100]; int array_name [ ] = {1,2,3,4}; declare and allocate an integer array in one statement. int array_name[] = new int[10][20]; multidimensional array. Null For reference type (class, array). Class {public|final|abstract} class name { [class_variable_declarations] public static void main {String[] args) { Statements } [methods] } this, super Home
  • 4. Methods {public|private } [static] {type|void} name(arg, …, arg) {statements} Variable {public |private} [static] type name [=expression]; Arithmetic Operators +, -, *, / Addition, subtraction, multiplication, division %, ++, -- Modulus, increment, decrement. Relational Operators =, !=, >, <, Equal, not equal, greater, less, >=, <= Greater or equal, less or equal. Logical Operators &, |, !, ^, ||, &&, AND, OR, NOT, XOR, short-circuit OR, AND Bitwise Operators &, |, ~, ^, AND, OR, NOT, XOR >>, >>>, << Shift right, shift right zero fill, shift left. Comments // rest of line /* multiline comment*/ /**documentation comment*/ Compile and Run javac nameOfFile.java java nameOfFile CLASSPATH must set correctly. (The name of the file has to match exactly the name of the class) Home
  • 5. Character Escape Sequence Name Sequence Decimal Unicode Backspace b 8 u0008 Horizontal tab t 9 u0009 Line feed n 10 u000A Form feed f 12 u000C Carriage return r 13 u000D Double quote ” 34 u0022 Single quote ’ 39 u0027 Backslash Java Statements Statement Purpose Syntax expression side effects var = expr; expr++; method(); new Type(); compound group statements { statements } empty do nothing ; labeled name a statement label: statement variable declare a variable [final] type name [=value] [, name[=value]] - ; if conditional if (expr) statement [ else statement] switch conditional switch (expr) {[ case expr: statement] – [ default; statements] } while loop while (expr ) statement do loop do statement while (expr); for simplified loop for (init; test; increment) statement foreach collection iteration for (variable: iterable) statement break exit block break [ label ]; continue restart loop continue [ label ] ; return end method return [ label ] ; synchronized critical section synchronized ( expr ) { statements } throw throw exception throw expr; try handle exception try { statements } [ catch ( type name) { statements } ] … { finally {statements}] assert verify invariant assert invariant [ : error];
  • 6. Flow Control if (Boolean-expression) statement1; [else ststement2;] while loop [initialization] while (termination-clause) { body; [iteration;] } do while loop do { body; [iteration;] } while (termination-clause); for loop for (initialization; termination-clause; iteration) body; Home Program Structure class className { public static void main (String[] args) { statements; } method definition1 …. method definition } Key Words abstract const float int protected throw boolean continue for interface public throws break default future long rest transient byte do generic native return true byvalue double goto new short try case else if null static var cast extends implements operator super void catch false import outer switch volatile char final inner package synchronized while class finally instanceof private this Home
  • 7. The Operator precedence (for common Java operators) Precedence Operator(s) Symbol(s) Highest Logical NOT ! Intermediate Multiplication, division, modulus  / % Addition, subtraction + - Relational  <= <= Equality == != Logical AND && Logical OR || Conditional ?: Lowest Assignment = Home Some Scanner Class Methods Method Example & Description nextByte byte x; Scanner keyboard = new Scanner(System.in); System.out.print(“Enter a byte value: “); x = keyboard.nextByte(); Description: Returns input as a byte nextDouble double number; Scanner keyboard = new Scanner(System.in); System.out.print("Enter a double value: "); number = keyboard.nextDouble(); Description: Returns input as a double. nextFloat float number; Scanner keyboard = new Scanner(System.in); System.out.print("Enter a float value: "); number = keyboard.nextFloat(); Description: Returns input as a float. nextInt int number; Scanner keyboard = new Scanner(System.in); System.out.print("Enter an integer value: "); number = keyboard.nextInt(); Description: Returns input as an int. nextLine String name; Scanner keyboard = new Scanner(System.in); System.out.print("Enter your name: "); name = keyboard.nextLine();
  • 8. Description: Returns input as a String. nextLong long number; Scanner keyboard = new Scanner(System.in); System.out.print("Enter a long value: "); number = keyboard.nextLong(); Description: Returns input as a long. nextShort short number; Scanner keyboard = new Scanner(System.in); System.out.print("Enter a short value: "); number = keyboard.nextShort(); Description: Returns input as a short. Home Converting Strings to Numbers Method Byte.parseByte Convert a String to a byte byte num; num = Byte,parseByte(str); Double.parseDouble Convert a String to a double double num; num = Double.parseDouble(str); Float.parseFloat Convert a String to a float float num; num = Float.parseFloat(str) Integer.parseInt Convert a String to an int int num; num = Integer.parseInt(str); Long.parseLong Convert a String to a long long num; num = Long.parseLong(str) Short.parseShort Convert a String to a short short num; num = Short.parseShort(str); Selected methods that respond to events Listener Method ActionListener actionPerformed(ActionEvent) AdjustmentListener adjustmentValueChanged(AdjustmentEvent) FocusListener focusGained(FocusEvent) and focusLost (FocusEvent ItemListener itemStateChanged(ItemEvent)
  • 9. Alphabetical list of some event listeners Listener Type of Events Example ActionListener Action events Button clicks AdjustmentListener Adjustment events Scroll bar moves ChangeListener Change events Slider is repositioned FocusListener Keyboard focus events Text field gains or loses focus ItemListener Item events Check box changes status KeyListener Keyboard events Text is entered MouseListener Mouse events Mouse clicks MouseMotionListener Mouse movements events Mouse rolls WindowListener Window events Window closes Some Swing components and their associated registering methods Component(s) Associated Listener Registering Method(s) JButton, JCheckBox, JComboBox, JTextField, and JRadioButton addActionListener() JScrollBar addAdjustmentListener() All Swing components addFocusListener(), addKeyListener(), addMouseListener(), and addMouseMotionListener() JButton, JCheckBox, JComboBox, and JRadioButton addItemListener() All JWindow and JFrame components addWindowListener() JSlider and JCheckBox addChangeListener() Home
  • 10. Some JComboBox class methods Method Purpose void addItem(object) Adds an item to the list Void removeItem(Object) Removes an item from the list Void removeAllItems() Removes all items from the list Object getItemAt(int) Returns the listed item at the index position specified by the integer argument. Int getItemCount() Returns the number of items in the list Int getSelectedIndex() Returns the position of the currently selected item Object getSelectedItem() Returns the currently selected item Object[] getSelectedObjects() Returns an array containing selected Objects Void setMaximumRowCount(int) Sets the number of rows in the combo box that can be displayed at one time Void setSelectedIndex(int) Sets the index at the position indicated by the argument Void setSelectedItem(Object) Sets the selected item in the combo box display area to be the Object aargument. Some Java Layout Managers Layout Manager When to Use BorderLayout Use when you add components to a maximum of five sections arranged in north, south, east, west, and center positions. FlowLayout Use when you need to add components from left to right; FlowLayout automatically moves to the next row when needed, and each component takes its preferred size GridLayout Use when you need to add components into a grid of rows and columns; each components is the same size. CardLayout Use when you need to add components that are displayed one at a time BoxLayout Use when you need to add components into a single row or a single column GridBagLayout Use when you need to set size, placement, and alignment constraints for every component that you add. Home
  • 11. Examples of user actions and their resulting event types User Action Resulting Event Type Click a button ActionEvent Click a component MouseEvent Click an item in a list box ItemEvent Click an item in a check box ItemEvent Change text in a text field TextEvent Open a window WindowEvent Iconify a window WindowEvent Press a key KeyEvent Home
  • 12. Events with their related listeners and handlers Events Listeners(s) Handler(s) ActionEvent ActionListener actionPerformed(ActionEvent) ItemEvent ItemListener itemStateChanged(ItemEvent) TextEvent TextListener textValueChanged(TextEvent) AdjustmentEvent AdjustmentListener adjustmentValueChanged (AdjustmentEvent) ContainerEvent ContainerListener componentAdded(CoontainerEvent) componentRemoved(ContainerEvent) ComponentEvent ComponentListener componentMoved(ComponentEvent) componentHidden(ComponentEvent) componentResized(ComponentEvent) componentShown(ComponentEvent) FocusEvent FocusListener focusGained(FocusEvent) focusLost(FocusEvent) MouseEvent MouseListener MouseMotionListener mousePressed(MouseEvent) mouseReleased(MouseEvent) mouseEntered(MouseEvent) mouseExited(MouseEvent) mouseClicked(MouseEvent) mouseDragged(MouseEvent) mouseMoved(MouseEvent) KeyEvent KeyListener keyPressed(KeyEvent) keyTyped(KeyEvent) keyReleased(KeyEvent) WindowEvent WindowListener windowActivated windowClosing windowClosed windowDeiconified windowIconified windowOpened MouseWheelEvent MouseWheelListener mouseWheelMoved(MouseWheelEvent) MouseMotionListener methods Method Description Void mouseDragged(MouseEvent e) Invoked when a mouse button is pressed on a component and then dragged Void mouseMoved(MouseEvent e) Invoked when the mouse pointer has been moved onto a component but no buttons have been pressed Home
  • 13. MouseListener methods Method Description void mouseClicked(MouseEvent e) Invoked when the mouse button has been clicked (pressed and released) on a component void mouseEntered(MouseEvent e) Invoked when the mouse pointer enters a component void mouseExited(MouseEvent e) Invoked when the mouse pointer exits a component void mousePressed(MouseEvent e) Invoked when a mouse button has been pressed on a component void mouseReleased(MouseEvent e) Invoked when a mouse button has been released on a component Some useful MouseEvent methods Method Description Int getButton Returns which, if any, of the mouse buttons has changed state; uses fields NOBUTTON, BUTTON1, BUTTON2, and BUTTON3 Int getClickCount Returns the number of mouse clicks associated with the current event Int getX() Returns the horizontal x-position of the event relative to the source component Int getY() Returns the vertical y-position of the event relative to the source component Home
  • 14. Some useful MouseEvent fields Field Description Static int BUTTON1 Indicates mouse button #1; used by getButton() Static int BUTTON2 Indicates mouse button #2; used by getButton() Static int BUTTON3 Indicates mouse button #3; used by getButton() Static int NOBUTTON Indicates no mouse buttons; used by getButton() Static int MOUSE_CLICKED The “mouse clicked” event Static int MOUSE_DRAGGED The “mouse dragged” event Static int MOUSE_ENTERED The “mouse entered” event Static int MOUSE_EXITED The “mouse exited” event Home
  • 15. Useful event class methods Class Method Purpose EventObject Object getSource() Returns the Object involved in the event ComponentEvent Component getComponent() Returns the Component involved in the event. WindowEvent Window getWindow() Returns the window involved in the event ItemEvent Object getItem() Returns the Object that was selected or deselected ItemEvent Int get StateChange() Returns an integer named ItemEvent . SELECTED or ItemEvent . DESELECTED InputEvent Int get Modifiers() Returns an integer to indicate which mouse button was clicked InputEvent Int get When() Returns a time indicating when the event occurred InputEvent Boolean isAltDown() Returns whether the Alt key was pressed when the event occurred InputEvent Boolean isControlDown() Returns whether the Ctrl key was pressed when the event occurred InputEvent Boolean isShiftDown() Returns whether the Shift key was pressed when the event occurred KeyEvent Int getKeyChar() Returns the Unicode character entered from the keyboard MouseEvent Int getClickCount() Returns the number of mouse clicks; lets you identify the users double- clicks MouseEvent Int getX() Returns the x-coordinate of the mouse pointer MouseEvent Int getY() Returns the y-coordinate of the mouse pointer MouseEvent Point getPoint Returns the Point Object that contains the x- and y- coordinates of the mouse location Home
  • 16. Java Packages java.applet Provides the classes necessary to create an applet and the classes an applet uses to communicate its applet context. java.awt Contains all of the classes for creating user interfaces and for painting graphics and images. java.awt.color Provides classes for color spaces java.awt.datatransfer Provides interfaces and classes for transferring data between and within applications java.awt.dnd Drag and Drop is a direct manipulation gesture found in many Graphical User Interface systems that provides a mechanism to transfer information between two entities logically associated with presentation elements in the GUI java.awt.event Provides interfaces and classes for dealing with different types of events fired by AWT components java.awt.font Provides classes and interfaces relating to fonts. java.awt.geom Provides the Java 2D classes for defining and performing operations on objects related to two dimensional geometry. java.awt.im Provides classes and interfaces for the input method framework. java.awt.im.spi Provides interfaces that enable the development of input methods that can be used with any Java runtime environment. java.awt.image Provides classes for creating and modifying images. Java.awt.image.rendera ble Provides classes and interfaces for producing rendering- independent images. java.awt.print Provides classes and interfaces for a general printing API java.beans Contains classes related to developing beans – components based on the JavaBeans™ architecture. java.beans,beans.conte xt Provides classes and interfaces relating to beans context 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.lang.ref Provides reference-object classes, which support a limited degree of instruction with the garbage collector java.lang.reflect Provides classes and interfaces for obtaining reflective information about classes and objects. java.math Provide classes for performing arbitrary-precision integer arithmetic (BigInteger) and arbitrary-precision decimal arithmetic (BigDecimal) java.net Provides the classes for implementing networking applications java.nio Defines buffers, which are containers for data, and provides an overview of the other NIO packages
  • 17. java.nio.channels Defines channels, which represent connections to entities that are capable of performing I/O operation, such as files and sockets, defines, selectors, for multiplexed, non-blocking I/O operations java.nio.channels.spi Service provider classes for the java.nio.channels package java.nio.charset Defines charsets, decoders and encoders for translating between byte and Unicode characters java.nio.charset.api Service provider classes for the java.nio.charset package java.rmi Provides the RMI package java.rmi.activation Provides support for RMI Object Activation java.rmi.dgc Provides classes and interfaces for the RMI registry java.rmi.registry Provides classes and interfaces for supporting the server side of RMI java.security Provides classes and interfaces for the security framework. java.security.aci The classes and interfaces in the package have been superseded by classes in the java.security package java.security.cert Provides classes and interfaces for parsing and managing certificates, certificate revocation lists (CRLs) and certification paths java.security.interfaces Provides interfaces for generating RSA (Rivest, Shamir and Adleman Asymmetric Cipher algorithm) as defined in the RSA Laboratory Technical Note PKCS#1. And DSA (Digital Signature Algorithm) keys as defined in NIST’s FIPS-186 java.security.spec Provides classes and interfaces for key specifications and algorithm parameter specifications java.sql Provides the API for accessing and processing data stored in a data source (usual a relational database) using the Java 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). java.util.jar Provides classes for reading and writing the JAR (Java™ Archive) file format, which is based on the standard ZIP file format with an optional manifest file. java.util.logging Provides the classes and interfaces of the Java™ 2 platform’s core logging facilities. java.util.prefs This package allows applications to store and retrieve user and system preference and configuration data. java.util.reges Classes for matching character sequences against patterns specified by regular expressions. java.util.zip Provides classes for reading and writing the standard ZIP and GZIP file formats.
  • 18. Java Extension Packages javax.accessibility Defines a contract between user-interface components and an assistive technology that provides access to those components. javax.crypto Provides the classes and interface for cryptographic operations. javax.crypto.interfaces Provides interfaces for Diffie-Hellman keys as defined in RSA Laboratories’’ PKCS #3. javax.crypto.spec Provides classes and interfaces for key specifications and algorithm parameter specifications. javax.imageio The main package of the Java Image I/O API. javax.imageio.event A package of the Java I/O API dealing with synchronous notification of events during the reading and writing of images. javax.imageio.metadata A package of the Java Image I/O API dealing with reading and writing metadata. javax.imageio.plugins.jpeg Classes supporting the built-in JPEG plug-in. javax.imageio.spi A package of the Java Image I/O API containing the plug- in interfaces for readers, writers, transcoders, and streams, and a runtime registry. javax.imageio.stream A package of the Java Image I/O API dealing with low-level I/O from files and streams. javax.naming Provides the classes and interfaces for accessing naming services. javax.naming.directory Extends the java, naming package to provide functionality for accessing directory services. javax.naming.event Provides support for event notification when accessing naming and directory services. javax.naming.Idap Provides support for LDAPv3 extended operations and controls. javax.naming.spi Provides the means for dynamically plugging in support for accessing naming and directory services through the javax.naming and related packages. javax.net Provides classes for networking applications. javax.net.ssl Provides classes for the secure socket package. javax.print Provides the principal classes and interfaces for the JavaTM Print Service API. javax.print.attribute Provides classes and interfaces that describe the type of JavaTM Print Service attributes and how they can be collected into attribute sets. javax.print.attribute.standard Package javax.print.attribute.standard contains classes for specific printing attributes.
  • 19. java.print.event Packages javax.print.event contains event classes and listener interfaces. javax.rml Contains user APIs for RMI-IIOP. javax.rmi.CORBA Contains portability APIs for RMI-IIOP. javax.security.auth This package provides a framework for authentication and authorization. javax.security.authen.callback This package provides the classes necessary for services to interact with applications I order to retrieve information (authentication data including usernames or passwords, for example) or to display information (error and warning messages, for example). javax.security.auth.kerberos This package contains utility classes related to the Kerberos network authentication protocol. javax.security.auth.login This package provides a pluggable authentication framework. javax.security.auth.spi This package provides the interface to be used for implementing pluggable authentication modules. javax.security.auth.x500 This package contains the classes that should be used to store X500 Principal and X500 Private Credentials in a Subject. javax.security.cert Provides classes for public key certificates. javax.sound.midi Provides interfaces and classes for I/O, sequencing, and synthesis of MIDI (Musical Instrument Digital Interface) data. javax.sound.midi.spi Supplies interfaces for service providers to implement when offering new MIDI devices, MIDI file readers and writers, or sound bank readers. javax.sound.sampled Provides interfaces and classes for capture, processing, and playback of sampled audio data. javax.sound.sampled.spi Supplies abstract classes for service providers to subclass when offering new audio devices, sound file readers and writers, or audio format converters. javax.sql Provides the API for server side data source access and processing from the JavaTM programming language. javax.sql.swing Provides a set of “lightweight” (all-Java language) components that, to the maximum degree possible, work the same on all platforms javax.swing.border Provides classes and interface for drawing specialized borders around a Swing component. javax.swing.colorchooser Contains classes and interfaces used by the JColorChooser component. javax.swing.event Provides for events fired by Swing components. javax.swing.filechooser Contains classes and interfaces used by the JFileChooser component.
  • 20. javax.swing.plaf Provides one interface and many abstract classes that Swing uses to provide its pluggable look-and-feel capabilities. javax.swing.plaf.basic Provides user interface objects built according to the Basic look and feel javax.swing.plaf.metal Provides user interface objects built according to the Java look and feel (once codenamed Metal), which is the default look and feel. javax.swing.plaf.multi Provides user interface objects that combine two or more look and feels. javax.swing.table Provides classes and interfaces for dealing with javax.swing.JTable. javax.swing.text Provides classes and interfaces that deal with editable and noneditable text components. javax.swing.text.html Provides the class HTMLEditorKit and supporting classes for creating HTML text editors. javax.swing.text.html.parser Provides the default HTML parser, along with support classes. javax.swing.text.rtf Provides a class (RTFEditorKit) for creating Rich-Text- Format text editors. javax.swing.tree Provides classes and interfaces for dealing with javax.swing.JTree. javax.swing.undo Allows developers to provide support for undo/redo in applications such as text editors. javax.transaction Contains three exceptions thrown by the ORB machinery during unmarshalling. javax.transaction.xa Provides the API that defines the contract between the transaction manager and the resource manager, which allows the transaction manager to enlist and delist resource objects (supplied by the resource manager driver) in JTA transactions. javax.xml.parsers Provides classes allowing the processing of XML documents javax.xml.transform This package defines the generic APIs for processing transformation instruction, and performing a transformation from source to result. javax.xml.transform.dom This package implements DOM-specific transformation APIs. javax.xml.transform.sax This package implements SAX2-specific transformation APIs. javax.xml.transform.stream This package implements stream-and URI-specific transformation APIs. Home
  • 21. All efforts have been made to ensure correct information here. Users should use it at their own discretion as no liability is hereby implied. Please do kindly call my attention to any errors that need to be corrected or any vital and latest additions that ought to be added to this reference. Thank you. Christopher Akinlade, 2016 Acknowledgements Java Programming 8th Edition, © 2016, Joyce Farrell, Cengage Learning Starting Out with Java 6th Edition, © 2016 Tony Gaddis, Pearson Education, Inc. Java in a Nutshell 6th Edition, © 2015 Benjamin J. Evans & David Flanagan, O’Reilly Media Inc Java 8 Pocket Guide, ©2014 Robert Liguori and Patricia Liguori, Gliesian, LLC., O’Reilly Books Jialong He, [email protected]; http://www.bigfoot.com/~jialong_he Home