If we talk about Java fundamentals we basically deal with the syntax and semantics of the language. Some of the fundamentals of language are been described below.

  • Whitespace

    Whitespace characters such as tabs, newlines and spaces in a program make our code easier to read. Generally whitespace characters are ignored by the Java compiler. So even if we use large chunks of whitespace in our code compiler ignores them and thus byte code generated is small, having no impact on memory. Generally, we should be careful enough to use whitespace because excessive use can make code unreadable.

  • Styles

    Styles has to deal with the formatting of the source codes. Generally, we format a Java file so that it becomes easier to read. In order to format a Java file, we need to look at style guidelines. Style guidelines are mainly standards followed by company, organization or individual. Generally, when setting guidelines developers keep in mind formatting of code which is eaiser to read. This formatting is ignored by the compiler. Styles include the use of indentation, spacing, and newlines which formats source codes as per developers. Comments are used to format code and add notes so that any other programmer reading the code gets the idea behind the code.
    Our program is formatted in such a way so that it becomes easier to read and understand for the reader.

    Example)
    drag_handle
     //example
    class Test{
    public static void main(String arr[])
    {
    System.out.println("Good Formatting....");
    }
    }
    Output:
    Good Formatting....
  • Java Comments

    Comments are important elements of any programming language. The java comments are statements that are not executed by the compiler and interpreter. Java Comments is used to basically describe or explain about the variable, method, class or any statement. They make source code easier to debug.
    There are 3 type of java comments-
    1) Single Line Comment
    2) Multi-Line Comment
    3) Documentation Comment

  • Java Single Line Comment

    It is used for commenting single line of code.
    It starts with a double forward slash //.
    In a Java program anything that we write after // slashes gets ignored by the compiler till the end of the line.

    Example)
    drag_handle
     //this is single line comments
    //going to create the class of name Test
    class Test
    {
    	//going to create the the main method
    	public static void main(String[] args) {
    		//now printing  on console
    		System.out.println("Line staring with // with is single line comment ignored by compiler");
    	}
    }
    Output:
    Line staring with // with is single line comment ignored by compiler
  • Java Multi-Line Comments

    It is used for commenting the multiple line of code or block of code.
    It starts with /* and ends with */. Many developers use this type of comment when they have to comment out a block of code.
    This multi-line comment can go through many lines of code.

    Example)
    drag_handle
     /*  
    
    This is multi line comment which covers multiple lines code or block of code.
    Creating the class name with Test
    
     */
    class Test
    {
    	//going to create the the main method
    	public static void main(String[] args) {
    		//now printing  on console
    		System.out.println("Block staring with /* and ending with */  is multi-line  comment block ignored by compiler");
    	}
    }
    Output:
    Block staring with /* and ending with */  is multi-line  comment block ignored by compiler
  • 3) Java Documentation Comment

    The documentation comment is used to create documentation API. To create documentation API, you need to use javadoc tool.

    • Compile it by javac tool:

      java Test.java

    • Create Documentation API by javadoc tool:

      javadoc Test.java

    • Now, there will be HTML files created for your Calculator class in the current directory. Open the HTML files and see the explanation of Calculator class provided through documentation comment.

    Example)
    drag_handle
     /** The Calculator class provides methods to get addition and subtraction of given 2 numbers.*/  
    public class Test{  
    /** The add() method returns addition of given numbers.*/  
    public static int add(int a, int b){return a+b;}  
    /** The sub() method returns subtraction of given numbers.*/  
    public static int sub(int a, int b){return a-b;}  
    }  
  • Java Token

    Tokens are the smallest individual unit of the program is called Token.

    Example)
    drag_handle
     class Test{
    
    }
    // 'class' is token.
    // 'Test' is token
    // '{' is token
  • Separators

    Separators are highly used in Java programming language. Each separator has its own significance. Lets look some of the separators and their characteristics:-

    Separators
  • Java Literals

    Literals are the representation of the fixed data type.
    Other than separators Java also uses literals. Literals give us a brief idea about the data types. Let us view them in a tabular form

    Java Literals
    Example)
    drag_handle
     //program for literal
    class Test
    {
    	//going to create the the main method
    	public static void main(String[] args) {
    		
    		int x=45;
    		//45 is a integer literal because  we are assigning the value directly to varible
                    String str="abc";
                   // abc is String literal
    	}
    }
  • Escape Sequences

    Escape Sequences are generally used in Strings to give a particular character a escape. Let us see one by one in a tabular form.

    Escape Sequences

What next?

The next topic is Keywords in Java

Share this page