IDE extension that lets you fix coding issues before they exist!

Setup is effortless and analysis is automatic for most languages

Self-Hosted

Fast, accurate analysis; enterprise scalability

Why is this an issue?

There is no reason to re-assign a variable to itself. Either this statement is redundant and should be removed, or the re-assignment is a mistake and some other value or variable was intended for the assignment instead.

Noncompliant code example

Compliant solution.

  • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
  • CodeQL overview
  • Writing CodeQL queries
  • CodeQL query help documentation »
  • CodeQL query help for Java and Kotlin »

Self assignment ¶

Click to see the query in the CodeQL repository

Assigning a variable to itself does not have any effect. Therefore, such an assignment is either completely unnecessary, or it indicates a typo or a similar mistake.

Recommendation ¶

If the assignment is unnecessary, remove it. If the assignment indicates a typo or a similar mistake, correct the mistake.

The following example shows part of a method that is intended to make a copy of an existing MotionEvent without preserving its history. On line 8, o.mFlags is assigned to itself. Given that the statement is surrounded by statements that transfer information from the fields of o to the fields of the new event, ev , the statement is clearly a mistake. To correct this, the mFlags value should be assigned to ev.mFlags instead, as shown in the corrected method.

References ¶

Help - Eclipse Platform: Java Compiler Errors/Warnings Preferences .

  • Java Arrays
  • Java Strings
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Spring Boot

java self assignment

  • Explore Our Geeks Community
  • Java Tutorial

Overview of Java

  • Introduction to Java
  • The complete History of Java Programming Language
  • C++ vs Java vs Python
  • How to Download and Install Java for 64 bit machine?
  • Setting up the environment in Java
  • How to Download and Install Eclipse on Windows?
  • JDK in Java
  • How JVM Works - JVM Architecture?
  • Differences between JDK, JRE and JVM
  • Just In Time Compiler
  • Difference between JIT and JVM in Java
  • Difference between Byte Code and Machine Code
  • How is Java platform independent?

Basics of Java

  • Java Basic Syntax
  • Java Hello World Program
  • Java Data Types
  • Primitive data type vs. Object data type in Java with Examples
  • Java Identifiers

Operators in Java

  • Java Variables
  • Scope of Variables In Java

Wrapper Classes in Java

Input/output in java.

  • How to Take Input From User in Java?
  • Scanner Class in Java
  • Java.io.BufferedReader Class in Java
  • Difference Between Scanner and BufferedReader Class in Java
  • Ways to read input from console in Java
  • System.out.println in Java
  • Difference between print() and println() in Java
  • Formatted output in Java
  • Fast I/O in Java in Competitive Programming

Flow Control in Java

  • Decision Making in Java (if, if-else, switch, break, continue, jump)
  • Java if statement with Examples
  • Java if-else
  • Java if-else-if ladder with Examples
  • Loops in Java
  • For Loop in Java
  • Java while loop with Examples
  • Java do-while loop with Examples
  • For-each loop in Java
  • Continue Statement in Java
  • Break statement in Java
  • Usage of Break keyword in Java
  • return keyword in Java
  • Java Arithmetic Operators with Examples
  • Java Unary Operator with Examples

Java Assignment Operators with Examples

  • Java Relational Operators with Examples
  • Java Logical Operators with Examples
  • Java Ternary Operator with Examples
  • Bitwise Operators in Java
  • Strings in Java
  • String class in Java
  • Java.lang.String class in Java | Set 2
  • Why Java Strings are Immutable?
  • StringBuffer class in Java
  • StringBuilder Class in Java with Examples
  • String vs StringBuilder vs StringBuffer in Java
  • StringTokenizer Class in Java
  • StringTokenizer Methods in Java with Examples | Set 2
  • StringJoiner Class in Java
  • Arrays in Java
  • Arrays class in Java
  • Multidimensional Arrays in Java
  • Different Ways To Declare And Initialize 2-D Array in Java
  • Jagged Array in Java
  • Final Arrays in Java
  • Reflection Array Class in Java
  • util.Arrays vs reflect.Array in Java with Examples

OOPS in Java

  • Object Oriented Programming (OOPs) Concept in Java
  • Why Java is not a purely Object-Oriented Language?
  • Classes and Objects in Java
  • Naming Conventions in Java
  • Java Methods

Access Modifiers in Java

  • Java Constructors
  • Four Main Object Oriented Programming Concepts of Java

Inheritance in Java

Abstraction in java, encapsulation in java, polymorphism in java, interfaces in java.

  • 'this' reference in Java
  • Inheritance and Constructors in Java
  • Java and Multiple Inheritance
  • Interfaces and Inheritance in Java
  • Association, Composition and Aggregation in Java
  • Comparison of Inheritance in C++ and Java
  • abstract keyword in java
  • Abstract Class in Java
  • Difference between Abstract Class and Interface in Java
  • Control Abstraction in Java with Examples
  • Difference Between Data Hiding and Abstraction in Java
  • Difference between Abstraction and Encapsulation in Java with Examples
  • Difference between Inheritance and Polymorphism
  • Dynamic Method Dispatch or Runtime Polymorphism in Java
  • Difference between Compile-time and Run-time Polymorphism in Java

Constructors in Java

  • Copy Constructor in Java
  • Constructor Overloading in Java
  • Constructor Chaining In Java with Examples
  • Private Constructors and Singleton Classes in Java

Methods in Java

  • Static methods vs Instance methods in Java
  • Abstract Method in Java with Examples
  • Overriding in Java
  • Method Overloading in Java
  • Difference Between Method Overloading and Method Overriding in Java
  • Differences between Interface and Class in Java
  • Functional Interfaces in Java
  • Nested Interface in Java
  • Marker interface in Java
  • Comparator Interface in Java with Examples
  • Need of Wrapper Classes in Java
  • Different Ways to Create the Instances of Wrapper Classes in Java
  • Character Class in Java
  • Java.Lang.Byte class in Java
  • Java.Lang.Short class in Java
  • Java.lang.Integer class in Java
  • Java.Lang.Long class in Java
  • Java.Lang.Float class in Java
  • Java.Lang.Double Class in Java
  • Java.lang.Boolean Class in Java
  • Autoboxing and Unboxing in Java
  • Type conversion in Java with Examples

Keywords in Java

  • List of all Java Keywords
  • Important Keywords in Java
  • Super Keyword in Java
  • final Keyword in Java
  • static Keyword in Java
  • enum in Java
  • transient keyword in Java
  • volatile Keyword in Java
  • final, finally and finalize in Java
  • Public vs Protected vs Package vs Private Access Modifier in Java
  • Access and Non Access Modifiers in Java

Memory Allocation in Java

  • Java Memory Management
  • How are Java objects stored in memory?
  • Stack vs Heap Memory Allocation
  • How many types of memory areas are allocated by JVM?
  • Garbage Collection in Java
  • Types of JVM Garbage Collectors in Java with implementation details
  • Memory leaks in Java
  • Java Virtual Machine (JVM) Stack Area

Classes of Java

  • Understanding Classes and Objects in Java
  • Singleton Method Design Pattern in Java
  • Object Class in Java
  • Inner Class in Java
  • Throwable Class in Java with Examples

Packages in Java

  • Packages In Java
  • How to Create a Package in Java?
  • Java.util Package in Java
  • Java.lang package in Java
  • Java.io Package in Java
  • Java Collection Tutorial

Exception Handling in Java

  • Exceptions in Java
  • Types of Exception in Java with Examples
  • Checked vs Unchecked Exceptions in Java
  • Java Try Catch Block
  • Flow control in try catch finally in Java
  • throw and throws in Java
  • User-defined Custom Exception in Java
  • Chained Exceptions in Java
  • Null Pointer Exception In Java
  • Exception Handling with Method Overriding in Java
  • Multithreading in Java
  • Lifecycle and States of a Thread in Java
  • Java Thread Priority in Multithreading
  • Main thread in Java
  • Java.lang.Thread Class in Java
  • Runnable interface in Java
  • Naming a thread and fetching name of current thread in Java
  • What does start() function do in multithreading in Java?
  • Difference between Thread.start() and Thread.run() in Java
  • Thread.sleep() Method in Java With Examples
  • Synchronization in Java
  • Importance of Thread Synchronization in Java
  • Method and Block Synchronization in Java
  • Lock framework vs Thread synchronization in Java
  • Difference Between Atomic, Volatile and Synchronized in Java
  • Deadlock in Java Multithreading
  • Deadlock Prevention And Avoidance
  • Difference Between Lock and Monitor in Java Concurrency
  • Reentrant Lock in Java

File Handling in Java

  • Java.io.File Class in Java
  • Java Program to Create a New File
  • Different ways of Reading a text file in Java
  • Java Program to Write into a File
  • Delete a File Using Java
  • File Permissions in Java
  • FileWriter Class in Java
  • Java.io.FileDescriptor in Java
  • Java.io.RandomAccessFile Class Method | Set 1
  • Regular Expressions in Java
  • Regex Tutorial - How to write Regular Expressions?
  • Matcher pattern() method in Java with Examples
  • Pattern pattern() method in Java with Examples
  • Quantifiers in Java
  • java.lang.Character class methods | Set 1
  • Java IO : Input-output in Java with Examples
  • Java.io.Reader class in Java
  • Java.io.Writer Class in Java
  • Java.io.FileInputStream Class in Java
  • FileOutputStream in Java
  • Java.io.BufferedOutputStream class in Java
  • Java Networking
  • TCP/IP Model
  • User Datagram Protocol (UDP)
  • Differences between IPv4 and IPv6
  • Difference between Connection-oriented and Connection-less Services
  • Socket Programming in Java
  • java.net.ServerSocket Class in Java
  • URL Class in Java with Examples

Operators constitute the basic building block of any programming language. Java too provides many types of operators which can be used according to the need to perform various calculations and functions, be it logical, arithmetic, relational, etc. They are classified based on the functionality they provide.

Types of Operators: 

  • Arithmetic Operators
  • Unary Operators
  • Assignment Operator
  • Relational Operators
  • Logical Operators
  • Ternary Operator
  • Bitwise Operators
  • Shift Operators

This article explains all that one needs to know regarding Assignment Operators. 

Assignment Operators

These operators are used to assign values to a variable. The left side operand of the assignment operator is a variable, and the right side operand of the assignment operator is a value. The value on the right side must be of the same data type of the operand on the left side. Otherwise, the compiler will raise an error. This means that the assignment operators have right to left associativity, i.e., the value given on the right-hand side of the operator is assigned to the variable on the left. Therefore, the right-hand side value must be declared before using it or should be a constant. The general format of the assignment operator is, 

Types of Assignment Operators in Java

The Assignment Operator is generally of two types. They are:

1. Simple Assignment Operator: The Simple Assignment Operator is used with the “=” sign where the left side consists of the operand and the right side consists of a value. The value of the right side must be of the same data type that has been defined on the left side.

2. Compound Assignment Operator: The Compound Operator is used where +,-,*, and / is used along with the = operator.

Let’s look at each of the assignment operators and how they operate: 

1. (=) operator: 

This is the most straightforward assignment operator, which is used to assign the value on the right to the variable on the left. This is the basic definition of an assignment operator and how it functions. 

Syntax:  

Example:  

2. (+=) operator: 

This operator is a compound of ‘+’ and ‘=’ operators. It operates by adding the current value of the variable on the left to the value on the right and then assigning the result to the operand on the left. 

Note: The compound assignment operator in Java performs implicit type casting. Let’s consider a scenario where x is an int variable with a value of 5. int x = 5; If you want to add the double value 4.5 to the integer variable x and print its value, there are two methods to achieve this: Method 1: x = x + 4.5 Method 2: x += 4.5 As per the previous example, you might think both of them are equal. But in reality, Method 1 will throw a runtime error stating the “i ncompatible types: possible lossy conversion from double to int “, Method 2 will run without any error and prints 9 as output.

Reason for the Above Calculation

Method 1 will result in a runtime error stating “incompatible types: possible lossy conversion from double to int.” The reason is that the addition of an int and a double results in a double value. Assigning this double value back to the int variable x requires an explicit type casting because it may result in a loss of precision. Without the explicit cast, the compiler throws an error. Method 2 will run without any error and print the value 9 as output. The compound assignment operator += performs an implicit type conversion, also known as an automatic narrowing primitive conversion from double to int . It is equivalent to x = (int) (x + 4.5) , where the result of the addition is explicitly cast to an int . The fractional part of the double value is truncated, and the resulting int value is assigned back to x . It is advisable to use Method 2 ( x += 4.5 ) to avoid runtime errors and to obtain the desired output.

Same automatic narrowing primitive conversion is applicable for other compound assignment operators as well, including -= , *= , /= , and %= .

3. (-=) operator: 

This operator is a compound of ‘-‘ and ‘=’ operators. It operates by subtracting the variable’s value on the right from the current value of the variable on the left and then assigning the result to the operand on the left. 

4. (*=) operator:

 This operator is a compound of ‘*’ and ‘=’ operators. It operates by multiplying the current value of the variable on the left to the value on the right and then assigning the result to the operand on the left. 

5. (/=) operator: 

This operator is a compound of ‘/’ and ‘=’ operators. It operates by dividing the current value of the variable on the left by the value on the right and then assigning the quotient to the operand on the left. 

6. (%=) operator: 

This operator is a compound of ‘%’ and ‘=’ operators. It operates by dividing the current value of the variable on the left by the value on the right and then assigning the remainder to the operand on the left. 

Please Login to comment...

  • nishkarshgandhi
  • chakka_saikiran
  • Java-Operators

Please write us at contrib[email protected] to report any issue with the above content

Improve your Coding Skills with Practice

 alt=

THANKSGIVING SALE! Save upto 50% now through December 7.

Vibrant Publishers LLC

Item added to your cart

All about java assignment operators.

Like every other programming language, Java language also provides a feature called Operators. There are a few types of Operators exist in Java. In this java tutorial, we will focus our learning on Assignment operators.

Assignment Operators exist for assigning a value to a variable in Java. The right side of the operator will be a value and the left side will be the variable that we created. So a general syntax would be as follows:

Simple Assignment Operator:

java self assignment

+= Assignment Operator:

-= assignment operator:, *= assignment operator:, /= assignment operator:.

java self assignment

  • Choosing a selection results in a full page refresh.
  • SET Advisory Board
  • Civil Engineering
  • Computer Engineering
  • Computer Science & Systems
  • Electrical Engineering
  • Information Technology
  • Mechanical Engineering
  • Minor in Applied Computing
  • M.S. in Computer Science & Systems
  • M.S. in Electrical & Computer Engineering
  • M.S. in Information Technology
  • Master of Cybersecurity & Leadership
  • Ph.D. in Computer Science & Systems
  • Graduate Certificate in Software Development Engineering
  • Data Science Certificate
  • Industry Capstone Program
  • Undergraduate Scholarships
  • Graduate Fellowships and Funding
  • CyberCorps®: Scholarship for Service
  • Vicky L. Carwein and William B. Andrews Endowment for Graduate Programs
  • Student Mentors
  • Student Concerns
  • Internships for Credit
  • Courses & Schedule Planning
  • Teaching Resources
  • Community and Technical Colleges Committee
  • Women in Data Science (WiDS) Tacoma @ UW Tacoma

Java Programming Self-Assessment

Newly admitted Computer Science and Systems students begin their programming coursework in either of three courses, depending on experience and skills:

  • TCSS 142, Intro. to Object-Oriented Programming - For students with minimal programming experience or who feel they would benefit from a review of basic concepts
  • TCSS 143, Foundations of Object-Oriented Programming - for students who have taken the equivalent of TCSS 142  and are confident in their mastery of the course material
  • TCSS 305, Programming Practicum - For students who have taken the equivalent of TCSS 143  and are confident in their understanding of object-oriented programming concepts and techniques

Not sure where to start? Take our assessment.

It is important for you to know the level of knowledge required to progress to the next programming course. To help you make an informed decision about where to begin, the following self-assessment exams have been provided. If you have taken the equivalent of TCSS 142, you should take the TCSS 143 assessment test to verify your mastery of the required prerequisite knowledge. Likewise, if you have taken the equivalent of TCSS 143, you should take the TCSS 305 assessment test.

Please make sure to take your time and allow yourself up to one hour. This assessment will only be of value if you make an honest effort.

  • TCSS 143 Self-Assessment Test
  • TCSS 305 Self-Assessment Test

To find out how well you performed, download the answer key:

  • TCSS 143 answer key
  • TCSS 305 answer key

Follow up with an advisor

After you take the exam, you should meet with an academic adviser to discuss the results. Contact SET advising  to make an appointment.

  • Academic advising
  • Academic calendar
  • Schools and programs
  • Study Abroad
  • Teaching and Learning Center
  • Campus Safety
  • Equity & Inclusion
  • Financial Aid
  • Student Life
  • University YMCA Student Center
  • Administration
  • Institutional Research
  • Parking & transportation

IMAGES

  1. Java Assignment Help

    java self assignment

  2. Java Practice Assignment #2

    java self assignment

  3. ICT For All Classes : Java Assignments and Answers

    java self assignment

  4. Assignment Ref.: Java Assignment Help Image sharing

    java self assignment

  5. Java Assignment Help

    java self assignment

  6. Beginners Guide for Java Assignment Writing

    java self assignment

VIDEO

  1. Jambore SH

  2. Please Tell Me About Your Self

  3. My New York City street photography self assignment 2023

  4. Programming in Java || Week 10 Assignment Answers || NPTEL 2023

  5. Fawn java self pathay

  6. A Self-Modifying Java program

COMMENTS

  1. What Is Concrete Class in Java?

    Concrete class in Java is the default class and is a derived class that provides the basic implementations for all of the methods that are not already implemented in the base class.

  2. Java Developer Course Online for Free: Where to Start

    Java is one of the most popular programming languages in the world, and a career in Java development can be both lucrative and rewarding. However, taking a Java developer course online for free can be a challenge. With so many options avail...

  3. Common Mistakes to Avoid When Downloading Free Java Software

    Java is a popular programming language widely used for developing a variety of applications and software. If you are looking to download free Java software, it is important to be cautious and aware of some common mistakes that many people m...

  4. Self assign in constructor of java

    3 Answers 3 ... No, it is not possible. this and reza represent different objects; you cannot replace the object being created in a constructor

  5. Java static code analysis: Variables should not be self-assigned

    There is no reason to re-assign a variable to itself. Either this statement is redundant and should be removed, or the re-assignment is a mistake and some

  6. Self assignment

    Assigning a variable to itself does not have any effect. Therefore, such an assignment is either completely unnecessary, or it indicates a

  7. Java Assignment Operators with Examples

    Simple Assignment Operator: The Simple Assignment Operator is used with the “=” sign where the left side consists of the operand and the right

  8. Self-Assignment Inside the Constructor

    Self assign in constructor of java, Assign function arguments to `self`, Assignment operator.

  9. What is += Addition Assignment Operator in Java?

    x += y in Java is the same as x = x + y. It is a compound assignment operator. Most commonly used for incrementing the value of a variable since

  10. Java self-assessment tool

    Java self-assessment tool. Take this 2 minute quiz to see if you are leveraging the many tools, features and assets that can help you get the most from your

  11. What happens when you assign an object to itself in Java?

    Can we assign one object to another in Java? Yes we can ... Now both of your virtual self will play independently of each other within a game.

  12. All About Java Assignment Operators

    And the java string variable 'name' has been assigned the value 'This is awesome!”. Apart from simple assignment operations, java developers use

  13. Java Programming Self-Assessment

    Java Programming Self-Assessment · TCSS 142, Intro. to Object-Oriented Programming - For students with minimal programming experience or who feel they would

  14. Self Assessment ( ANSWERS )

    Self Assessment ( ANSWERS ) | Programming using Java | INFYTQ.