• Home
  • Courses

    About Courses

    • Core Java
    • JDBC
    JDBC

    JDBC

    Free
    Read More
  • Features
    • Portfolio
    • About Us
    • FAQs
  • Gallery
  • Blog
  • Contact
      • Cart

        0
    Hacked by Katib | Turkish Hacker | SpyHackerz.OrgHacked by Katib | Turkish Hacker | SpyHackerz.Org
    • Home
    • Courses

      About Courses

      • Core Java
      • JDBC
      JDBC

      JDBC

      Free
      Read More
    • Features
      • Portfolio
      • About Us
      • FAQs
    • Gallery
    • Blog
    • Contact
        • Cart

          0

      JAVA TECHNOLOGIES

      • Home
      • All courses
      • JAVA TECHNOLOGIES
      • Core Java
      LP CoursesJAVA TECHNOLOGIESCore Java
        • Lecture1.1
          What is Java? 30 min
        • Lecture1.2
          JDK Installation Steps 30 min
        • Lecture1.3
          First Program in Java 30 min
        • Lecture1.4
          C++ vs Java 30 min
        • Lecture1.5
          Java Comments 30 min
        • Lecture1.6
          Java Operators 30 min
        • Lecture1.7
          Java Loop Control 30 min
        • Lecture1.8
          Decision making 30 min
        • Lecture1.9
          Object Oriented Programming 30 min
        • Lecture1.10
          Objects and Classes 30 min
        • Lecture1.11
          Java Inheritance 30 min
        • Lecture1.12
          Static,non-static and final 30 min
        • Lecture1.13
          Abstract Class vs Interface 30 min
        • Lecture1.14
          Overloading vs Overriding 30 min

        Java Operators

        1. Assignment Operator

        You can change the value of a variable in your program by using an assignment statement, which has the general form:

        Syntax: target=expression

        Examples:

        [php]
        a = 10;
        b = a;
        c = (x – 2)/(2 + 2);
        [/php]

        2. Arithmetic Operators

        Arithmetic operators are used for basic mathematical operations.

        + addition
        – subtraction
        * multiplication
        / division
        % modulus

        [php]
        public class ArithmeticExample {
        public static void main(String[] args) {
        int num1, num2, add, sub, multi, div, modu;
        num1 = 5;
        num2 = 2;
        add = num1 + num2;
        sub = num1 – num2;
        multi = num1 * num2;
        div = num1 / num2;
        modu = num1 % num2;
        System.out.println("Addition = " + add);
        System.out.println("Subtraction = " + sub);
        System.out.println("Multiplication = " + multi);
        System.out.println("Division = " + div);
        System.out.println("Modulus = " + modu);
        }
        }
        [/php]

        Download Code Here

        3. Relational Operators

        There are six relational operators that compare values of other types and produce a boolean result:

        < Less than <= Less than or equal to
        > Greater than >= Greater than or equal to
        == Equals != Not equals

        [php]
        public class RelationalExample {
        public static void main(String args[]) {
        int a, b, c;
        a = 1;
        b = 2;
        System.out.println("a = " + a);
        System.out.println("b = " + b);
        System.out.println("a < b is " +( a<b)); System.out.println("a > b is " +( a>b));
        System.out.println("a == c is " +( a==c));
        System.out.println("a <= c is " +( a<=c)); System.out.println("a >= b is " +( a>=b));
        System.out.println("b != c is " +( b!=c));
        System.out.println("b == a+c is " +( b==a+c));
        }
        }
        [/php]

        Download code here

        4. Logical Operators

        There are three logical operators in Java, these are.

        && and
        || or
        ! not

        [php]
        public class LogicalExample {
        public static void main(String args[]) {
        boolean a = true;
        boolean b = false;
        System.out.println("a && b = " + (a&&b));
        System.out.println("a || b = " + (a||b) );
        System.out.println("!(a && b) = " + !(a && b));
        }
        }
        [/php]


        Download code here

        5. Increment and Decrement Operator

        The ++ and — are increment and decrement operator in java, respectively.

        The increment operator increase its operand by one. The decrement operator decreases its operand by one. By using increment operator we can write

        x = x+1; as x++;

        Both have the same meaning. In the same way, the statement:

        x = x-1; as x--;

        [php]
        public class IncrementOperator {
        public static void main (String args[]) {
        int a = 1;
        int b = 2;
        int c;
        int d;
        c = ++b;
        d = a++;
        c++;
        System.out.println("a = " + a);
        System.out.println("b = " + b);
        System.out.println("c = " + c);
        System.out.println("d = " + d);
        }
        }
        [/php]

        Download code here

        6. Compound Assignment Operators

        These are also called the Shorthand operators because it somewhat simplify the use of the operators and the assignment operation.

        += Assignment by Additional
        -= Assignment by subtraction
        *= Assignment by multiplication
        /= Assignment by division
        %= Assignment by modulus

         

        [php]
        public class ArithAssignOperator
        {
        public static void main(String[] args)
        {
        int a = 10, b = 15, c = 15;
        System.out.println("Arithmeic Assignment operators");
        System.out.println(" Addition = " + (a += b));
        System.out.println(" Subtraction = " + (c -= b));
        System.out.println(" Division = " + (a /= 2));
        System.out.println(" Multiplication = " + (a *= 2));
        }
        }
        [/php]

        Download code here

        Prev Java Comments
        Next Java Loop Control

        Leave A Reply Cancel reply

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

        All Courses

        • JAVA TECHNOLOGIES

        Latest Courses

        Core Java

        Core Java

        Free
        JDBC

        JDBC

        Free
        logo-eduma-the-best-lms-wordpress-theme

        contactus@tech2our.com

        Company

        • About Us
        • Blog
        • Contact

        Links

        • Courses
        • Events
        • FAQs

        Support

        • Documentation
        • Forums
        • Language Packs

        Copyright © 2012-2017 Tech2Our.com. All Rights Reserved.

        • Privacy
        • Terms
        • Sitemap