What Is Java
Java programming is a programming language that allows to interact with the system and develop set of instruction. It supports Object-Oriented Concepts for managing the user instructions and generates output. Java provides different format like J2SE for the standard edition, J2EE for enterprises edition and J2ME for a micro edition. It support console, window, web, and mobile based applications. It supports platform independent concept with the help of JVM (Java Virtual Machine). Platform independent means java application support multiple machines and Operating System for execution. It provides built-in classes, functions, keywords for managing the instructions and is available in JDK (Java Development Kit) with different versions like JDK1.1, JDK1.8 etc. This language introduced by Sun microsystem in 1971.
Features of Java:
- Class:- It is a way to define the group of similar data member and bind together for data processing. It helps us to declare the member function also and access with the help of an object.
- Object:- It is an instance of the class that allows accessing the data member of existing class. It processes similar to the variable and contains complete details of existing class. The class is not capable to execute its own function so need to create an object of that class.
- Polymorphism:- It is the feature of object-oriented programming that allows executing multiple operations with the single identifier. It means one too many.
- Inheritance:- It is the feature to extend the data member of a class to another class. It is basically used to share the data members and a member function of multiple classes for reusability.
- Encapsulation:- This feature identifies the data members in encapsulated format and provide the user with data processing.
- Abstraction:- This feature that provides to the user for the new definition of an existing function. It means the user can define the new definition of the existing function which Detroit as abstract.
- Exception:- The programming instructions are defined in a particular syntax and generate the error at compilation time but Java programming language also controls runtime error, which generates at the time of program execution. The runtime error is known as an exception.
Simple program in Java
public static void main (String s)
How to compile ?
The programming instructions are developed in particular editor and save with dot(.) java. This file compile on command prompt with following instruction. We save the file with class name generally because we need to use class name for execution.
compile in cmd – javac <file name>.java
run in cmd- java <file name>
Data Types in Java
The data type is used to separate the nature of variable and we define a data type for a particular variable that creates a memory to hold the value. There are following type of data type:-
Operators in java
Java programming language provides different tokens to control the different operations of the data and return a particular value.
There are different types of operators :
1. Arithmetic Operator:- It is an operator that allows managing the arithmetic operations like +, -, *, /, %.
2. Comparison Operator:- It is an operator that compare the data and return logical value like true or false. It also identified as the relational operator.
3. Logical Operator:- It is an operator that allow to combine the relational, conditions and return the logical value true or false.
4. Assignment Operator:- This operator assigns the value to the particular variable.
5. Increment Operator:- This operator increases the value with one step and assign on the existing variable.
a) pre-increment:- It is an operator that increase the value before executing the statement and the operator use before the variable like ++a.
b) post-increment:- It is an operator that increase the value after executing the statement and the operator use after the variable like a++.
6. Decrement Operator:- This operator decreases the value with one step and assign on the existing variable.
a) pre-decrement:- It is an operator that decrease the value before executing the statement and the operator use before the variable like –a.
b) post-decrement:- It is an operator that decrease the value after executing the statement and the operator use after the variable like a–.
7. Bitwise Operator:- It is an operator that allows managing value at a bit level.
Scanner class is a class that available in java.util package. It contains set of classes related to input. We create an object of this class to get the functions and access its related members.
Functions in Scanner Class
- nextInt:- It is a function that allows getting integer input from the user.
- float:- It allows getting float input through the user.
- next:- It is a function that allows getting input without space.
- nextLine:- It is also used for string input with space.
- next short:- This function allows getting integer value with short data.
Program to add two numbers
public static void main(String s)
Scanner sc = new Scanner (System.in);
System.out.print(“Enter first value “);
int a = sc.nextInt();
System.out.print(“Enter second value “);
int b = sc.nextInt();
int c = a+b;
System.out.print(“Sum is ” + c);