Arrays

Creating Arrays

There are three steps to creating an array, declaring it, allocating it and initializing it.

Declaring Arrays

Like other variables in Java, an array must have a specific type like byte, int, String or double. Only variables of the appropriate type can be stored in an array. You cannot have an array that will store both ints and Strings, for instance.

Like all other variables in Java an array must be declared. When you declare an array variable you suffix the type with [] to indicate that this variable is an array. Here are some examples:

int[] k;
float[] yt;
String[] names;

In other words you declare an array like you’d declare any other variable except you append brackets to the end of the variable type.

Allocating Arrays

Declaring an array merely says what it is. It does not create the array. To actually create the array (or any other object) use the new operator. When we create an array we need to tell the compiler how many elements will be stored in it. Here’s how we’d create the variables declared above: new

k = new int[3];
yt = new float[7];
names = new String[50];

The numbers in the brackets specify the dimension of the array; i.e. how many slots it has to hold values. With the dimensions above k can hold three ints, yt can hold seven floats and names can hold fifty Strings. 

Initializing Arrays

Individual elements of the array are referenced by the array name and by an integer which represents their position in the array. The numbers we use to identify them are called subscripts or indexes into the array. Subscripts are consecutive integers beginning with 0. Thus the array k above has elements k[0], k[1], and k[2]. Since we started counting at zero there is no k[3], and trying to access it will generate an ArrayIndexOutOfBoundsException. subscripts indexes k k[0] k[1] k[2] k[3] ArrayIndexOutOfBoundsException

You can use array elements wherever you’d use a similarly typed variable that wasn’t part of an array.

Here’s how we’d store values in the arrays we’ve been working with:

k[0] = 2;
k[1] = 5;
k[2] = -2;
yt[6] = 7.5f;
names[4] = "Fred";

This step is called initializing the array or, more precisely, initializing the elements of the array. Sometimes the phrase “initializing the array” would be reserved for when we initialize all the elements of the array.

For even medium sized arrays, it’s unwieldy to specify each element individually. It is often helpful to use for loops to initialize the array. For instance here is a loop that fills an array with the squares of the numbers from 0 to 100.

float[] squares = new float[101];

for (int i=0; i <= 500; i++) {
  squares[i] = i*2;
}

Shortcuts

We can declare and allocate an array at the same time like this:

int[] k = new int[3];
float[] yt = new float[7];
String[] names = new String[50];

We can even declare, allocate, and initialize an array at the same time providing a list of the initial values inside brackets like so:

int[] k = {1, 2, 3};
float[] yt = {0.0f, 1.2f, 3.4f, -9.87f, 65.4f, 0.0f, 567.9f};

Two Dimensional Arrays

Declaring, Allocating and Initializing Two Dimensional Arrays

Two dimensional arrays are declared, allocated and initialized much like one dimensional arrays. However we have to specify two dimensions rather than one, and we typically use two nested for loops to fill the array. for

The array examples above are filled with the sum of their row and column indices. Here’s some code that would create and fill such an array:

class FillArray {

  public static void main (String args[]) {
  
    int[][] M;
    M = new int[4][5];
  
    for (int row=0; row < 4; row++) {
      for (int col=0; col < 5; col++) {
        M[row][col] = row+col;
      }
    }
    
  }
  
}

In two-dimensional arrays ArrayIndexOutOfBounds errors occur whenever you exceed the maximum column index or row index. Unlike two-dimensional C arrays, two-dimensional Java arrays are not just one-dimensional arrays indexed in a funny way.

Multidimensional Arrays

You don’t have to stop with two dimensional arrays. Java lets you have arrays of three, four or more dimensions. However chances are pretty good that if you need more than three dimensions in an array, you’re probably using the wrong data structure. Even three dimensional arrays are exceptionally rare outside of scientific and engineering applications.

The syntax for three dimensional arrays is a direct extension of that for two-dimensional arrays. Here’s a program that declares, allocates and initializes a three-dimensional array:

class Fill3DArray {

  public static void main (String args[]) {
  
    int[][][] M;
    M = new int[4][5][3];
  
    for (int row=0; row < 4; row++) {
      for (int col=0; col < 5; col++) {
        for (int ver=0; ver < 3; ver++) {
          M[row][col][ver] = row+col+ver;
        }
      }
    }
    
  }
  
}

Example 1 : declaring and initializing 1-dimensional arrays

An array groups elements of the same type. It makes it easy to manipulate the information contained in them.

class Arrays1{ 

public static void main(String args[]){

// this declares an array named x with the type “array of int” and of 
// size 10, meaning 10 elements, x[0], x[1] , … , x[9] ; the first term
// is x[0] and the last term x[9] NOT x[10].
int x[] = new int[10];

// print out the values of x[i] and they are all equal to 0.
for(int i=0; i<=9; i++)
System.out.println(“x[“+i+”] = “+x[i]);

// assign values to x[i] 
for(int i=0; i<=9; i++)
x[i] = i; // for example

// print the assigned values of x[i] : 1,2,……,9
for(int i=0; i<=9; i++)
System.out.println(“x[“+i+”] = “+x[i]);

// this declares an array named st the type “array of String”
// and initializes it
String st[]={“first”,”second”,”third”};

// print out st[i]
for(int i=0; i<=2; i++)
System.out.println(“st[“+i+”] = “+st[i]);

}
}

Example 2 : Find the sum of the numbers 2.5, 4.5, 8.9, 5.0 and 8.9

class Arrays2{ 

public static void main(String args[]){

// this declares an array named fl with the type “array of int” and
// initialize its elements

float fl[] = {2.5f, 4.5f, 8.9f, 5.0f, 8.9f};

// find the sum by adding all elements of the array fl
float sum = 0.0f;
for(int i=0; i<= 4; i++)
sum = sum + fl[i];

// displays the sum
System.out.println(“sum = “+sum);
}
}

Check that the sum displayed is 29.8.

Example 3 : declaring and initializing 2-dimensional arrays

class Arrays3{ 

public static void main(String args[]){

// this declares a 2-dimensional array named x[i][j] of size 4 (4 elements)
// its elements are x[0][0], x[0][1], x[1][0] and x[1][1].
// the first index i indicates the row and the second index indicates the
// column if you think of this array as a matrix.

int x[][] = new int[2][2];

// print out the values of x[i][j] and they are all equal to 0.0.
for(int i=0; i<=1; i++)
for(int j=0; j<=1; j++)
System.out.println(“x[“+i+”,”+j+”] = “+x[i][j]);

// assign values to x[i] 
for(int i=0; i<=1; i++)
for(int j=0; j<=1; j++)
x[i][j] = i+j; // for example

// print the assigned values to x[i][j] 
for(int i=0; i<=1; i++)
for(int j=0; j<=1; j++)
System.out.println(“x[“+i+”,”+j+”] = “+x[i][j]);

// this declares a 2-dimensional array of type String
// and initializes it
String st[][]={{“row 0 column 0″,”row 0 column 1”}, // first row 
{“row 1 column 0″,”row 1 column 1”}}; // second row 

// print out st[i]
for(int i=0; i<=1; i++)
for(int j=0; j<=1; j++)
System.out.println(“st[“+i+”,”+j+”] = “+st[i][j]);

}
}

 

// This is the Hello program in Java
class Hello {

    public static void main (String args[]) {
    
      /* Now let's say hello */
      System.out.print("Hello ");
      System.out.println(args[0]);
  }

}

If you run the program without giving it any command line arguments, then the  runtime system generates an exception something like,

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException at Hello.main(C:\javahtml\Hello.java:7)

Since we didn’t give Hello any command line arguments there wasn’t anything in args[0]. Therefore Java kicked back this not too friendly error message about an “ArrayIndexOutOfBoundsException.”

we can fix this problem by testing the length of the array before we try to access its first element (using array.length). This works well in this simple case, but this is far from the only such potential problem. 

What is an Exception ?

Let us see what happens when an exception occurs and is not handled properly

When you compile and run the following program

public class Test{ 
    public static void main(String str[]){
    int y = 0;
    int x = 1;
    // a division by 0 occurs here.
    int z = x/y;
    System.out.println(“after didvision”);
  }
}

The execution of the Test stops and this is caused by the division by zero at – x/y – an exception has been thrown but has not been handled properly.

How to handle an Exception ?

To handle an Exception, enclose the code that is likely to throw an exception in a try block and follow it immediately by a catch clause as follows

public class Test{ 
    public static void main(String str[]){
        int y = 0;
        int x = 1;
        // try block to “SEE” if an exception occurs
        try{
          int z = x/y;
          System.out.println(“after didvision”);
           // catch clause below handles the 
          // ArithmeticException generated by 
          // the division by zero.
       } catch (ArithmeticException ae) 
       {System.out.println(” attempt to divide by 0″);}
       System.out.println(” after catch “);
   } 
}

The output of the above program is as follows

attempt to divide by 0 
after catch

the statement – System.out.println(“after didvision”) – is NOT executed, once an exception is thrown, the program control moves out of the try block into the catch block.

The goal of exception handling is to be able to define the regular flow of the program in part of the code without worrying about all the special cases. Then, in a separate block of code, you cover the exceptional cases. This produces more legible code since you don’t need to interrupt the flow of the algorithm to check and respond to every possible strange condition. The runtime environment is responsible for moving from the regular program flow to the exception handlers when an exceptional condition arises.

In practice what you do is write blocks of code that may generate exceptions inside try-catch blocks. You try the statements that generate the exceptions. Within your try block you are free to act as if nothing has or can go wrong. Then, within one or more catch blocks, you write the program logic that deals with all the special cases.

To start a section of code which might fail or not follow through you start a try clause:

try
{
  // Section of code which might fail
}

The try statement is needed in case of an exception. If the read fails in some way it will throw an exception of type java.io.IOException. That exception must be caught in this method, or the method can declare that it will continue throwing that message. Exception handling is a very powerful tool, you can use it to catch and throw exceptions and thus group all your error handling code very well and make it much more readable in larger more complex applications. After the try section there must exist one or more catch statements to catch some or all of the exceptions that can happen within the try block. Exceptions that are not caught will be passed up to the next level, such as the function that called the one which threw the exception, and so on. .

try
{
  // Section of code which might fail
}
catch (Exception1ThatCanHappen E)
{
  // things to do if this exception was thrown..
}
catch (Exception2ThatCanHappen E)
{
  // things to do if this exception was thrown..
}

Here’s an example of exception handling in Java using the Hello World program above:

Source Code

// This is the Hello program in Java
class ExceptionalHello {

    public static void main (String args[]) {
    
      /* Now let's say hello */
      try {
        System.out.println("Hello " + args[0]);
      }
      catch (Exception e) {
        System.out.println("Hello whoever you are");      
      }
  }

}

You may or may not print an error message. If you write an exception handler and you don’t expect it to be called, then by all means put a

System.out.println("Error: " + e);

This has the folowing advantages over handling your errors internally:

  • You can react to an error in custom defined way. A read error does not mean that the program should crash.
  • You can write code with no worry about failure which will be handled by the users of your class.
  • You can group your error handling code much better.
  • You can make your application more transactional focused with nested try catch blocks:

A simple Java code which demonstrates the exception handling in Java

Refer to the java API document to see all exception types that can be handled in Java.

Source Code

public class excep2
{
	public static void main(String args[])
	{
		int i =0 ;
		//Declare an array of strings
		String Box [] = {"Book", "Pen", "Pencil"};
		while(i<4)
		{
			try
			{
				System.out.println(Box[i]);
				
			}
			catch(ArrayIndexOutOfBoundsException e)
			{
				System.out.println("Subscript Problem " + e);
			i++;
			}
			finally
			{
				System.out.println("This is always printed.");
			}
			i++;
		}
	}
}

Advertisements

NetBeans Shortcut Keys

 

Key Function
?? Ctrl-Shift-L Show popup list of all currently applicable shortcut keys and key sequences.

Hit Ctrl-Shift-L again to see a dialog with the list of all defined keys/sequences and the contexts in which they apply, and to define new keys/sequences.  This list is very long, so sort by the Binding column if you are trying to look up a particular key.

Click Highlight all occurrences of identifier in file
Ctrl-Click Go to declaration of object at cursor (variable, class, etc.)
Cmd-B Go to declaration of object at cursor (variable, class, etc.)
Cmd-Shift-B Go to source code that implements object at cursor (variable, class, etc.)
?? F4 Go to type at cursor in class hierarchy window
Cmd-O Selection dialog for types (classes, etc.), where you can type the beginning of the short name (w/o packages) and quickly go to the right source file.  Wildcards * (any sequence of chars) and ? (any single char) are supported.

Nested tip: In this dialog box, you can type just the capitalized letters of your class name if you prefer.  For example, I can type FTI to get to my FileTreeIterator class.
?? Ctrl-F3 Selection dialog for members of the current class (methods, variables, etc.), where you can type the beginning of the name and quickly go to the right place in the source file.  Wildcards * (any sequence of chars) and ? (any single char) are supported.
Thanks to Ken Smith for showing me this one!
Ctrl-Shift-O Selection dialog for files (Java source files, config files, property files, etc.), where you can type the beginning of the short file name (w/o folder names) and quickly go to the right source file.  Wildcards * (any sequence of chars) and ? (any single char) are supported.

Nested tip: In this dialog box, you can type just the capitalized letters of resource name if you prefer.  For example, I can type CBW to get to my CloseBrowserWindow.jsp file.
?? Ctrl-Shift-H Selection dialog to show a type in the class hierarchy window.  Like Ctrl-Shift-T, but shows class hierarchy instead of Java source.  Wildcards * (any sequence of chars) and ? (any single char) are supported.

Nested tip: In this dialog box, you can type just the capitalized letters of your class name if you prefer.  For example, I can type FTI to get to my FileTreeIterator class.
?? Ctrl-T Show Quick Class Hierarchy
DblClick a tab Maximize/restore view/editor in that tab (toggle)
Shift-Esc Maximize/restore current view/editor (toggle)
Ctrl-Space
Content Assist and Javadocs

  • Code completion, name completion, etc.
  • Does lots of useful completions in different contexts.  Try it!
  • When the cursor is among the methods of a class declaration, this pops up a list of parent methods that can be overridden, getters/setters that can be generated, etc.
  • After an open paren of a method call, this pops up the parameter list.
  • When on an unrecognized class name, this suggests import statements to add, based on the available classes and JAR files.
  • Shows Javadocs also in a 2nd window.
Cmd-\
?? Ctrl-Shift-Space Parameter Hints
?? Ctrl-1 Quick Fix (after finding compiler error, easy way to add imports, correct spelling errors, etc.)
?? Ctrl-2 Quick Assist (fast renaming, etc.)
?? Ctrl-3 Quick Access (fast way to find an editor command)
Cmd-I Quick Search (fast way to find an editor command, Java package, etc.)
Cmd-Z Undo
Cmd-Shift-Y Redo
Cmd-Y
?? Alt-Shift-Z Undo refactoring operation
?? Alt-Shift-Y Redo refactoring operation
?? Ctrl-O Show current context (method, class, package, etc.), and allow quick navigation to other methods, members, inherited methods, etc.
Cmd-F12 Show members of class and allow quick navigation to other methods, members, inherited methods, etc.
?? Ctrl-G Show context of identifier at cursor (method, class, package, etc.)
?? Alt-Left Go back (through recent editing locations)
?? Cmd-[
?? Opt-Cmd-Left
?? Alt-Right Go forward (through recent editing locations)
?? Cmd-]
?? Opt-Cmd-Right
Ctrl-Q Go to most recently edited location
Ctrl-F4 Close editor window
Cmd-W
?? Ctrl-PageDn Go to next editor window in current tab set
?? Ctrl-Fn-Down
?? Ctrl-PageUp Go to previous editor window in current tab set
?? Ctrl-Fn-Up
?? Ctrl-E Switch to another editor in current tab set.  Can type a name here.
?? Ctrl-F6 Go to next editor (shows list and toggles between 2 most recent)
?? Ctrl-F7 Go to next view (shows list and toggles between 2 most recent)
?? Ctrl-F8 Go to next perspective (shows list and toggles between 2 most recent)
Cmd-Shift-1 Go to current source file in Projects tree
Cmd-Shift-2 Go to current source file in Files tree
Cmd-Shift-M Toggle Bookmark
Cmd-Shift-Period Go to next bookmark
Cmd-Shift-Comma Go to previous bookmark
Cmd-[ Go to matching bracket
?? Ctrl-Shift-Down
Go to next object (method, variable, class, etc.) in source file.
?? Ctrl-Opt-Down
?? Ctrl-Shift-Up
Go to previous object (method, variable, class, etc.) in source file.
?? Ctrl-Opt-Up
Ctrl-G Go to line number
Cmd-F Search within a file
Cmd-R Search and replace within a file
Ctrl-H
Ctrl-Opt-G Search for word at cursor
Cmd-G Search Next within a file
Cmd-Shift-G Search Previous within a file
Ctrl-F7 Find all usages in file, package, project, all projects, etc.
Cmd-Shift-F Find all occurrences in files, project, open projects, etc.
Cmd-Shift-H Find and replace all occurrences in files, project, open projects, etc.
?? Ctrl-H Search in project, workspace, file system, etc.
Also offers Java-sensitive searches, limiting matches to:

  • Declarations of objects
  • References to objects
  • Implementors of interfaces
  • Reads of variables
  • Writes of variables
?? Ctrl-J Incremental Search forward
?? Ctrl-Shift-J Incremental Search back
?? Ctrl-Period Search Next, also Next Error, Next Diff (only in the views for search, problems, compare, etc.)
?? Ctrl-Comma Search Previous, also Previous Error, Previous Diff (only in the views for search, problems, compare, etc.)
?? Ctrl-Shift-U When an identifier is selected: Find all occurrences of identifier in the file (showing them in Search pane)
When a class or interface name that follows one of the keyword “extends” or “implements” is selected: Find all methods in the file that implement methods defined in the class or interface (showing them in Search pane)
?? Ctrl-Alt-G Find all occurrences of selected text in workspace (showing them in Search pane)
?? Ctrl-Shift-G Find all references to selected identifier in workspace (showing them in Search pane)
?? Ctrl-Alt-H Show call hierarchy
Cmd-Slash Toggle Comment
Tab Indent
Shift-Tab Undent
F6 Run (may have to click on project name first)
Cmd-Shift-F6 Debug (may have to click on project name first)
F7 Step Into
F8 Step Over
Cmd-F7 Step Out
F5 Resume
Ctrl-Up/Down Move up/down the call stack
?? Alt-Shift-W Show in another view (chosen from popup)
?? Alt-Shift-Arrows Expand/contract selection syntactically (variable ==> expression ==> statement ==> block ==> method ==> class ==> file)
Ctrl-R Rename item (method, field, variable, parameter, type, compilation unit, package, source folder, project)
Cmd-U, U To upper case
Cmd-U, L To lower case
Cmd-U, S Toggle case
Cmd-Shift-U Create JUnit Test
Cmd-Shift-T Goto JUnit Test
Ctrl-F6 Run JUnit Test
Cmd-F6

Hotmail Keyboard Shortcuts

To do this Press this
Delete a message Delete
Create a new message Ctrl+N
Send a message Ctrl+Enter
Open a message Ctrl+Shift+O
Print a message Ctrl+Shift+P
Reply to a message Ctrl+R
Reply all to a message Ctrl+Shift+R
Forward a message Ctrl+Shift+F
Save a draft message Ctrl+S
Flag a message for follow up L
Mark a message as junk Ctrl+Shift+J
Mark a message as read Ctrl+Q
Mark a message as unread Ctrl+U
Move to a folder Ctrl+Shift+V
Open the next message Ctrl+.
Open the previous message Ctrl+,
Close a message Esc
Search your email messages /
Check spelling F7
Select all S then A
Deselect all S then N
Go to the inbox F then I
Go to your Drafts folder F then D
Go to your Sent folder F then S

Yahoo mail Keyboard Shortcuts

  List of shortcut keys
Shortcut Command How useful(?)
Shortcut Command +       –
m Check Mail +       –
Shft+m Check All Mail (includes all POP accounts) +       –
Ctrl+\ Close Current Tab +       –
n New Message +       –
Shft+n New Message in its own window +       –
r Reply +       –
Shft+r Reply in a new window +       –
a Reply All +       –
Shft+a Reply All in a new window +       –
f Forward message +       –
Shft+f Forward in a new window +       –
k Mark As Read +       –
Shft+k Mark As Unread +       –
l (that’s an L, not a one) Flag +       –
Shft+l (that’s an L, not a one) Clear Flag +       –
Your “delete” key Delete Item +       –
Ctrl+p – or just p ! Print +       –
Ctrl+s Save Draft +       –
 

Ctrl+Enter (Alt+s also supported) Send Message +       –
v Turn Reading Pane on and off +       –
Ctrl+[ Navigate through tabs-right to left motion +       –
Ctrl+] Navigate through tabs-left to right motion +       –
Enter (select a message first, or more than one) Open message in its own tab +       –
Enter (select a contact first, in Contacts) Edit contact info +       –
Ctrl+f Find a word or phrase in a message +       –
F11 Expand window to maximum height +       –
Ctrl+. (that’s Ctrl with the period) Next message (in message tab) +       –
Ctrl+, (Ctrl with the comma) Previous message (in message tab) +       –
To set this up, press: Ctrl+Alt+Shft+up arrow. Click the optn you want, then OK. Now: To use the Next (or previous) message with same Subject; Next (or previous) flagged message; Next (or previous) unread message; Next (or previous) from: _________ +       –
Ctrl+Shft+End Skip to oldest unread message +       –
d Move message to a folder +       –
Esc Close read-message tab +       –
Ctrl+Shft+c or c Start a new chat +       –

Gmail Keyboard shortcuts

Shortcut Key Definition Action
c Compose Allows you to compose a new message. <Shift> + c allows you to compose a message in a new window.
/ Search Puts your cursor in the search box.
k Move to newer conversation Opens or moves your cursor to a more recent conversation. You can hit <Enter> to expand a conversation.
j Move to older conversation Opens or moves your cursor to the next oldest conversation. You can hit <Enter> to expand a conversation.
n Next message Moves your cursor to the next message. You can hit <Enter> to expand or collapse a message. (Only applicable in ‘Conversation View.’)
p Previous message Moves your cursor to the previous message. You can hit <Enter> to expand or collapse a message. (Only applicable in ‘Conversation View.’)
o or <Enter> Open Opens your conversation. Also expands or collapses a message if you are in ‘Conversation View.’
u Return to conversation list Refreshes your page and returns you to the inbox, or list of conversations.
e Archive Archive your conversation from any view.
m Mute Archives the conversation, and all future messages skip the Inbox unless sent or cc’d directly to you. Learn more.
x Select conversation Automatically checks and selects a conversation so that you can archive, apply a label, or choose an action from the drop-down menu to apply to that conversation.
s Star a message or conversation Adds or removes a star to a message or conversation. Stars allow you to give a message or conversation a special status.
+ Mark as important Helps Gmail learn what’s important to you by marking misclassified messages. (Specific to Priority Inbox)
Mark as unimportant Helps Gmail learn what’s not important to you by marking misclassified messages. (Specific to Priority Inbox)
! Report spam Marks a message as spam and removes it from your conversation list.
r Reply Replies to the message sender. <Shift> + r allows you to reply to a message in a new window. (Only applicable in ‘Conversation View.’)
a Reply all Replies to all message recipients. <Shift> +a allows you to reply to all message recipients in a new window. (Only applicable in ‘Conversation View.’)
f Forward Forwards a message. <Shift> + f allows you to forward a message in a new window. (Only applicable in ‘Conversation View.’)
<Esc> Escape from input field Removes the cursor from your current input field.
<Ctrl> + s Save draft Saves the current text as a draft when composing a message. Hold the <Ctrl> key while pressing s and make sure your cursor is in one of the text fields — either the composition pane, or any of the To, CC, BCC, or Subject fields — when using this shortcut.
# Delete Moves the conversation to Trash.
l Label Opens the Labels menu to label a conversation.
v Move to Moves the conversation from the inbox to a different label, Spam or Trash.
<Shift> + i Mark as read Marks your message as ‘read’ and skip to the next message.
<Shift> + u Mark as unread Marks your message as ‘unread’ so you can go back to it later.
[ Archive and previous Removes the current view’s label from your conversation and moves to the previous one.
] Archive and next Removes the current view’s label from your conversation and moves to the next one.
z Undo Undoes your previous action, if possible (works for actions with an ‘undo’ link).
<Shift> + n Update current conversation Updates your current conversation when there are new messages.
q Move cursor to chat search Moves your cursor directly to the chat search box.
y Remove from Current View* Automatically removes the message or conversation from your current view.

  • From ‘Inbox,’ ‘y’ means Archive
  • From ‘Starred,’ ‘y’ means Unstar
  • From ‘Trash,’ ‘y’ means Move to inbox
  • From any label, ‘y’ means Remove the label

* ‘y’ has no effect if you’re in ‘Spam,’ ‘Sent,’ or ‘All Mail.’

. Show more actions Displays the ‘More Actions’ drop-down menu.
<Ctrl> + <Down arrow> Opens options in Chat
  • <Ctrl> + <Down arrow> moves from edit field in your chat window to select the ‘Video and more’ menu
  • Next, press <Tab> to select the emoticon menu
  • Press <Enter> to open the selected menu
? Show keyboard shortcuts help Displays the keyboard shortcuts help menu within any page you’re on. (Note: Typing ? will display the help menu even if you don’t have keyboard shortcuts enabled)
k Move up a contact Moves your cursor up in your contact list
j Move down a contact Moves your cursor down in your contact list
o or <Enter> Open Opens the contact with the cursor next to it.
u Return to contact list view Refreshes your page and returns you to the contact list.
e Remove from Current Group Removes selected contacts from the group currently being displayed.
x Select contact Checks and selects a contact so that you can change group membership or choose an action from the drop-down menu to apply to the contact.
<Esc> Escape from input field Removes the cursor from the current input
# Delete Deletes a contact permanently
l Group membership Opens the groups button to group contacts
z Undo Reverses your previous action, if possible (works for actions with an ‘undo’ link)
. Show more actions Opens the “More actions” drop-down menu.

Combo-keys – Use the following combinations of keys to navigate through Gmail.

Shortcut Key Definition Action
<Tab> then <Enter> Send message After composing your message, use this combination to send it automatically. (Supported in Internet Explorer and Firefox, on Windows.)
y then o Archive and next Archives your conversation and moves to the next one.
g then a Go to ‘All Mail’ Takes you to ‘All Mail,’ the storage site for all mail you’ve ever sent or received (and have not deleted).
g then s Go to ‘Starred’ Takes you to all conversations you have starred.
g then c Go to ‘Contacts’ Takes you to your Contacts list.
g then d Go to ‘Drafts’ Takes you to all drafts you have saved.
g then l Go to ‘Label’ Takes you to the search box with the “label:” operator filled in for you.
g then i Go to ‘Inbox’ Returns you to the inbox.
g then t Go to ‘Sent Mail’ Takes you to all mail you’ve sent.
* then a Select all Selects all mail.
* then n Select none Deselects all mail.
* then r Select read Selects all mail you’ve read.
* then u Select unread Selects all unread mail.
* then s Select starred Selects all starred mail.
* then t Select unstarred Selects all unstarred mail.
Aside

In Java there are total 8 data types available which are further divided into 4 groups viz. integers, floating point numbers, character & boolean values.

Type

Size in Bytes (Bits)

Range

Default value

Contains

Integers
Byte 1 byte (8 bits) -128 to 127 0 Signed Integer
Short 2 bytes(16 bits) -32768 to 32767 0 Signed Integer
Int 4 bytes(32 bits) -2147483648 to 2147483647 0 Signed Integer
Long 8 bytes(64 bits) -9223372036854775808 to 9223372036854775807 0 Signed Integer
Floating point numbers
Float 4 bytes(32 bits) -3.4e38 to 3.4e38(i.e. 3.4*1017) 0.0 IEEE754 Floating point number
Double 8 bytes(64 bits) -1.7e308 to 1.7e308(i.e. 1.7*10151) 0.0 IEEE754 Floating point number
Characters
char 2 bytes(16 bits) \u0000 to \uFFFF \u0000 Unicode Characters
Boolean values
boolean 1 bit Not Applicable False true or false

Table : Data Types in Java

Data Types in Java

Java Tutorials Code Sample – GlassPaneDemo.java

package components;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import javax.swing.event.MouseInputAdapter;
/** An application that requires no other files. */
public class GlassPaneDemo {
    static private MyGlassPane myGlassPane;
    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("GlassPaneDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Start creating and adding components.
        JCheckBox changeButton =
                new JCheckBox("Glass pane \"visible\"");
        changeButton.setSelected(false);
        
        //Set up the content pane, where the "main GUI" lives.
        Container contentPane = frame.getContentPane();
        contentPane.setLayout(new FlowLayout());
        contentPane.add(changeButton);
        contentPane.add(new JButton("Button 1"));
        contentPane.add(new JButton("Button 2"));
        //Set up the menu bar, which appears above the content pane.
        JMenuBar menuBar = new JMenuBar();
        JMenu menu = new JMenu("Menu");
        menu.add(new JMenuItem("Do nothing"));
        menuBar.add(menu);
        frame.setJMenuBar(menuBar);
        //Set up the glass pane, which appears over both menu bar
        //and content pane and is an item listener on the change
        //button.
        myGlassPane = new MyGlassPane(changeButton, menuBar,
                                      frame.getContentPane());
        changeButton.addItemListener(myGlassPane);
        frame.setGlassPane(myGlassPane);
        //Show the window.
        frame.pack();
        frame.setVisible(true);
    }
    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}
/**
 * We have to provide our own glass pane so that it can paint.
 */
class MyGlassPane extends JComponent
                  implements ItemListener {
    Point point;
    //React to change button clicks.
    public void itemStateChanged(ItemEvent e) {
        setVisible(e.getStateChange() == ItemEvent.SELECTED);
    }
    protected void paintComponent(Graphics g) {
        if (point != null) {
            g.setColor(Color.red);
            g.fillOval(point.x - 10, point.y - 10, 20, 20);
        }
    }
    public void setPoint(Point p) {
        point = p;
    }
    public MyGlassPane(AbstractButton aButton,
                       JMenuBar menuBar,
                       Container contentPane) {
        CBListener listener = new CBListener(aButton, menuBar,
                                             this, contentPane);
        addMouseListener(listener);
        addMouseMotionListener(listener);
    }
}
/**
 * Listen for all events that our check box is likely to be
 * interested in.  Redispatch them to the check box.
 */
class CBListener extends MouseInputAdapter {
    Toolkit toolkit;
    Component liveButton;
    JMenuBar menuBar;
    MyGlassPane glassPane;
    Container contentPane;
    public CBListener(Component liveButton, JMenuBar menuBar,
                      MyGlassPane glassPane, Container contentPane) {
        toolkit = Toolkit.getDefaultToolkit();
        this.liveButton = liveButton;
        this.menuBar = menuBar;
        this.glassPane = glassPane;
        this.contentPane = contentPane;
    }
    public void mouseMoved(MouseEvent e) {
        redispatchMouseEvent(e, false);
    }
    public void mouseDragged(MouseEvent e) {
        redispatchMouseEvent(e, false);
    }
    public void mouseClicked(MouseEvent e) {
        redispatchMouseEvent(e, false);
    }
    public void mouseEntered(MouseEvent e) {
        redispatchMouseEvent(e, false);
    }
    public void mouseExited(MouseEvent e) {
        redispatchMouseEvent(e, false);
    }
    public void mousePressed(MouseEvent e) {
        redispatchMouseEvent(e, false);
    }
    public void mouseReleased(MouseEvent e) {
        redispatchMouseEvent(e, true);
    }
    //A basic implementation of redispatching events.
    private void redispatchMouseEvent(MouseEvent e,
                                      boolean repaint) {
        Point glassPanePoint = e.getPoint();
        Container container = contentPane;
        Point containerPoint = SwingUtilities.convertPoint(
                                        glassPane,
                                        glassPanePoint,
                                        contentPane);
        if (containerPoint.y < 0) { //we're not in the content pane
            if (containerPoint.y + menuBar.getHeight() >= 0) {
                //The mouse event is over the menu bar.
                //Could handle specially.
            } else {
                //The mouse event is over non-system window
                //decorations, such as the ones provided by
                //the Java look and feel.
                //Could handle specially.
            }
        } else {
            //The mouse event is probably over the content pane.
            //Find out exactly which component it's over. 
            Component component =
                SwingUtilities.getDeepestComponentAt(
                                        container,
                                        containerPoint.x,
                                        containerPoint.y);
                            
            if ((component != null)
                && (component.equals(liveButton))) {
                //Forward events over the check box.
                Point componentPoint = SwingUtilities.convertPoint(
                                            glassPane,
                                            glassPanePoint,
                                            component);
                component.dispatchEvent(new MouseEvent(component,
                                                     e.getID(),
                                                     e.getWhen(),
                                                     e.getModifiers(),
                                                     componentPoint.x,
                                                     componentPoint.y,
                                                     e.getClickCount(),
                                                     e.isPopupTrigger()));
            }
        }
        
        //Update the glass pane if requested.
        if (repaint) {
            glassPane.setPoint(glassPanePoint);
            glassPane.repaint();
        }
    }
}