Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

What are basic fundamentals of Java programming language ?.

Java is a very versatile language. It is the language of future on the programming perspective. In this tutorial hub I will be providing you with Java fundamentals. 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
When dealing with whitespace generally syntax rules come into picture. Whitespace characters such as tabs, newlines and spaces in a program makes 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. These formatting is ignored by the compiler. Styles include 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.


// Bad Style Coding
// Very hard to read, no indents used

public class Welcome {
public static void main(String[] args){
int i = 0; // single line comment
    
for(int i=0;i<=10;i++){
int j = 1;
int k = j;
System.out.println("Welcome to comments"); 
}
} 



// Good Style Coding
// Very easy to read, excellent use of indents

public class Welcome {
  public static void main(String[] args){
    int i = 0; // single line comment
    
    for(int i=0;i<=10;i++){
      int j = 1;
      int k = j;
      System.out.println("Welcome to comments"); 
    } 
  }
}

  • Comments
Comments are important elements of any programming language. Comments provide us a way to insert notes in a source code. They make us understand a complex code without going into much depth of the code. They make source code easier to debug. Also they are ignored by the compiler so we have no issues related to memory. There are mainly 2-3 types of Java comments Single line comment and multi-line comment. A single line comment as the name suggest comments out single line. 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. You can also use multi-line comment which 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.


public class Welcome {
  public static void main(String[] args){
    int i = 0; // single line comment
    
    for(int i=0;i<=10;i++){
     /* int j = 1;
        int k = j;
        System.out.println("Welcome to comments"); */ 
     /* multi-line comment, whole code between is commented out */ 
    }
  }
}

  • Identifiers


Identifiers are names given to variables , class , methods in a Java source code. There are rules imposed on the naming conventions of Java identifiers. The rules are as follows:
  1. An Identifier must begin with a unicode character, dollar sign or underscore.
  2. After the first character you can add numbers along with unicode characters, dollar sign and underscore.
  3. Generally use of currency symbols such as dollar sign should be avoided.
  4. Java identifiers are Case-sensitive.
  5. Java identifiers should not be a reserved keyword of Java.
  6. Capital letters should be used to separate two words.
  • Reserved Keywords
In Java there are several words which are reserved by the language and cannot be used for naming identifiers. The list of such keywords are :
  • Separators
Separators are highly used in Java programming language. Each separator has its own significance. Lets look some of the separators and their characteristics:-
  • Literals
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
  • 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 in Java video :- 
 
     
    © 2021 Learn Java by Examples Template by Hubberspot