HOME FORUM BLOGS CONTACT LINKS FEEDBACK LOGIN REGISTER
 

JAVA DEVELOPER SITE - COMPLETE JAVA TUTORIALS

Java Operators like arithmatic,addtion,subtraction,multiplication,shift



Newly Added TutorialNewly Added Tutorial


Java Exception Handling
Factory Design Pattern
Thread Creation in Java
Read a File in Java
Convert List to Array
Read Excel in Java
Setting thread priorities
Method Invocation Using Reflection
Ajax Basics
Stateless Session Beans Callback
Ajax Autocomplete in Java
Hello World Java
Hello World Java
Decision Table
Object Serialization
Singleton Pattern
Java Heap Size
Set Heap Size Eclipse
OutofMemory Exception in Java
Axis Web Services
Java C++ Difference
SOA Tutorials
Filenet Platform BPM
Eclipse Tips & Tricks
enterprise service bus (ESB)
Enterprise Application Integration (EAI)

JAVA Tutorials

Collection Framework
Operators in Java
If-else Statement

Thread
File
Generics
Input-Output in java
File Stream
Java Methods
Java Arrays
Java Objects
Java Exception Handling
Java Inheritance Tutorial
Java Threads
Garbage collection

J2EE Tutorials

Servlets Tutorials
Introduction to Struts Framework
JSP Tutorials
SPRING Framework Tutorials
STRUTS Tutorials
HIBERNATE Tutorials
WEB-SERVICES Tutorials

Java Collections

MAP
SET
LIST
VECTOR

Advanced Java

Stateless Session Bean
Introduction to EJB
Stateful Session Bean
Java Design Patterns

BRMS Tutorial

ILOG
BLAZE ADVISOR
PEGA
Drools
BRMS
BPM
JRules for .NET
ilog jrules interview questions
ilog jrules certification dumps
Java Certification Study Guide
hibernate tutorial
hello world struts example

All Tutorial

php mysql tutorial
SCJP 1.5/1.6
SCWCD 1.5/1.6
Polymorphism
Thread Tutorial
Generics & Exceptions
Spring Struts Hibernate

 
 
 

Useful Java Links




Operators
Operators are the symbols defining a certain operation to be performed.

Assignment Operators
An assignment operator assigns a value to a certain variable after evaluating the expression to be assigned.

The assignment operator, "=", sets the variable on its left equal to the value on its right. This code creates the variable a and sets it equal to 5

int a;
a = 5;

Fairly simple, right? Here is where it can get a slightly more tricky.

int a;
int b;
b = 6;
a = b; //a equals 6

At first glance, you might think that the last statement is setting a equal to the letter "b", but instead it is setting a equal to the value of b, which is 6. Essentially, a holds the value of 6. You can also set a variable and declare it on the same line:

int a = 6;

However, you cant say char myChar = y; to set a character to "y" That would set the character variable myChar to the value stored in the character variable y. To set myChar equal to the character y, use a character literal — a technical term for "a character in single-quotes": char myChar = "y";. Note that a char primitive can only hold a single character. char myChar = "Yo"; is illegal.

Finally, whats so special about floats and doubles? Doubles and floats can have decimals: float myFloat = 5.1;. (The term "float" is short for "floating-point number," referring to the decimal point.)

Now, why would you want to set a variable? You would need to set a variable for further use, i.e., to access at a later time.

Addition Operator +
The addition operator returns the sum of the the values to the left, and the value to the right of it.

If you want to evaluate the expression 23 plus 75, you would type:

23+75

The addition operator also works with variables:

myInt+yourInt

Note, this operator is not to be confused with the concatenation operator, which we will discuss later.

Subtraction -, multiplication *, division /, and modulus %operators
Just like the addition operator, the subtraction, multiplication, division, and modulus operators are used as follows:

int a = 9;
 
a-1; // evaluates to 8
a/3; // evaluates to 3
a*2; // evaluates to 18
a%4; // evaluates to 1

Subtraction, multiplication, and division, you have seen before, but the modulus operator is much less commonly used. Actually, it is commonly used, but is known under a different name, the remainder. Nine divided by four gives a remainder of one, so therefore 9%4 (pronounced "9 mod 4") evaluates to 1.

When more than one of the operators are used in the same statement, for example:

int a, b, c, d;
a = a-b/c*d;

the Java language would use the order-of-operations in this case.

Plus-equals
The plus-equals operator ("+=") adds the value on the right, to the variable on the left, and then assigns that value back into the variable on the left.

Example:

int a = 6; // assigns the value 6 to variable a
a += 5; // adds 5 to a, and assigns that value back into a, now a is 11

Minus-equals, multiply-equals, divide-equals, and mod-equals
Minus-equals, multiply-equals, divide-equals, and mod-equals works in the same way as plus-equals, except instead of addition, they do subtraction, multiplication, division, and modulus, respectively.

Concatenation operator
The concatenation operator (+) looks exactly like the addition operator, however it performs a different operation. The concatenation operator concatenates or "puts together," for lack of a better term, two Strings.

String myString = "Hello, ";
String yourString = "world.";
String ourString = myString + yourString; // evaluates to "Hello, world."

 



If you need any urgent assistance on Operators, kindly email your requirement to us at : info@javagenious.com or Contact-an-Expert. Our experts will try their best to solve your problem.

Keyword Tags: Operators tutorial,Operators in java,Concepts of Operators,Java,J2EE,Interview Questions,Operators Examples


Java Virtual Machine (JVM)

Most programming languages compile source code directly into machine code, suitable for execution on a particular microprocessor architecture. read more


Java Related Discussions

 
Javagenious.com

Interview Questions
Placement Papers
FAQs on J2EE
FAQs on JNDI
XML-Tutorials
Remote Web Services
Exception-Handling
JMS Tutorials
seam richfaces tutorial
richfaces live demo
jquery example demo
JQuery Tutorial and Source Code
JSF Tutorial
XSL Tutorial
J2EE JMS
CORBA Applications
Java CERTIFICATION
SCJP 1.5
SCJP 1.6
SCWCD 1.5
SCBCD
Mis
Ajax autosuggest autocomplete from database
Struts forms and validation with webflow
Java Apache POI Examples
JDBC Tutorial

Oracle
MYSQL Tutorial
php Tutorial
JQuery Examples
JQuery Tuorial
Upload Java File
JAXB Examples
PL-SQL Tutorial
Dojo AJAX
EJB Examples
Java IDE
Eclipse
NetBeans
IBM Rational Weblogic Workshop
Downloads
SCJP 1.6 Dumps
SCJP 1.5 DUMP
SCJP Material
SCWCD
Java Security
SCBCD Dumps
External Links
SUN Java
JOracle
Bea Weblogic
IBM
PHP Certification
Technical Interview Questions
Amazon Interview Questions
Google Interview Questions
Microsoft Interview Questions
IBM Interview Questions
Yahoo Interview Questions
HOME | FORUM | ABOUT | BLOGS | CONTACT-US