Wednesday, October 12, 2011

Java Review: Tuesday, October 12, 2011

Java Run-time Exceptions


  • Class IllegalStateException
  • example
    • throw new IllegalStateException();
  • use to catch programming development errors.
  • exception should never occur unless there is a programming error.
  • Class RuntimeException
  • not checked
  • not extra code
  • danger of being a 'lazy programmer'
  • can use to side step catch and specify requirements
  • Runtime exceptions represent problems that are the result of programming problems
  • If the client can reasonable be expected to recover from an exception, make it a checked exception
Garbage Collection in Java VMs


  • Big memory
    • works with
      • JVMs
      • HotSpot
      • IBM JDK
      • JRockit
      • what about Dalvik?
    • off-heap store
      • not subject to Java GC
    • Terracotta's tiered cache
    • Enterprise Ehcache
    • store up to a terabyte in the off-heap
  • Android, designing from performance
  • requesting GC
    • System.gc();
  • no guarantee it will run

Java Constants and Conditional Compile


  • No textual preprocessor
  • constants and conditional compilation
  • use public static final boolean constant for  a regular if statement in regular code
  • Have class using the constant interface implement the constant interface



Tuesday, October 11, 2011

Tech Review: Monday, October 10, 2011

C# null-coalescing operator



  • From C# Reference for VS 2010
  • example
    • int? x = null;
    • int y = x ?? -1;
    • string s = null;
    • Console.WriteLine (s ?? "Unspecified");
  • used to define a default value for a nullable value type
  • it returns the left-hand operand if it is not null; otherwise it returns the right operand
  • not in Java, but some would like to add the feature
  • more about not in Java
  • coalescing mean "to grow together"
  • does this sound like a good description of what the operator is doing?

Regions in Java


I know the above picture is not about 'Regions in Java' code, but it looked nice.

  • Basically, there are no region pre-compiler directives in Java
  • There is support in some IDEs
    • NetBeans
      • // <editor-fold defaultstate="collapsed" desc="Your Fold Comment">
      • ...
      • // <editor-fold>
    • Eclipse
      • does it automatically for methods, imports, etc.
      • Not declaration like in NetBeans
      • Could you add one?
    • Emacs?
Velocity Android 2.0 Internet Table 7" $100

Velocity Micro T103 Cruz Android 2 Internet Tablet
  • almost what I want
  • missing the camera
  • Multi touch capacitive screen
Viewsonic gTablet 10.1" Android 2.2:  $270
Viewsonic gTablet 10.1" 16GB Internet Tablet
  • This is what I want except the price and Android version


Simple C# Program



  • the main routine starts with a Capital 'M' in C#
  • starts with a lower case 'm' in Java
Listeners and Events (Actions) in Java


  • lesson on writing event listeners
  • action listener
    • public class Beeper ... implements ActionListener {
  • adding an action listener to something
    • button.addActionLisener ( new Beeper() )
  • implement the method that does the action
    • public void actionPerformed (ActionEvent e) {
  • complete Beeper example
Java Color Map


  • color map in java
  • Copyright
    • Carnegie Mellon
    • Sun
    • Mitsubishi
Java List Interface and ArrayList Class



  • Class ArrayList<E>
  • Example
    • List list = Collections.synchronizedList (new ArrayList(...));
Java Collection Interface and Collections Class

  • static void sort (List list)
  • reverse (List list)
Java Queue Interface and PriorityQueue Class



  • new elements are put (enqueued) on the back of the queue
  • element are pulled (dequeued) from the front of the queue
  • First In First Out (FIFO)
  • Interface Queue<E>
  • offer (E o) // enqueue
    • adds an element to the tail of the queue
  • poll () // dequeue
    • returns a removed element from the queue
    • null is empty
  • Class PriorityQueue<E>
  • boolean add (E o)
  • boolean offer (E o)
  • E poll ()
Java Map Interface and HashMap Class

  • Interface Map<K,V>
  • V put (K key, V value)
  • V get (Object key)
  • Class HashMap<K,V>
  • Example:
    • Map m = Collections.synchronizedMap (new HashMap (...));


Chrome Remote Desktop


  • BETA
  • allow users to remotely access another computer through the Chrome browser or Chromebook
  • An add on
  • can easily miss the Icon after installation