Java notes

Developed at Sun Microsystems in 1991, first called Oak, named Java in January 1995.

The intent is that a relatively few experts design the best Classes for others to consume.

The goal of the client programmer is to collect a toolbox full of classes they can use to quickly put together an application. The goal of the class creator is to build a class that exposes only what's necessary to the client programmer, and keeps everything else hidden.

The simplest way to reuse a class is to place an object of that class inside a new class: we call this "creating a  member object." Your new class can be made up of any number and type of other objects, whatever is necessary to achieve the functionality desired in your new class. This concept is called composition, since you are composing a new class from existing classes. Sometimes composition is referred to as a "has-a" relationship, as in "a car has a trunk."

The class body follows the class declaration and is embedded within curly braces { and }.

Pure substitution - deriving the class, which has the same interface as base class.

A Circle is a Shape, but Shape is not a Circle.

You'd normally think that since it's more flexible, you'd always want to create objects on the heap rather than the stack.

Java and Smalltalk require that all objects be created on the heap, so there is no option for the optimization allowed in C++.

When you see the word "type", think "class" and vice versa.

Class Declaration components:
http://java.sun.com/docs/books/tutorial/java/javaOO/classdecl.html
Declaring Member Variables:
http://java.sun.com/docs/books/tutorial/java/javaOO/variables.html
Method Declaration:
http://java.sun.com/docs/books/tutorial/java/javaOO/methoddecl.html
Stack class example:
http://java.sun.com/docs/books/tutorial/java/javaOO/classes.html

Class - a template for multiple objects with similar features, general, abstract representation of an object. At the top of Java class hierarchy is the class Object.
Object/Instance - concrete entity;
Behavior - defined by methods, may be class & instance methods.
Method - (like functions in other lang's), may belong to class or instance, has 4 parts: return type, name, arguments/parameters, body

Sample:
returnType methodName(type1 arg1, type2 arg2, type3 arg3..)
{
    ... body ...
}

Hiding/Overriding a method - redefining a superclass method's body(functionality) with the same
 RETURN TYPE, NAME, ARGUMENTS = method signature

Attributes - defined by variables, may be class, instance & local variables.
Also could be primitive or member variable.

Instance variable: each new instance of the class gets a new copy of all instance variables defined by class.

Class variable - only one copy of variable exists:
static String surname = "Johnson";
Class variable used when an attribute has the same value for all instances of a class.

Local variable - declared and used inside method definition, stores information needed by a single method

Inheritance - a mechanism of adopting the functionality (variables & methods) of existing class. SuperClass - SubClass. Java has only single inheritance.
Interface - a class with declared but not defined/implemented methods.
For methods, an interface only allows declarations. That is, you cannot have method bodies. An interface can also contain data members of primitive types, but these are implicitly static and final.
If you forget to say that a method from the implemented interface is public, you'll get a compile-time error stating that you can't reduce the accessibility of a method during overriding.

If you know something is going to be a base class, your first choice should be to make it an interface, and only if you're forced to have method definitions or member variables should you change to an abstract class.

Ex: class Message implements myMessages { ..... }

Package - a way to group together related classes & interfaces, can be nested: java.awt.Color
Subclassing - mechanism of defining new classes as the differences between them & their SuperClasses.
Example: public class MyClass extends java.applet.Applet

public - visible to all other classes in your program, applets must be declared as public.
Statement - single Java operation. Semicolon ; is a statement delimiter.
Expression - statement returning a value.
Block - group of statement surrounded by braces: { }
UniCode - character set of 30,000+ characters, including ASCII as a subset (16 bit based)
Assigning variables: score = 200; int score = 200;

3 types of comments:   // comment   - single line;
                       /* comment */   - multiple lines;
                       /** comment */   - auto documentation

Literals: number, Boolean, character, string(automatically creates instance of class Java String)
3 categories of variables:
   eight basic primitive data types ( int i; )
   objects IDs   ( MotorVehicle mv; )
   arrays Ids    ( Car[] cars; )

Primitive   Type          Bits      Value range
types(8)
Integers    byte          8         -128 to 127
            short         16        -32,768 to 32,767
            int           32        -2,147,483,648  to 2,147,483,647
            long          64        - 9.1 * 10^18  to 9.9 * 10^18
Fltg point  float         32
            double        64

 Ind. char char 16(UniCode 65536 permutations)char c = 'A';
 Logical  boolean  true of false

Hexadecimal- base-16 numbering system ----> 0 1 2 3 4 5 6 7 8 9 A B C D E F
Operators: % - modulus(remainder); x += y  same as  x = x + y;
 
== comparison;   Vs  = assignment;
!= not equal;

Creating new object:  String teamName = new String( );
new - reserved word; a method always has parentheses which could be empty or contain arguments;
Java memory management is automatic, garbage collector looks for unused objects and reclaims the memory.

Dot notation: MyCustomer.orderTotal.layway = false;

Parameters: <APPLET code=NeonSign.class HEIGHT=200 WIDTH=100>
   <PARAM NAME=text VALUE="Welcome to Hollywood">
   <PARAM NAME=textColor VALUE="Red">
   </APPLET>

Should be enclosed in one of more general text tag: <P>, <H1>, <H2>, etc.

<APPLET CODE =myclass.class
CODEBASE ="http://www.joesserver.com/javaclasses"
WIDTH=100 HEIGHT=100></APPLET>

Parms received in an applet as follows:
String signText = getParameter("text");
String signColor = getParameter("textColor");

Calling a method - myCustomer.addOrder(item, price, quantity);
   myCustomer.cancelOrder();

Casting - a way to convert the value of an object or primitive type into another type.

Java class library consists of the following packages:
lang, util, io, net, awt, applet.
The only package automatically available in a program is java.lang, the rest must be imported.

_Arrays:
Array elements can contain primitive types or objects.
When array/object is created all elements/variables initialized as follows:
0-numerics, false-Boolean, \0-character, null-object.
To create array:
1-declare variable to hold the array;
 int[] arrABC; or int arrABC[]; or even int[] arrABC[];
2-create new array object & assign it to the variable;
 int[] arrABC = new int[10]; (shortcut to include. steps 1&2)
3-store things in array - initializing.
 arrABC[0] = 25;
[0] - subscript expression specifies the number of the first element.

String[] basketballTeams = { "Lakers", "Knicks", "Celtic", "76-ers" };
creates an array with 4 elements.

_Copy array:
System.arraycopy(ar1, start1, ar2, 0, 256);

_Ternary operator has three terms. Ex: maximum number of two

int max = a > b ? a : b
 same as
_if (myScore > yourScore) bestScore = myScore;
else bestScore = yourScore;

Ex: maximum number of four
int max = a > (b > (c > d ? c : d) ? b : (c > d ? c : d)) ? a : (b > (c > d ? c : d) ? b : (c > d ? c : d))

char grade;

switch (grade)
{
  case "A":
    // do this;
    break;
  case "B":
    // do that;
    break;
  default:
    // do something else;
    break;
}

keywords:
~break - executes first statement outside of current loop;
(could be labeled: break pointA - starts executing from next statement after point)

~continue - starts the current over at the next iteration;

loops: outer, inner, innermost, outermost.

constants: final int phone# = 3797038

Return type could be: one of the primitive types, class name, void.
If the return type is not void, last statement of a method body must be: return arg;
Overloading - creating more than one method with the same name but different argument list. The difference could be in number and type.

Thus overloading works regardless of whether the method was defined at this level or in a base class.

Often, the same word expresses a number of different meanings - it's overloaded.

Each overloaded method must take a unique list of argument types.

When you pass objects (incl. arrays) parameters to a method, the objects are passed by reference.
Primitive types are passed by value.
Class method is available to other classes, regardless of whether an instance of a class exists. (static k-word).

A Java application may consist of one or more classes. Unlike applet it needs a starting point - a starting class with main method.
 public static void main(String args[])
 {
   ... do something ...
 }

_Converting String to number:
 int i = Integer.valueOf("22").intValue();
 long l = Long.valueOf("22").longValue();
 double x = Double.valueOf("22.5").doubleValue();
 float totalPrice = Float.valueOf(args[i]).floatValue();
 int x = Integer.parseInt(args[0]).intValue();
 int x = Integer.parseInt("255").intValue(); // x = 255;

_Converting a number to a String:
 String score = String.valueOf(255); // score = "255"

To execute both the current object method and overridden method use super keyword. Ex.
void myMethod(String a, String b) {
 super.myMethod(a, b);
 // additional functionality needed
}

If you don't call super() explicitly in your constructor, Java will do it for you--using super() with no arguments.

Access control list - list of directories allowed to be used by an applet.

Five important methods of Applet class called during applet's Life Cycle:
initialization, starting, stopping, painting, destruction.

1. public void init() -  happens once, create needed objects, set up initial state, load images
   & fonts, set parameters.
2. public void start() -  can occur several times, start or re-start a thread, etc.
3. public void stop() -  when page is left, suspend a thread,
4. public void paint(Graphics g) - can occur hundreds of time during applet's LC.
5. public void destroy() - clean up before garbage collection, not normally    used.

Bounding box of the applet - dimensions.

Applet and application need to parse the parameters passed to them.

Drawing a line:
public void paint(Graphics g) {
 g.drawLine(25, 25, 75, 75);
}

Creating a new font object:
Font f = new Font("TimesRoman", Font.BOLD + Font.ITALIC, 24);

The list of fonts available on the system:  java.awt.Toolkit.getFontList();
 
Color c = new Color(140, 140, 140);

Color.white    255, 255, 255
Color.black    0,   0,   0
Color.red      255, 0,   0
Color.green    0,   255, 0
Color.blue     0,   0,   255
 
If you didn't use threads, that while would run in the default Java system thread, which is also responsible for handling painting the screen, dealing with user input like mouse clicks, and keeping everything internally up to date.
 
To use threads: boilerplate code that you can copy and paste from one applet to another.
Coding components of the threads(all generic):

public class Neko extends Applet implements Runnable
{

  Thread runner;

  /* Start */
  public void start()
  {
    if (runner == null)
    {
      runner = new Thread(this);
      runner.start();
    }
  }

  /* Stop */
  public void stop()
  {
    if (runner != null)
    {
      runner.stop();
      runner = null;
    }
  }

  /* Run */
  public void run()
  {
    doProcessing();
  }
}
 

AWT - package of classes to implement UI components.

All system events generate an instance of the Event class, which contains information about when & where event took place, the kind of event it is, and some other details.

Java has no freestanding functions like C.
All class methods are implicitly final.
Top-level class, the class used as an argument to the java interpreter, in Java application contains a main() method.

public abstract computeInterest();  - method without a definition, class containing abstract method also must be declared as abstract.

Java provides a capability to reuse code written in other languages with a facility called native methods.

Method modifiers:
Not affecting scope
final - can not be overwritten
static - class method
native - written in C and linked into the interpreter.
abstract - not defined in the class, must be defend in a subclass.
synchronized - acquires a lock on the class/instance.

Affecting scope
public - can be accessed by any class.
private - can be accessed only by methods in the same class.
protected - can be accessed in subclasses.
unspecified(not explicitly specified) - can be accessed by all methods in the same package.

Variable scope - parts of a program from which it can be accessed.
Variable extent - duration for which the variable has meaning within the program.

Java requires initialization for local variables.

Two components are involved in allocating and initializing memory in Java:
new operator - creating new instance of a class & allocating memory for it.
constructor method - named as a class, can be overloaded, if default initial values of instance variables are all that is required, an explicit constructor is not needed. All base-class constructors are always called in the constructor for a derived class.

Interface - similar to a class except the methods defined in the interface have no statements & all variables are final. The methods are defined in any class that implements the interface.

Public methods of a class make up its external interface.
Interfaces are used to approximate multiple inheritance.

Returning multiple values in Java requires returning an instance of a class.

Try/catch/finally block:

try
{
  doFileProcessing();
}
catch(Exception e)
{
  // do this if something going wrong in try block
  System.err.println("Error: " + e.getMessage());
}
finally
{
  // do this in any event
}

Passing parameters to a program

java Pgm1 parm1 parm2 parm3

public static void main(String args[]) {
 if (args.length > 0) {
 }
}

Three logic operators: && (and), ||(or), and !(not).

Java source code is composed of a number of different pieces.
The lowest level is made up of tokens:
keywords, operators, comments, identifiers, separators, white space, and literals.
The tokens are combined to make statements & expressions, which in turn are combined into blocks, methods, & classes.

"Things get mighty complicated mighty quickly."

Scientific notation  1.0 < 10.0 En; (*10) = E
Sample: 2,100,000 = 2.1E6

When doing arithmetic on unlike types, Java widens the types involved so as to avoid losing information.

Class is a user-defined data type.

If no constructor exists, Java provides a generic one.

The levels of access control from "most access" to "least access" are: ~public
~package (implicit)
~protected
~private

Every class, method, & variable implements access protection which is defined as either public, private, protected, or unspecified(package).

public variables & methods of an object can be accessed from anywhere the object can be seen.

private Vs & Ms of an O can be only accessed by objects in the same class (siblings).

protected - v & m accessed by objects in the same package or by objects in a subclass.

Unspecified v/m is accessible to anything in the same package.

Code reusability is achieved by the mechanism of inheritance.

final
class - will not be subclassed.
method - can not be overwritten in subclass.
variable - is a constant.

abstract
method - only declared here, will be implemented in subclasses, must be   part of abstract class.
class - can not be instantiated.

The difference b/w abstract class & interface:
methods of abstract class are defined/implemented in subclasses.
methods of interface are defined in the classed that implement the interface.

Java omits many rarely used, poorly understood, confusing features of C++.

Polymorphism = also called dynamic binding =? overloading.

Don't be fooled: If it isn't late binding, it isn't polymorphism.
To use polymorphism, and thus object-oriented techniques, effectively in your programs you must expand your view of programming to include not just members and messages of an individual class, but also the commonality among classes and their relationships with each other. Although this requires significant effort, it's a worthy struggle, because the results are faster program development, better code organization, extensible programs, and easier code maintenance.

An interface is like a class with nothing but abstract methods and final, static fields. All methods and fields of an interface must be public.

Random number between 1 & 6:
int num = Math.round(Math.random() *(6.0 - 1.0) + 1.0);

As long as the signatures are different two overloaded methods can return different types. Polymorphic methods in Java are distinguished only by their signatures, never by their return type.

To copy an array into another array use arraycopy method with 5 args:
System.arraycopy(Array ar1, int ar1_pos, Array ar2, int ar2_pos, int n)

Two-dimensional arrays: ar [row] [col];

Every applet must have a paint method, which is called by the Browser whenever a part of the applet's visible area is uncovered.

FontMetrics object allows to determine the width, height, and other useful characteristics of a particular String, character, or an array of characters in a particular font.

Every application in event driven environment has an event loop, which loops continuously. On every pass through the loop, the application retrieves the next event from its event queue and responds accordingly.

Three key methods are involved in painting the screen:
paint(Graphics g), repaint(), update(Graphics g).

Keyboard method - keyDown is called whenever a non-modifier key is pressed & produces an int.

There is one keyPress event & six mouse events.
mouseDown (Event e, int x, int y)
mouseUp  (Event e, int x, int y)
mouseMove (Event e, int x, int y)
mouseDrag (Event e, int x, int y)
mouseExit (Event e, int x, int y)
mouseEnter (Event e, int x, int y)

Event is a class in java.awt package. All methods(6) and variables(9) are public. Most frequently used methods are shiftDown() and controlDown();

Variables:
int id - type of event, about 27 types.Ex: KEY_PRESS, MOUSE_DOWN, etc.

The handleEvent() method is just a big switch statement that tests the ID of the event and dispatches it to the appropriate method.

Three steps in handling components:
1.  Declare
2.  Initialize
3.  Add to the layout.

Could be combined into add(new Label("Hello, I am a label");

A switch statement can only switch based on char, byte, short, or int.

Exception handling wires error handling directly into the programming language itself (and sometimes even the operating system).

An exception is an object that is "thrown" from the site of the error, and can be "caught" by an appropriate exception handler that is designed to handle that particular type of error.

Java's exception handling stands out among programming languages, because in Java exception-handling was wired in from the beginning and you're forced to use it. If you don't write your code to properly handle
exceptions, you'll get a compile-time error message.

Automatically downloading and running programs across the Internet can sound like a virus-builders dream.

There are 6 different places to store data:
1. Registers. This is the fastest of all storage because it exists in a different place than the other storage: inside the processor itself.
2. The stack. This lives in the general RAM (Random-access memory) area, but has direct support from the processor via its stack pointer. Some Java storage exists on the stack - in particular, object handles - Java objects are not placed on the stack.

3. The heap. This is a general-purpose pool of memory (also in the RAM area) where all Java objects live.

4. Static storage. "Static" is used here in the sense of "in a fixed location" (although it's also in RAM). Static
storage contains data that is available for the entire time a program is running.

5. Constant storage. Constant values are often placed directly in the program code itself, which is safe since they can never change.

6. Non-RAM storage. If data lives completely outside a program it can exist while the program is not running,
outside the control of the program.

To create an object with new, especially a small, simple variable, isn't very efficient because new places objects on the heap.

The variable holds the value itself, and it's placed on the stack so it's much more efficient.

Java 1.1 has added two classes for performing high-precision arithmetic: BigInteger and BigDecimal.

Note that you cannot do the following, even though it is legal C and C++:
{
 int x = 12;
 {
  int x = 96; /* illegal */
 }
}

When you define a class (and all you do in Java is define classes, make objects of those classes, and send messages to those objects) you can put two types of elements in your class: data members (sometimes called fields) and member functions (typically called methods).
Note carefully that the default values are what Java guarantees when the variable is used as a member of a class.
However, this guarantee doesn't apply to "local" variables - those that are not fields of a class. Here, Java definitely improves on C++: you get a compile-time error telling you the variable may not have been initialized.

Object-oriented programming is often summarized as simply "sending messages to objects."

return keyword says "leave the method".

A problem in any programming language is the control of names. If you use a name in one module of the program, and another programmer uses the same name in another module, how do you distinguish one name from another and prevent the two names from "clashing"? In C this is a particular problem because a program is often an unmanageable sea of names.

With ordinary, non-static data and methods you must create an object, and use that object, to access the data or method since non-static data and methods must know the particular object they are working with.

All of the javadoc commands occur only within /** comments. The comments end with */ as usual. There are two primary ways to use javadoc: embed HTML, or use "doc tags." Doc tags are commands that start with a '@' and are placed at the beginning of a comment line (a leading '*', however, is ignored).

narrowing conversion VS widening conversion

Java allows you to cast any primitive type to any other primitive type, except for Boolean, which doesn't allow any casting at all. Class types do not allow casting; to convert one to the other there must be special methods (String is a special case).

for(int i = 0, j = 1; i < 10 && j != 11; i++, j++){
 /* body of for loop */;
}

switch(integral-selector) {
case integral-value1 :
statement;
break;
case integral-value2 :
statement;
break;
default:
statement;

automatic compilation
The first time you create an object of an imported class, the compiler will go hunting for the .class file of the same name (so if you're creating an object of class X, it looks for X.class) in the appropriate directory. If it only finds X.class, that's what it must use. However, if it also finds an X.java in the same directory, the compiler will first compare the date stamp on the two files, and if X.java is more recent than X.class, it will automatically recompile X.java to generate an up-to-date X.class.

The Java access specifyers public, protected and private are placed in front of each definition for each member in your class, whether it's a data member or a method.

There can only be one public class per compilation unit (file).

Every non-primitive object has a toString( ) method, and it's called in special situations when the compiler wants a string but it's got one of these objects.

Java automatically inserts calls to the base-class constructor in the beginning of the derived-class constructor.

One of the advantages of inheritance is that it supports incremental development by allowing you to introduce new code without causing bugs in existing code.

When using final with object handles rather than primitives, the meaning gets a bit confusing. With a primitive, final makes the value a constant, but with an object handle, final makes the handle itself a constant. The handle must be initialized to an object at the point of declaration, and the handle can never be changed to point to another object. However, the object itself may be modified; Java does not provide a way to say that an object is constant. This includes arrays, which are also objects.

Connecting a method call to a method body is called binding.
Late(dynamic, run-time) binding, means the binding occurs at run-time, based on the type of the object.
All method binding in Java is late binding, unless a method has been declared final (which is the other reason for the existence of the final keyword).

... step through this array ...

java.lang.Throwable is a superclass of Error, Exception, RuntimeExeption.

Percolate = penetrate = filter

... until the most-derived class is reached.

When using composition to create a new class, you never worry about finalizing the member objects.

Pure inheritance =

To solve the general programming problem, you need to create any number of objects, anytime, anywhere.

Almost any statement that might conceivably fail for any reason should be wrapped in a try-catch block. For main categories are file access, array processing, users input, and network.

The exception will be caught by the first catch block that matches it or one of its superclasses.

Any operation that is going to take a noticeable period of time should be placed in its own thread.

3D rectangles
g.draw3DRect(120,20,60,60,false);

narrowing conversion and widening conversion

A primary consideration in object-oriented design is "separating
the things that change from the things that stay the same".

When you create a source-code file for Java, it's commonly called a compilation unit (sometimes a translation unit).

One of the advantages of inheritance is that it supports incremental development by allowing you to introduce new code without causing bugs in existing code.

This first call to getImage() retrieves the file at that specific URL
(http://www.server.com/ files/image.gif). If any part of that URL changes, you have to recompile your Java applet to take into account the new path:

    Image img = getImage(
    new URL("http://www.server.com/files/image.gif"));

In the following form of getImage, the image.gif file is in the same directory as the HTML files that refer to this applet:

    Image img = getImage(getDocumentBase(), "image.gif")

In this similar form, the file image.gif is in the same directory as the
applet itself:

    Image img = getImage(getCodeBase(), "image.gif")

If you have lots of image files, it's common to put them into their own
subdirectory. This form of getImage() looks for the file image.gif in the directory images, which, in turn, is in the same directory as the Java applet:

    Image img = getImage(getCodeBase(), "images/image.gif")

__two kinds of types in Java: primitive and reference
__primitive types: char byte short int long float double
__reference types: class interface array
__Variables Have Types, Objects Have Classes
__Widening Primitive Conversions

byte  to short, int, long, float, or double
short  to int, long, float, or double
char  to int, long, float, or double
int  to long, float, or double
long  to float or double
float to double

__Names (simple or qualified) are used to refer to entities declared in a Java program. A declared entity is:
  a package,
 class type,
 interface type,
 array types,
 member (field or method) of a reference type,
 parameter (to a method, constructor, or exception handler),
 local variable.

__Class Array is not instantiable

     b for a byte
     c for a char
     d for a double
     e for an Exception
     f for a float
     i, j, and k for integers
     l for a long
     o for an Object
     s for a String
     v for an arbitrary value of some type

Class variables exist once per class. Class methods operate without reference to a specific object.

_a-z (\u0061-\u007a)??????

_Access levels
       class   subcls  package  world
private  x
package(dft) x  x
protected x x x
public  x x x x

&&        Left && Right     Left and Right are both true
||        Left || Right     Either Left or Right is true
!         ! Right           Right is false

Bitwise operators:
>>          OpLeft >> Dist      Shift bits of OpLeft right by Dist bits (signed)
<<          OpLeft << Dist      Shift bits of OpLeft left by Dist bits
>>>         OpLeft >>> Dist     Shift bits of OpLeft right by Dist bits (unsigned)
&           OpLeft & OpRight    Bitwise and of the two operands
|           OpLeft | OpRight    Bitwise inclusive or of the two operands
^           OpLeft ^ OpRight    Bitwise exclusive or (xor) of the two operands
~           ~ OpRight           Bitwise complement of the right operand (unary)

_Keywords:
_Reserved word:

abstract declares that a class or method is abstract

boolean  declares a boolean variable or return type
break    prematurely exits a loop
byte     declares a byte variable or return type
case    one case in a switch statement
catch    handle an exception
char    declares a character variable or return type
class    signals the beginning of a class definition
continue prematurely return to the beginning of a loop
default   default action for a switch statement
do        begins a do while loop
double    declares a double variable or return type
else      signals the code to be executed if an if statement is not true
extends    specifies the class which this class is a subclass of
final     declares that a class may not be subclassed or that a field or method may not be overridden
finally declares a block of code guaranteed to be executed
float  declares a floating point variable or return type
for  begins a for loop
if   execute statements if the condition is true
implements declares that this class implements the given interface
import  permit access to a class or group of classes in a package
instanceof tests whether an object is an instanceof a class
int  declares an integer variable or return type
interface signals the beginning of an interface definition
long  declares a long integer variable or return type
native  declares that a method is implemented in native code
new  allocates a new object
package defines the package in which this source code file belongs
private declares a method or member variable to be private
protected declares a class, method or member variable to be protected
public  declares a class, method or member variable to be public
return  returns a value from a method
short  declares a short integer variable or return type
static  declares that a field or a method belongs to a class rather than     an object
super  a reference to the parent of the current object
switch  tests for the truth of various possible cases
synchronized indicates that a section of code is not thread-safe
this  a reference to the current object
throw  throw an exception
throws  declares the exceptions thrown by a method
transient This field should not be serialized
try  attempt an operation that may throw an exception
void  declare that a method does not return a value
volatile warns the compiler that a variable changes asynchronously
while  begins a while loop

_Bitwise operations:

AND
1 & 1 = 1
1 & 0 = 0
0 & 1 = 0
0 & 0 = 0

inclusive OR
1 | 1 = 1
1 | 0 = 1
0 | 1 = 1
0 | 0 = 0

exclusive OR
1 ^ 1 = 1
1 ^ 0 = 1
0 ^ 1 = 1
0 ^ 0 = 0

complement(unary)
~1 = 0
~0 =
 
 

_Exceptions:
Exception is an object derived, either directly, or indirectly from the class Throwable
 Error
 Exception
  RuntimeException

_exception  <bubbles up through the call stack>  until an appropriate handler is found and one of the calling methods handles the exception.

public class tryCatchFinally {
  public static void main(String[] args) {
    try {
      System.out.println("Hello " + args[0]);
    }
    catch (ArrayIndexOutOfBoundsException e) {
      System.out.println("Hello Whoever you are.");
    }
    finally {
      System.out.println("How are you?");
    }
  }
}
 

<for> loop
for (int i = 0; i < 50; i = i+1) {
      System.out.println(i);
    }

Seven kinds of <literals>
boolean: true or false
int: 89, -945, 37865
long: 89L, -945L, 5123567876L
float: 89.5f, -32.5f,
double: 89.5, -32.5, 87.6E45
char: 'c', '9', 't'
String: "This is a string literal"

_Character data type:

  \b  backspace
  \t  tab
  \n  linefeed
  \f  formfeed
  \r  carriage return
  \"  double quote, "
  \'  single quote, '
  \\  backslash, \

Unicode characters:
 \u00AE (c) The copyright symbol

_for loop:
 class Hello {
    public static void main (String args[]) {
       System.out.print("Hello ");   // Say Hello
       for (int i = 0; i < args.length; i = i + 1) { // Test and Loop
         System.out.print(args[i]);
         System.out.print(" ");
       }
       System.out.println();  // Finish the line
    }
 }

_Updating other class's variables: