Home arrow Java & J2EE arrow Page 2 - Java Operators

Assignment Operators - Java

It's been about a month or so since we finished our beginning Java series, so I'm sure you're ready for more. This time, I am going to teach you to work with operators in Java. When I am finished, you will be able to do complex mathematical equations, add one string of text to another, and build programs so powerful you will be able to put thousands of hard working Americans out of work with the push of a button.

  1. Java Operators
  2. Assignment Operators
  3. Doing More Math with Assignment Operators
  4. Forming a Relationship with Operators
By: James Payne
Rating: starstarstarstarstar / 21
October 22, 2007

print this article



Variables with no data are just like frosty cold mugs with no soda in them --worthless. Sure, your girlfriend could throw them at you when you forget to take out the garbage or mention how pretty her sister looks. But when mugs and variables were invented, it was because their creator wanted an object that would hold something. In the case of mugs, it's beer, and in the case of variables, it's data. That's where certain kinds of operators come in.

To fill a variable with data, you use one of the assignment operators, the simplest of which is the = symbol.

my_iQ = 250;

The above code assigns the value 250 to my_iq (I didn't want to be boastful, so I lowered the amount). If I later decided what the heck, why not be boastful, I could always do this:

my_iq = 250;

my_iq = my_iq + 50;

This would first assign the value 250 to my_iq, then add 50 to the value of my_iq, leaving it at 300, which is what it truly is (wink wink). A simpler way to write the above code is like this:

my_iq = 50;

my_iq += 50;

If I were drinking the night before, I could also use the subtraction assignment operator to show my true IQ:

my_iq = 300;

my_iq -= 250;

The code above would show that alcohol has reduced my monstrous IQ to a feeble 50.

If you are working with text or strings, you could do the following:

class MyName {

public static void main(String[] args){

String first_name = “James”;

String second_name = “Payne”;

String full_name = first_name + second_name;




The above sample will print out the text: “James Payne” to your monitor.

>>> More Java & J2EE Articles          >>> More By James Payne

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates


Dev Shed Tutorial Topics: