string handling :: futureX


String comparison:


There are three ways to compare String objects:


  • By equals() method
  • By = = operator
  • By compareTo() method



By equals() method:

equals() method compares the original content of the string.It compares values of string for equality.String class provides two methods:


public boolean equals(Object another){}
compares this string to the specified object.

public boolean equalsIgnoreCase(String another){}
compares this String to another String, ignoring case.


class Simple{
 public static void main(String args[]){

   String s1="salman";
   String s2="salman";
   String s3=new String("salman");
   String s4="shahrukh";

   System.out.println(s1.equals(s2));//true
   System.out.println(s1.equals(s3));//true
   System.out.println(s1.equals(s4));//false
 }
}


By == operator:

The = = operator compares references not values.


class Simple{
 public static void main(String args[]){

   String s1="Sachin";
   String s2="Sachin";
   String s3=new String("Sachin");

   System.out.println(s1==s2);//true (because both refer to same instance)
   System.out.println(s1==s3);//false(because s3 refers to instance created in nonpool)
 }
}


By compareTo() method:

compareTo() method compares values and returns an int which tells if the values compare less than, equal, or greater than.

Suppose s1 and s2 are two string variables.If:

s1 == s2          :0
s1 > s2            :positive value
s1 < s2            :negative value


class Simple{
 public static void main(String args[]){

   String s1="Sachin";
   String s2="Sachin";
   String s3="Ratan";

   System.out.println(s1.compareTo(s2));//0
   System.out.println(s1.compareTo(s3));//1(because s1>s3)
   System.out.println(s3.compareTo(s1));//-1(because s3 < s1 )
 }
}


String Concatenation:



There are two ways to concat string objects:


  • By + (string concatenation) operator
  • By concat() method


 By + (string concatenation) operator

String concatenation operator is used to add strings.

For Example:

class Simple{
 public static void main(String args[]){

   String s="Sachin"+" Tendulkar";
   System.out.println(s);//Sachin Tendulkar
 }
}


The compiler transforms this to:

String s=(new StringBuilder()).append("Sachin").append(" Tendulkar).toString();

String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method.String concatenation operator produces a new string by appending the second operand onto the end of the first operand.The string concatenation operator can concat not only string but primitive values also.

For Example:

class Simple{
 public static void main(String args[]){

   String s=50+30+"Sachin"+40+40;
   System.out.println(s);//80Sachin4040
 }
}


If either operand is a string, the resulting operation will be string concatenation. If both operands are numbers, the operator will perform an addition.


 By concat() method

concat() method concatenates the specified string to the end of current string.

Syntax : public String concat(String another){}

class Simple{
 public static void main(String args[]){

   String s1="Sachin ";
   String s2="Tendulkar";

   String s3=s1.concat(s2);

   System.out.println(s3);//Sachin Tendulkar
  }
}

Substring:



You can get substring from the given String object by one of the two methods:
       

public String substring(int startIndex)

This method returns new String object containing the substring of the given string from specified startIndex (inclusive).

public String substring(int startIndex,int endIndex):

This method returns new String object containing the substring of the given string from specified startIndex to endIndex.

In case of string

startIndex    :starts from index 0(inclusive).
endIndex      :starts from index 1(exclusive).

class Simple{
 public static void main(String args[]){

   String s="Sachin Tendulkar";
   System.out.println(s.substring(6));//Tendulkar
   System.out.println(s.substring(0,6));//Sachin
 }
}



                                                             JAVA TUTORIALS HOMEPAGE

GENERAL

2G Network GSM 850 / 900 / 1800 / 1900 - C6602, C6603
3G Network HSDPA 850 / 900 / 2100 - C6603
                  HSDPA 850 / 900 / 1700 / 1900 / 2100 - C6602
4G Network LTE 800 / 850 / 900 / 1800 / 2100 / 2600 - C6603
SIM                 Micro-SIM
Announced 2013, January
Status         Coming soon. Exp. release 2013, March


BODY

Dimensions 139 x 71 x 7.9 mm (5.47 x 2.80 x 0.31 in)
Weight         146 g (5.15 oz)
                  - IP57 certified - dust and water resistant
                        - Water proof up to 1 meter and 30 minutes

sony xperia z body :: futureX


DISPLAY

Type         TFT capacitive touchscreen, 16M colors
Size                 1080 x 1920 pixels, 5.0 inches (~441 ppi pixel density)
Multitouch Yes, up to 10 fingers
Protection Shatter proof and scratch-resistant glass
                   - Timescape UI
                         - Sony Mobile BRAVIA Engine 2


sony xperia Z display :: futureX 

SOUND

Alert types Vibration; MP3 ringtones
Loudspeaker Yes
3.5mm jack Yes


MEMORY

Card slot microSD, up to 32 GB
Internal 16 GB, 2 GB RAM


DATA

GPRS         Up to 107 kbps
EDGE         Up to 296 kbps
Speed         HSDPA, 42 Mbps; HSUPA, 5.8 Mbps; LTE, Cat3, 50 Mbps UL, 100 Mbps DL
WLAN         Wi-Fi 802.11 b/g/n, Wi-Fi Direct, DLNA, Wi-Fi hotspot
Bluetooth Yes, v4.0 with A2DP
NFC         Yes
USB                 Yes, microUSB v2.0 (MHL)


CAMERA

Primary 13.1 MP, 4128x3096 pixels, autofocus, LED flash
Features Geo-tagging, touch focus, face detection, image stabilization, HDR, sweep panorama
Video Yes, 1080p@30fps, continuous autofocus, video light, video stabilizer, HDR
Secondary Yes, 2.2 MP, 1080p@30fps


FEATURES

OS Android OS, v4.1.2 (Jelly Bean), planned upgrade to v4.2 (Jelly Bean)
Chipset Qualcomm MDM9215M / APQ8064
CPU         Quad-core 1.5 GHz Krait
GPU Adreno 320
Sensors Accelerometer, gyro, proximity, compass
Messaging SMS (threaded view), MMS, Email, IM, Push Email
Browser HTML5
Radio Stereo FM radio with RDS
GPS         Yes, with A-GPS support and GLONASS
Java Yes, via Java MIDP emulator
Colors Black, White, Purple
          - SNS integration
                - TV-out (via MHL A/V link)
                - Active noise cancellation with dedicated mic
                - MP4/H.263/H.264/WMV player
                - MP3/eAAC+/WMA/WAV/Flac player
                - Document viewer
                - Photo viewer/editor
                - Voice memo/dial
                - Predictive text input

sony Xperia Z :: futureX 

BATTERY  

Non-removable Li-Ion 2330 mAh battery

Stand-by         Up to 550 h (2G) / Up to 530 h (3G)
Talk time Up to 11 h (2G) / Up to 14 h (3G)
Music play Up to 40 h
HTML Headings

HTML Headings

Headings are defined with the <h1> to <h6> tags.

<h1> defines the most important heading. <h6> defines the least important heading.

Example

<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>


Note: Browsers automatically add some empty space (a margin) before and after each heading.

Importance of Headings

Use HTML headings for headings only. Don't use headings to make text BIG or bold.Search engines use your headings to index the structure and content of your web pages.
               Since users may skim your pages by its headings, it is important to use headings to show the document structure.

H1 headings should be used as main headings, followed by H2 headings, then the less important H3 headings, and so on.



HTML Lines


The <hr>tag creates a horizontal line in an HTML page.

The hr element can be used to separate content:

Example

<p>This is a paragraph</p>
<hr><p>This is a paragraph</p>
<hr><p>This is a paragraph</p>


example of heading and lines :: futureX



HTML Comments


Comments can be inserted into the HTML code to make it more readable and understandable. Comments are ignored by the browser and are not displayed.

Comments are written like this:

Example

<!-- This is a comment -->

Note: There is an exclamation point after the opening bracket, but not before the closing bracket.



« Previous Chapter                                                                                                                                          Next Chapter »


String Handling in java

In java, string is basically an immutable object. We will discuss about immutable string later. Let's first understand what is string and how we can create the string object.

Generally string is a sequence of characters. But in java, string is an object. String class is used to create string object.


There are two ways to create String object:


  • By string literal
  • By new keyword



By String Literal :
String literal is created by double quote.
For Example:

String s="Hello";


Each time you create a string literal, the JVM checks the string constant pool first. If the string already exists in the pool, a reference to the pooled instance returns. If the string does not exist in the pool, a new String object instantiates, then is placed in the pool.For example:


String s1="Welcome";
String s2="Welcome";//no new object will be created


In the above example only one object will be created.First time JVM will find no string object with the name "Welcome" in string constant pool,so it will create a new object.Second time it will find the string with the name "Welcome" in string constant pool,so it will not create new object whether will return the reference to the same instance.

String objects are stored in a special memory area known as string constant pool inside the Heap memory.

Why java uses concept of string literal?

To make Java more memory efficient (because no new objects are created if it exists already in string constant pool).


By new Keyword :

String s=new String("Welcome");//creates two objects and one reference variable


In such case, JVM will create a new String object in normal(non pool) Heap memory and the literal "Welcome" will be placed in the string constant pool.The variable s will refer to the object in Heap(non pool).



Immutable String:

In java, strings are immutable (unmodifiable) objects.For example


class Simple{
 public static void main(String args[]){

   String s="Sachin";
   s.concat(" Tendulkar");//concat() method appends the string at the end
   System.out.println(s);//will print Sachin because strings are immutable objects
 }
}


Output: Sachin


As you can see in the above figure that two objects will be created but no reference variable refers to "Sachin Tendulkar".But if we explicitely assign it to the reference variable, it will refer to "Sachin Tendulkar" object.For example:


class Simple{
 public static void main(String args[]){

   String s="Sachin";
   s=s.concat(" Tendulkar");
   System.out.println(s);
 }
}


Output: Sachin Tendulkar


Why string objects are immutable in java?

Because java uses the concept of string literal.Suppose there are 5 reference variables,all referes to one object "sachin".If one reference variable changes the value of the object, it will be affected to all the reference variables. That is why string objects are immutable in java.


                                           JAVA TUTORIALS HOMEPAGE

HTML Attributes :: futureX

Attributes provide additional information about HTML elements.


HTML Attributes:


  • HTML elements can have attributes
  • Attributes provide additional information about an element
  • Attributes are always specified in the start tag
  • Attributes come in name/value pairs like: name="value"

Example:

HTML links are defined with the <a> tag. The link address is specified in the href attribute:


<a href="http://www.futurextech.blogspot.com">This is a link</a>


Attribute values should always be enclosed in quotes.

Double style quotes are the most common, but single style quotes are also allowed.

In some rare situations, when the attribute value itself contains quotes, it is necessary to use single quotes: name='John "Alfred" Nelson'


HTML Tip: Use Lowercase Attributes

Attribute names and attribute values are case-insensitive.

However, the World Wide Web Consortium (W3C) recommends lowercase attributes/attribute values in their HTML 4 recommendation.

Newer versions of (X)HTML will demand lowercase attributes.



« Previous Chapter                                                                                                                                          Next Chapter »



Copyright © 2013 futureX | Blogger Template by Clairvo