Latest Posts on Java Code Park

Import keyword

- No Comments
The import keyword makes one class or all classes in a package visible in the current Java source file. Imported classes can be referened without the use of fully−qualified class names.
  • Many Java programmers use only specific import statements (no '*') to avoid ambiguity when multiple packages contain classes of the same name.
  • import java.io.File;
    import java.net.*;
    


    Implements Java Keyword

    - No Comments
    The implements keyword is used in a class declaration to indicate that the class being declared provides implementations for all methods declared in the interface whose name follows the implements keyword.
  • In the example above, the Truck class must provide implementations for all methods declared in the IVehicle interface.
  • The Truck class is otherwise independent; it may declare additional methods and variables and may extend another class.
  • A single class may implement multiple interfaces.
  • public class Truck implements IVehicle
    {
    }


    if Java Keyword

    - No Comments
    The if keyword indicates conditional execution of a block. The condition must evaluate to a boolean value.
  • An if statement may have an optional else clause containing code that is executed if the condition is false.
  • Expressions containing boolean operands can contain only boolean operands.
  • 
    if (condition)
    {
    
    }
    if (condition)
    {
    
    }
    else
    {
    
    }


    For Keyword in Java

    - No Comments
    The for keyword specifies a loop whose condition is checked before each iteration. Examples
  • The for statement takes the form for(initialize; condition; increment)
  • The initialize statement is executed once as the flow of control enters the for statement.
  • The condition is evaluated before each execution of the body of the loop. The body of the loop is executed if the condition is true.
  • The increment statement is executed after
  • int i;
    for (i=0; i
    }


    Float Java Keyword

    - No Comments
    float Java Keyword float is a Java primitive type. A float variable may store a single−precision floating point value. ExamplesRemarks
  • The following rules apply to this keyword's use:
  • Floating point literals in Java always default to double−precision. To specify a single−precision literal value, follow the number with f or F, as in 0.01f.
  • Since floating point data types are approximations of real numbers, you should generally never compare floating point numbers for equality.
  • Java floating point numbers can represent infinity and NaN (not a number). The Float wrapper class defines the constants MIN_VALUE, MAX_VALUE, NEGATIVE_INFINITY, POSITIVE_INFINITY and NaN.
  • 
    float ratio = .01;
    float diameter = 6.15;
    float height = 1.35E03; // 1.35 * 103 or 1350.0
    float height = 1e−2; // 1.0 * 10−2 or 0.01
    


    Finally Java Keyword

    - No Comments
    The finally keyword is used to define a block that is always executed in a try−catch−finally statement. A finally block typically contains cleanup code that recovers from partial execution of a try block. Examples Remarks
  • The opening and closing curly braces { and } are part of the syntax of the finally clause and may not be omitted even if the clause contains a single statement.
  • Every try block must have at least one catch or finally clause.
  • If any portion of the try block is executed, the code in a finally block is always guaranteed to be executed whether an exception occurs or not and independent of whether the try or catch blocks contain return, continue or break statements.
  • In the absence of exceptions, control flows through the try block and then into the finally block.
  • If an exception occurs during execution of the try block and the appropriate catch block contains a break, continue or return statement, control flows through the finally block before the break, continue or return occurs.
  • try
    {
    
    }
    catch ( e)
    {
    
    }
    finally
    {
    
    }