Ciphers Security

Java Programming Tutorial

java programming

Hello, guys welcome to my new article on introduction to Java programming language in which I will tell you what java programming is and how it works.

In this article, I will explain what java programming is, its operators, data types, and how to run java programs in Windows and Linux.

Java Programming

Java is a programming language used for developing and running applications. It was first released by Sun Microsystems in 1995 and is now a subsidiary of Oracle Corporation. It is an object-oriented language, which means that it is based on the concept of “objects”, which can contain data and code that manipulates that data. Java is known for being fast, reliable, and secure. It is also platform-independent. Platform-independent means Java programs can run on any device that has a Java Virtual Machine (JVM) installed.

Java code should be saved with the (.java) extension to be executed.

Syntax: –

public class Main {
  public static void main(String[] args) {
    System.out.println("Hello World");
  }
}

Uses of Java Programming

Various uses of java programming are listed below: –

  1. Developing desktop applications
  2. Developing web applications
  3. Developing mobile applications
  4. Developing games
  5. Internet of Things (IoT) development
  6. Artificial Intelligence and Machine Learning
  7. Embedded systems development
  8. Developing smart cards and other secure devices
  9. Developing blockchain applications
  10. Developing chatbots and virtual assistants

Operators in Java Programming

In java programming language operators are divided into 3 categories which are Unary, Binary, and Ternary. There are a total of 10 types of operators present in java, which are given below: –

operators in java
  1. Arithmetic operator
  2. Relational operator
  3. Logical operator
  4. Boolean logical operator
  5. Increment/Decrement operator
  6. Bitwise operator
  7. Compound operator
  8. Assignment operator
  9. Instance operator
  10. Conditional operator

Arithmetic Operator

Arithmetic operators are used for performing mathematical operations like addition, subtraction, multiplication, and division. The basic arithmetic operators are +, -, *, and /. There is one more arithmetic operator which is % (modulus). It is a binary operator in which two operands are required to perform any operation.

Ex: –

public class Main {
  public static void main(String args[]) {
    int x = 2;
    int y = 4;
    int z = x + y;
    System.out.println(z);
  }
}

Relational Operator

A relational operator is used to compare two values and determine the relationship between them. The relational operators available in Java are <, >, <=, >=, ==, !=. Relational operators are binary operators in which two operands are required to perform any operation.

Ex: –

public class Main {
  public static void main(Strin args[]) {
    int x = 2;
    int y = 4;
    System.out.println(x > y); 
  }
}

Logical Operator

A logical operator is used to combine multiple relational expressions and create a more complex Boolean expression. The logical operators available in Java are &&(and), ||(or), !(not). It is a binary operator in which two operand is required to perform any operation.

Ex: –

public class Main {
  public static void main(String args[]) {
    int x = 5;
    int y = 10;
    int z = 15;

    if (x < y && y < z) {
      System.out.println("x is less than y and y is less than z");
    }
  }
}

Boolean logical Operator

The Boolean logical operators are used to perform logical operations on Boolean variables or expressions. The Boolean logical operators in Java are &, |, !, ^. It is a binary operator in which two operans are required to perform any operation.

Ex: –

public class Main {
  public static void main(String args[]) {
    boolean a = true;
    boolean b = false;

    if (a | b) {
    System.out.println("At least one of the expressions is true");
    }
  }
}

Increment/Decrement Operator

The increment and decrement operators are used to increase or decrease the value of a variable by a certain amount. The increment operator ++ and the decrement operator — can be used as prefixes or postfix operators. These are unary operators in which only one operand is required to perform any operation.

public class Main {
  public static void main(String args[]) {
    int a = 5;
	int b = ++a;
    System.out.println(b);
  }
}

Bitwise Operator

Bitwise operators are used for performing operations on the individual bits of an integer value. The bitwise operators in Java are & (and),| (or), ^ (xor), ~ (not), << (left shift), >> (right shift), and >>> (unsigned right shift). It is a binary operators.

Ex: –

public class Main {
  public static void main(String args[]) {
    int a = 5;   
    int b = 3;   
    int c = a ^ b;
    System.out.println(c);
  }
}

Compound Operator

Compound operators are used for combining an arithmetic or a bitwise operator with an assignment operator. It allows you to perform an operation and assign the result to a variable in a single step. It is a binary operator. The most common compound operators in Java are given below: –

  1. += (add and assign)
  2. -= (subtract and assign)
  3. *= (multiply and assign)
  4. /= (divide and assign)
  5. %= (modulus and assign)
  6. &= (bitwise and assign)
  7. |= (bitwise or and assign)
  8. ^= (bitwise xor and assign)
  9. <<= (left shift and assign)
  10. >>= (right shift and assign)
  11. >>>= (unsigned right shift and assign)

Ex: –

public class Main {
  public static void main(String args[]) {
    int a = 5;
    a += 2;
    System.out.println(a);
  }
}

Assignment Operator

The assignment operator = is used to assign a value to a variable. The value on the right side of the operator is stored in the variable on the left side of the operator. It is a unary operator.

Ex: –

public class Main {
  public static void main(String args[]) {
    int a = 10;
    int b = a;
    System.out.println(b);
  }
}

Instance Operator

An instance of an operator is used to determine whether an object is an instance of a particular class or interface. The instance of the operator returns a boolean value of true if the object is an instance of the specified class or interface, and false if it is not. It is a unary operator.

Ex: –

public class Main {
  public static void main(String args[]) {
    String str = "Hello";
    if (str instanceof String) {
      System.out.println("str is an instance of String");
    }
  }
}

Conditional Operator

The conditional operator is a shorthand way of writing an if-else statement. Conditional operators are (?) and (:). It is a ternary operator in which three operands are required for performing an operation. The syntax of the conditional operator is given below: –

expression1 ? expression2 : expression3

Ex: –

public class Main {
  public static void main(String args[]) {
    int a = 10;
    int b = 20;
    int c = (a > b) ? a : b;
    System.out.println(c);
  }
}

Data types in Java Programming

data types in java

Data types are the concept which is used to show or describe the nature of the variable whether it is an integer or character or another. In Java Data types are divided into four categories which are: –

  1. Integer
  2. Decimal
  3. Character
  4. Boolean

Data TypeSize in byteSize in bitsDescription
byte 1 byte8 bitsStores whole numbers from -128 to 127 (Integer)
short 2 bytes16 bitsStores whole numbers from -32,768 to 32,767 (Integer)
int 4 bytes32 bitsStores whole numbers from -2,147,483,648 to 2,147,483,647
(Integer)
long 8 bytes64 bitsStores whole numbers from -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807 (Integer)
float 4 bytes32 bitsStores fractional values up to 6 to 7 digits (Decimal)
double 8 bytes64 bitsStores fractional values up to 15 digits (Decimal)
char0.125 byte1 bitStores a single letter/alphabet or ASCII value
boolean2 bytes16 bitsStores true or false values

If you have any queries regarding the above content, or you want to update anything in the content, then contact us with your queries. You can directly post your question in the group.

Connect with us on these platforms




RECENT POST

Connect with us