String addition and Special Operators in Java.

In this article, String addition and Special Operators in Java are explained in detail with examples.
This operator is '+'. It is used to add or concate two or more string as a single string.
Ex
"Hello"+"World" =>"Helloworld"
It is also used to add a string with any value/variable and form a new string.
Ex
"sum is: "+(a+b)
Here value or variable is of any data type.
// program related to String addition and Special Operators in Java-string addition operator.
class StringAddition
{
public static void main(String args[])
{
String s1="Hello"+"world";
String s2="Hello"+"Beautiful"+"World";
System.out.println(s1+s2);
boolean flag=true;
byte b=10;
short s=100;
int i=1000;
long l=10000l;
float f=5.66f;
double d=3.1456;
char ch='A';
System.out.println("Boolean value is: "+flag);
System.out.println("Byte value is: "+b);
System.out.println("Short value is: "+s);
System.out.println("Int value is: "+i);
System.out.println("Long value is: "+l);
System.out.println("Float value is: "+f);
System.out.println("Double value is: "+d);
System.out.println("char value is: "+ch);
}
}
Output
HelloworldHelloBeautifulWorld
Boolean value is: true
Byte value is: 10
Short value is: 100
Int value is: 1000
Long value is: 10000
Float value is: 5.66
Double value is: 3.1456
char value is: A
String Addition-javaform
                           To get the code file use me.

Special Operators in Java.
These operators are used to perform special operations based on usage.They are two types
  • Dot operator.
  • Instanceof operator.
Dot Operator: This is used to access numbers of a class using object of that class.
Ex
obj.rollno=1001;
obj.name="sai";
obj.display();
It is also used to separate package with sub package, while importing/creating packages.
Ex
import.java.util.*; //importing a package.
import.java.sql.*;
package java.java1; //Creating a new package.
Instanceof operator: This is used to check whether a particular object belongs to that class or not in inheritance. (From topic String addition and Special Operators in Java)
Syntax
(object) instanceof (class name)
It returns "True/false" based on the comparison.
*Instanceof is also a relational operator.
Ex
// program related to String addition and Special Operators in Java-Instanceof operator.
class InstanceofOperator //this program shows how a instance of operator is used.
{
public static void main(String args[])
{
A a=new A();
B b=new B();
C c=new C();
boolean flag;
flag=(a instanceof A);
System.out.println("a instanceof A: "+flag);
flag=(b instanceof B);
System.out.println("b instanceof B: "+flag);
flag=(c instanceof C);
System.out.println("c instanceof C: "+flag);
}
}
class A
{
}
class B
{
}
class C
{
}
Output
Special Operators-Output-javaform
                            To get the code file use me.

Continue to next topic Typecasting in Java.

Begin your career in Digital Marketing,What is digital marketing? Digital Marketing online course. It's an current evolving technology which can give support to establish your own startup through Digital Marketing

 Do check my new startup Surprise Planners in HyderabadLavish Surprises our services are surprise party planners in Hyderabad, surprise giftssurprise birthday party planners Hyderabad, Wedding anniversary surprises, surprise planners Hyderabad.

Hi Friends, Please comment down your views in the comment section below. Thank you...

No comments:

Connect with Us by Subscribing here for more Updates..!

* indicates required