Java Keywords All List With Descriptions

Java Keywords All List With Descriptions
Java Keywords All List With Descriptions 

Java Language Keywords

    Java Keywords List: In the Java artificial language, a Keyword is anyone of fifty-two reserved words that have a predefined that means within the language attributable to this, programmers cannot use keywords as names for variables, methods, classes, or as the other symbol.


    Java Language Keywords: Java keywords in the Java programming language. You cannot use any of the following as identifiers in your programs. The keywords const and goto are reserved, even though they are not currently used. true, false, and null might seem like keywords, but they are actually literals; you cannot use them as identifiers in your programs.


    Java Keywords List

    1. abstract

    2. boolean      

    3. break        

    4. byte

    5. case    

    6. catch           

    7. char            

    8. class

    9. continue 

    10. default 

    11. do   

    12. double

    13. else         

    14. enum 

    15. extends

    16. final

    17. finally      

    18. float         

    19. for      

    20. if

    21. implements

    22. import

    23. instanceof

    24. int

    25. interface     

    26. long     

    27. new       

    28. package

    29. private  

    30. protected   

    31. public 

    32. return

    33. short      

    34. static        

    35. super   

    36. switch

    37. this          

    38. throw      

    39. throws     

    40. try

    41. void

    42. while  


    Java Keywords List and Descriptions

    Abstract: An abstract class cannot be used to create objects (to access it, it must be inherited from another class). An abstract method can only be used in an abstract class, and it does not have a body. The body is provided by the subclass.


    Assert: For debugging


    Boolean: A data type that can only store true and false values


    Break: Breaks out of a loop or a switch block


    Byte: A data type that can store whole numbers from -128 and 127


    Case: Marks a block of code in switch statements


    Catch: Catches exceptions generated by try statements


    Char: A data type that is used to store a single character


    Class: Defines a class


    Continue: Continues to the next iteration of a loop


    Const: Defines a constant. Not in use - use final instead


    Default: Specifies the default block of code in a switch statement


    Do: Used together with while to create a do-while loop


    Double: A data type that can store whole numbers from 1.7e−308 to 1.7e+308


    Else: Used in conditional statements


    Enum: Declares an enumerated (unchangeable) type


    Exports: Exports a package with a module. New in Java 9


    Extends: Extends a class (indicates that a class is inherited from another class)


    Final: A non-access modifier used for classes, attributes, and methods, which makes them non-changeable (impossible to inherit or override)


    Finally: Used with exceptions, a block of code that will be executed no matter if there is an exception or not


    Float: A data type that can store whole numbers from 3.4e−038 to 3.4e+038


    For: Create a for loop


    Goto: Not in use, and has no function


    If: Makes a conditional statement


    Implements: Implements an interface


    Import: Used to import a package, class, or interface


    Instanceof: Checks whether an object is an instance of a specific class or an interface


    Int: A data type that can store whole numbers from -2147483648 to 2147483647


    Interface: Used to declare a special type of class that only contains abstract methods


    Long: A data type that can store whole numbers from -9223372036854775808 to 9223372036854775808


    Module: Declares a module. New in Java 9


    Native: Specifies that a method is not implemented in the same Java source file (but in another language)


    New: Creates new objects


    Package: Declares a package


    Private: An access modifier used for attributes, methods, and constructors, making them only accessible within the declared class


    Protected: An access modifier used for attributes, methods, and constructors, making them accessible in the same package and subclasses


    Public: An access modifier used for classes, attributes, methods, and constructors, making them accessible by any other class


    Requires: Specifies required libraries inside a module. New in Java 9


    Return: Finished the execution of a method, and can be used to return a value from a method


    Short: A data type that can store whole numbers from -32768 to 32767


    Static: A non-access modifier used for methods and attributes. Static methods/attributes can be accessed without creating an object of a class


    Strictfp: Restrict the precision and rounding of floating point calculations


    Super: Refers to superclass (parent) objects


    Switch: Selects one of many code blocks to be executed


    Synchronized: A non-access modifier, which specifies that methods can only be accessed by one thread at a time


    This: Refers to the current object in a method or constructor


    Throw: Creates a custom error


    Throws: Indicates what exceptions may be thrown by a method


    Transient: A non-access modifier, which specifies that an attribute is not part of an object's persistent state


    Try: Creates a try...catch statement


    Var: Declares a variable. New in Java 10


    Void: Specifies that a method should not have a return value


    Volatile: Indicates that an attribute is not cached thread-locally, and is always read from the "main memory"


    While: Creates a while loop



    Java Language Rules for Naming an Identifier

    1. Identifiers cannot be a keyword.

    2. Identifiers are case-sensitive.

    3. It can have a sequence of letters and digits. However, it must begin with a letter, $ or _. The first letter of an identifier cannot be a digit.

    4. It's a convention to start an identifier with a letter rather than $ or _.

    5. Whitespaces are not allowed.

    6. Similarly, you cannot use symbols such as @, #, and so on.


    Java Language same valid identifiers

    1. score

    2. level

    3. highest score

    4. number1

    5. convertToString


    Java Language same invalid identifiers

    1. class

    2. float

    3. 1number

    4. highest Score

    5. @pple


    Java Keywords List and Descriptions with Examples


    1. abstract: Using the abstract keyword in java we can create abstract classes and methods. Abstract keywords are essential to implement abstraction into a program.

    abstract class DataFlair

         

    2. assert: Using the assert keyword we can implement assertion in a program. Using it we can check the correctness of any assumptions made in a program. The assert keyword was added in JDK 1.4.

    int i = 10;

               assert I> 5: "The value is greater than 5"; 



    3. boolean: Using the boolean keyword we can declare a boolean variable. A boolean variable is a variable that has two values, true and false.

    boolean flag=true; 


     
    4. break: The break keyword is a jump statement using which we can break out of a loop or switch statement. The break statement terminates the currently executing block of code.

    i=0;

    while(true)

    {

         if(i==10)

         break;

         i++;

    }

     

    5. byte: Using the byte keyword in java we can declare a variable that can hold a value of 1 byte or 8 bit.

    byte num=1;

     

    6. case: Using the case statement we can declare each case inside a switch-case block.

    {

         case 1:

                   System. out.println(“ONE”);

                   break;

    }


     
    7. catch: The catch keyword is part of exception handling in java. Using the catch keyword we can catch or capture the error caught by the try block. A catch block can exist only after the try block.

    catch (Exception e)

    {

           System. out.println(“An exception was caught by the try block”);

    } 


     
    8. char: Using the char keyword we can declare a character variable.

    char ch= 'A';


     
    9. class: Using the class keyword we can declare a class in java.

    class DataFlair

     

    10. continue: Continue is also a jump statement in java. Using it we can terminate the current iteration and continue from the next iteration inside the loop.

    i=0;

    while(i<=10)

    {

         if(i==5)

         continue;

         i++;

    }


    11. default: default is the keyword using which we can declare the default statement inside a switch case. It is executed when none of the cases match.

    Switch(num)

    {

         case 1:

                   System. out.println(“ONE”);

                   break;

         default:

                   System. out.println(“Not ONE”);

    }


    12. do: Using the do keyword we can declare a do-while loop. It is an exit-controlled loop, so it doesn’t have any entry conditions.

    i=0;

    do{

            i++;

         }while(i<=10);

     

    13. double: Using the double keyword we can declare a double variable. A double variable can hold a 64bit long floating point number.

    double d=1.23456


    14. else: Using the else keyword we can write statements that will be executed when the if block doesn’t execute successfully.

    i=5;

    if(i!=5)

    System. out.println(“Not Five”);

    else

    System. out.println(“FIVE”);


    15. enum: Using the enum keyword we can declare an enumerated class. It consists of a fixed set of constants. Enum constructors are always private by default. Enum keyword was added to java in JDK 5.0.

    enum Rainbow

    {

      Violet, Indigo, Blue, Green,

      Yellow, Orange, Red;

    }


    16. extends: extend keyword is used in inheritance. Using it we can inherit one class into another.

    class subclass extends superclass 


    17. final: Using the final keyword we can finalize the value of a variable. It means that the value cannot be updated by the user whatsoever.

    final int num=1000  


    18. finally: The final keyword is used after the try-catch block. It indicates the end of the block. Unlike the try-catch block, the final block will be executed regardless of whether an exception is found or not.

    finally{

    System. out.println("This block is always executed whatsoever!");

    }


    19. float: Using the float keyword we can declare a float variable in java. The float variable holds a 32-bit long floating-point number.

    float num= 1.324f;


    20. for: Using the for the keyword we can declare a for a loop. It is an entry-controlled loop, for this kind of loop the number of iterations should be known beforehand.

    for(i=0;i<10;i++)

    {

        System.out.println(i);

    }


    21. if: In java, the if keyword is used to declare an if conditional statement. The if statement is used to check the viability of a condition.

    i=5;

    if(i==5)

    {

        System. out.println(“The Number is Five”);

    }


    22. implements: Using the implements keyword in java we can declare an interface. It is like the inheritances extend keyword, here to access an interface we have to use the implements keyword.

    interface DataFlair{

    public void intern();

    }

    class internship implements DataFlair

    {

            Public void intern()

           {

                    System.out.println(“Internship Granted”);

            }

    }


    23. import: Using the import keyword in java we can access classes and interfaces present inside a package to the current code.

    import java.util.Arrays;


    24. instanceof: Using the instanceof keyword in java we can check whether a given object is an instance of another class or not. It returns true if the given object is an instance and false if not.

    public class DataFlair {

      public static void main(String[] args) {

        DataFlair Obj1 = new DataFlair();

        System.out.println(Obj1 instanceof DataFlair);// It will return True.

      }

    }


    25. int: Using the int keyword we can declare a variable of integer datatype. It can hold a value of 32-bit long.

    int num=100;


    26. interface: Using the interface keyword in java we can declare an interface inside the code.

    interface DataFlair{}


    27. long: Using the long keyword we can declare variables with the long data type. The long data type is an integer that can hold 64-bit data.

    long num=10000;


    28. native: The native keyword in java is used to indicate that a method is implemented in native code using JNI[Java Native Interface].

    Public native void Dataflair()


    29. new: Using the new keyword we can create a new instance for a class.

    public class Dataflair(){

    public static void main(String[] args){

    DataFlair obj1=new DataFlair();

    }


    30. Package: Using the package keyword in java we can create a new package in the java library.

    package com.DataFlair.Keywords;


    31. private: private keyword is an access modifier that declares a class or method as private; i.e; it can only be accessed by its local variables.

    private class DataFlair{}


    32. protected: protected is also an access modifier that declares a class or method as protected; i.e; it can be accessed by files in the PWD(Present Working Directory).

    protected class DataFlair{}


    33. public: the public is another access modifier that declares a class or method as public; i,e; it can be accessed globally.

    public class DataFlair{}


    34. return: The return keyword is used inside a method when it requires to return of a value of a certain return type except for the void.

    int sum(int a, int b)

    {

         return (a+b);

    }


    35. short: In java, the short keyword declares variables that can hold an integer value of 16-bit long.

    short num=1;


    36. static: In java, the static keyword declares a static variable or method. A static variable or method is stored in a static memory location.

    public static void main()


    37. strictfp: In java, the strictfp keyword ensures that every platform gets the same result for floating-point operation. The strictfp keyword is used on classes, methods, and interfaces. This keyword was introduced in JDK 1.2.

    strictfp class DataFlair{}


    38. super: The super keyword distinguishes variables with the same name in both parent class and child class in inheritance.

    class DataFlair

    {

         String name=” Company”;

    }

    class internship extends DataFlair/

    {

         String name=” Intern”;

         System.out.println(name);//Intern will be printed

         System.out.println(super.name);//Company will be printed

    }


    39. switch: Using the switch keyword we can initiate the switch case block in a java code.

    Switch(num)

    {

         case 1:

                   System. out.println(“ONE”);

                   break;

         default:

                   System. out.println(“Not ONE”);

    }


    40. synchronized: Using the synchronized keyword in java we can specify the critical section to be executed during multithread coding

    synchronized void print(int num)


    41. this: this keyword in java is used to distinguish local variables from global variables.

    class DataFlair{

    String name;

    DataFlair(String name)

    {

         this.name=name;

    }

    }


    42. throw: The throw keyword in java is used to throw custom-made exceptions explicitly into the code.

    throw new IOException("The Input is Not Acceptable”);


    43. throws: The throws keyword is used to propagate a checked exception.

    import java.io.*; 

    class DataFlair{ 

     void internship()throws IOException{ 

      throw new IOException("Internship Not Found"); 

     } 

    }


    44. transient: Using the transient keyword in java we can deserialize a variable. When a variable is declared transient, it is not considered for serialization.

    transient int num;}


    45. try: The try block is used in exception handling to test a block of code for exceptions. The try block is always followed by a catch block or finally block.

    try{

    //statement

    }catch(exception e){}


    46. void: Using the void keyword we can declare that the method will not return any value.

    void main()


    47. volatile: volatile keyword in java is used to indicate that a variable can change asynchronously.

    static volatile int num=100;


    48. while: Using the While keyword we can declare a while loop. While loop is an entry-controlled loop, where the number of iterations is not fixed.

    i=5;

    while(i<=10)

    {

        i++;

    }


    Read Also Others Programming Languages






    Post a Comment

    0 Comments
    * Please Don't Spam Here. All the Comments are Reviewed by Admin.