Home / JAVA / Java Programming
image source:-https://www.hostingireland.ie

Java Programming

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:

  1. 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.
  2. 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.
  3. Polymorphism:- It is the feature of object-oriented programming that allows executing multiple operations with the single identifier. It means one too many.
  4. 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.
  5. Encapsulation:- This feature identifies the data members in encapsulated format and provide the user with data processing.
  6. 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.
  7. 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

Class a

{

public static void main (String s[])

{

System.out.print(“Hello India”);

}

}

 

Class a
It is an instruction that create a class with particular identifier. Here class is a keyword and a is class identifier.
{
It is a symbol that identify starting of the class or function.
public static void main (String s[])
It is a main function that able to execute user define and system define function. Here public identify this function can access outside of the class. Static identify this function execute of class level and void identify it does not return any value after processing the data and main reserve function identifier. In this we pass, string array to hold the value from command line argument.
System.out.print(“hello india”)
It is an instruction that display the message and value of the variable. Here System is a class and print is a function name.
}
It identify ending of the class or function.

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.

a.java

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:-

 

int()
It is a data type that hold the integer value without any fraction.
float()
It is also use to store numeric value as integer but contain fraction data.
long()
It is also use to store numeric value as integer but contain use data.
double()
It is use to store float value with use data.
char()
It is use to store character value.
string()
It is use to store set of characters.
boolean()
It is a data type that contain logical value like true, false.
byte()
It is a data type that hold byte value like 0, 1.

 

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 +, -, *, /, %.

table for operator
Image source- http://www.expertsmind.com

 

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.

table for operator
Image Source- http://www.expertsmind.com

 

3. Logical Operator:- It is an operator that allow to combine the relational, conditions and return the logical value true or false.

Table of Logical operator
Image Source- http://slideplayer.com

 

4. Assignment Operator:- This operator assigns the value to the particular variable.

table
Image Source- https://1.bp.blogspot.com

 

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.

Operators
Image source- https://image.slidesharecdn.com

 

Scanner Class:

description of scanner class
Image source:-https://www.sitesbay.com

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

 

  1. nextInt:- It is a function that allows getting integer input from the user.
  2. float:- It allows getting float input through the user.
  3. next:- It is a function that allows getting input without space.
  4. nextLine:- It is also used for string input with space.
  5. next short:- This function allows getting integer value with short data.

 

Program to add two numbers

import java.util.*;

Class add

{

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);

}

}

 

import java.util.*
It is an instruction that allow to add the package into the program. A package is a collection of classes and it help to manage the user instruction. Here, import is a keyword that import the classes from the package. Java.util is a package that contain different type of classes. we use asterik symbol to import all classes from the util package.
Scanner sc = new Scanner (System.in)
It is an instruction that allow to add the package into the program. A package is a collection of classes and it help to manage the user instruction. Here, import is a keyword that import the classes from the package. Java.util is a package that contain different type of classes. we use asterik symbol to import all classes from the util package.
int a = sc.nextInt()
It is an instruction that allow to get integer input through user.

About Udit Mutreja

Check Also

Inheritance in Java

Inheritance in Java Inheritance is the feature of object-oriented programming concept for extending the data member …

Leave a Reply

Your email address will not be published. Required fields are marked *