This tutorial covers all the topics of Java Programming language. In this section you will learn about what is Java, download java, Java environment set up, features of Java, keywords in Java, data types in Java, conventions in Java, Java identifiers, access specifiers, variables in Java, Java literals, Java operators, conditional statements, loops in Java.
In this section we will discuss about the Java Programming Language.
This tutorial covers all the topics of Java Programming Language. In this section you will learn about what is Java, Download Java, Java environment set up, Features of Java, keywords in Java, DataTypes in Java, conventions in Java, Java identifiers, access specifiers, Variables in Java, Java literals, Java operators, conditional statements, loops in Java.
Java is a programming language based on the OOPs concept. It is a simple, secure and platform-independent language. It supports Multi-threading, distributed, and dynamic application. Applications developed using Java Programming Language are robust, portable, and their performance is high. It was developed by James Gosling and released by the Sun Microsystems in 1995. Java is called an emerging language because most of the syntaxes used in it are derived from the programming language 'C' and 'C++'. Java is written in such a way that it facilitate developer to write code in "write once run anywhere" (WORA) manner i.e. if a code is written on one platform and it is running over there then it can be run on another platform without recompiling there. Java is available as an open source under the GNU General Public License.
Java can be downloaded from the Oracle sites, an official website for Java. You can go through the link for downloading latest version of Java http://www.oracle.com/technetwork/java/javase/downloads/index.html then select the license acceptance agreement.
Java Environment Set Up
To run Java in your system you have to set up the environment. You can set up environment according to your platform i.e. O/S (Operating System). For example
- Environment Set Up for Windows
- Linux
Java has various features, these are as follows :
- Simple
- Object Oriented
- Compiler and Interpreter
- Platform Independent
- Secure
- Robust
- Distributed
- Multithreaded
- Dynamic
- Architectural Neutral
- High Performance
Keywords In Java
Keywords are the reserve word for doing specific task the programming language's compiler understands. Java has also keywords some of these are as follows :
abstract, assert, boolean, break, byte, case, catch, char, class, const, continue, default, do, double, else, enum, extends, final, finally, float, for, goto, if, implements, import, instanceof, int, interface, long, native, new, package, private, protected, public, return, short, static, strictfp, super, switch, synchronized, this, throw, throws, transient, try, void, volatile, while.
Java allows two types of data types these are as :
- Primitive Data Types: In Java there are eight primitive data types these data types are predefined by the language.
- Reference Data Types: Reference data types are the data types that contains the reference of any object of the declared type or any compatible type. for example Bicycle bicycle = new Bicycle(); Here bicycle is a reference data type variable.
Conventions In Java
Java is a case sensitive language it follows the conventions for declaring or defining the classes, methods, interfaces etc. To use the predefined data types, classes, methods, interfaces etc. we must have to follow as they are defined or declared.
Java Identifiers
Assigning a name to a Java component is called identifiers, For example assigning name to a method, classes, and variables. An identifiers should follow the following tips :
- Should be started with an alphabetic character, $, or an underscore (_) then the following character identifiers can contain any combination of characters.
- An identifier mustn't be a Java keyword.
- Identifiers in Java are case sensitive.
Access Specifiers
Access specifiers or modifiers explains the accessibility of Java component like, class, methods, variables, etc. There are two types of access modifiers these are :
- Access Modifiers : Specifies the scope of accessibility like, default, public, protected, private.
- Non-access Modifiers : Specifies the non accessibility like, final, abstract, strictfp.
There are three types of variables in Java.
- Instance variables
- Class variables
- Local variables
Java literals
Literals in Java represents the fix value. They can be used directly in Java Code for example, '\t' for tab space, '\b' for backspace, '\n' for newline etc.
Java Operators
Programming languages provides operators for manipulating variables. Java also have a set of operators for manipulating variables. These operators can be categorized as :
- Arithmetic Operators : '+', '-', '*', '/', '%'
- Relational Operators : '= =', '!=', '>', '<', '>=', '<='
- Bitwise Operators : '&', '|', '^', '~', '<<', '>>', '>>>'
- Logical Operators : '&&', '||', '!'
- Assignment Operators : '=', '+=', '-=', '*=, '/=', '%=', '<<=', '>>=' etc.
- Increment Operator : '++'
- Decrement Operator : '--'
- Ternary Operator : '? : '
Conditional Statement
Conditional statements are the statements used for testing the conditions. if, nested if, if-else, if-else if, nested if-else if etc. are called the conditional statements.
Loops In Java
0Java provides loops to execute the statements repeatedly in a controlled way. These loops are as :
- while loop
- while loop : while loop provides to execute the statement repeatedly till the statement satisfies the condition given as parameter of while loop. while loop can be written as :
- do....while loop : do....while loop is same as while loop but the only difference is that the do...while loop statement will execute once either it satisfies the condition or not whereas, while loop will execute only when it satisfies the condition do...while loop can be written as .
initialization; while(condition/boolean expression) { //statement } increment/decrement;
do{ //statement } while(condition/boolean expression);
- for loop
- for loop : for loop provides a simple way to execute the statement repeatedly till the statement satisfies the condition given as parameter of for loop. for loop can be written as :
- Advanced for loop (for each loop) : for each loop is introduced since Java 5, and is basically used to traverse the elements in array or a collection. for-each loop can be written as :
for(initialization; condition/boolean expression; increement/decreement) { //statement }
for(data_type variable : array/collection) { //statement }