Unformatted text preview:

Subscribe Now for FREE refcardz com tech facts at your fingertips CONTENTS INCLUDE n Java Keywords n Standard Java Packages n Character Escape Sequences n Collections and Common Algorithms n Regular Expressions n JAR Files Core Java By Cay S Horstmann Java Keywords continued About CORE JAVA This refcard gives you an overview of key aspects of the Java language and cheat sheets on the core library formatted output collections regular expressions logging properties as well as the most commonly used tools javac java jar Keyword Description Example finally the part of a try block that is always executed see try float the single precision floating point type float oneHalf 0 5F for a loop type for int i 10 i 0 i System out println i for String s line split s System out println s Note In the generalized for loop the expression after the must be an array or an Iterable Java Keywords Keyword Description Example abstract an abstract class or method abstract class Writable public abstract void write Writer out public void save String filename with assertions enabled throws an error if condition not fulfilled assert param null boolean the Boolean type with values true and false boolean more false break breaks out of a switch or loop while ch in next 1 if ch n break process ch www dzone com assert Note Run with ea to enable assertions the 8 bit integer type a conditional statement if input Q System exit 0 else more true implements defines the interface s that a class implements class Student implements Printable import imports a package import java util ArrayList import com dzone refcardz instanceof tests if an object is an instance of a class if fred instanceof Student value Student fred getId int the 32 bit integer type int value 0 interface an abstract type with methods that a class can implement interface Printable void print long the 64 bit long integer type long worldPopulation 6710044745L native a method implemented by the host system new allocates a new object or array Person fred new Person Fred null a null reference Person optional null package a package of classes package com dzone refcardz private a feature that is accessible only by methods of this class see class protected a feature that is accessible only by methods of this class its children and other classes in the same package class Student protected int id byte b 1 Not the same as 0xFF Note Be careful with bytes 0 case a case of a switch see switch catch the clause of a try block catching an exception see try char the Unicode character type char input Q class defines a class type class Person private String name public Person String aName name aName public void print System out println name Core Java not used if Note null instanceof T is always false Note Also see switch byte goto const not used continue continues at the end of a loop while ch in next 1 if ch continue process ch default the default clause of a switch see switch do the top of a do while loop do ch in next while ch n double the double precision floating number type double oneHalf 0 5 n else the else clause of an if statement see if enum an enumerated type enum Mood SAD HAPPY n extends defines the parent class of a class class Student extends Person private int id public Student String name int anId public void print n Get More Refcardz They re free n n n a constant or a class or method that cannot be overridden public static final int DEFAULT ID 0 DZone Inc Authoritative content Designed for developers Written by top experts Latest tools technologies Hot tips examples Bonus content online New issue every 1 2 weeks Subscribe Now for FREE Refcardz com final www dzone com 2 Core Java tech facts at your fingertips Java Keywords continued Operator Precedence Keyword Description Example public a feature that is accessible by methods of all classes see class return returns from a method int getId return id short the 16 bit integer type short skirtLength 24 static a feature that is unique to its class not to objects of its class public class WriteUtil public static void write Writable ws String filename public static final String DEFAULT EXT dat strictfp Use strict rules for floating point computations super invoke a superclass constructor or method Operators with the same precedence Notes method call Left to right unary unary cast new Right to left flips each bit of a number Left to right Be careful when using with negative numbers a b a b but a b a b For example 7 4 3 7 4 3 Left to right Left to right is arithmetic shift n 1 n 2 for positive and negative numbers is logical shift adding 0 to the highest bits The right hand side is reduced modulo 32 if the left hand side is an int or modulo 64 if the left hand side is a long For example 1 35 1 3 switch ch case Q case q more false break case break default process ch break instanceof Left to right null instanceof T Left to right Checks for identity Use equals to check for structural equality Left to right Bitwise AND no lazy evaluation with bool arguments Note If you omit a break processing continues with the next case Left to right Bitwise XOR Left to right Bitwise OR no lazy evaluation with bool arguments Left to right Left to right Right to left Right to left public Student String name int anId super name id anId public void print super print System out println id switch a selection statement a method or code block that is atomic to a thread public synchronized void addGrade String gr the implicit argument of a method or a constructor of this class public Student String id this id id public Student this throw throws an exception if param null throw new IllegalArgumentException throws the exceptions that a method can throw public void print throws PrinterException IOException transient marks data that should not be persistent class Student private transient Data cachedData try a block of code that traps exceptions try try fred print out catch PrinterException ex ex printStackTrace finally out close synchronized this grades add gr void denotes a method that returns no value public void print volatile ensures that a field is coherently accessed by multiple threads class Student private volatile int nextId a loop while in hasNext while Primitive types process in next Standard Java Packages java applet Applets Java programs that run inside a web page java awt Graphics and graphical user interfaces java beans Support for JavaBeans components classes with properties and event listeners java io Input and output java lang


View Full Document

UW CSE 142 - Study Guide

Loading Unlocking...
Login

Join to view Study Guide and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Guide and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?