JSP data types and conversion rules

Source: Internet
Author: User
Tags mysql manual

JSP Data Type

There are four basic types:

Int data types include: byte (8 bits), short (16 bits), int (32 bits), long (64 bits ),

Float length data types include: single precision 32 bits float) and double precision 64 bits double)

Values of boolean type variables include true and false.

Char data types include: unicode characters, 16 characters

Corresponding class types: Integer, Float, Boolean, Character, Double, Short, Byte, Long

JSP data type conversion principles

Conversion from low-precision to high-precision

Byte, short, int, long, float, double, and char Note: When two char-type operations are performed, they are automatically converted to the int type. When char and other types are computed, it will be automatically converted to int type before automatic conversion of other types

Convert basic types to class types

Forward conversion: Use the class wrapper to generate a new class type variable.

 
 
  1. Integer a= new Integer(2);  

Reverse conversion: using the class package

 
 
  1. int b=a.intValue();  

Class type conversion to string

Forward conversion: because each class is a subclass of the object class, And all object classes have a toString () function, you can use the toString () function to convert it.

Reverse conversion: a new class type variable is generated through the class package.

 
 
  1. eg1: int i=Integer.valueOf(“123”).intValue()  

JSP data type description: In the above example, a string is converted into an Integer object, and then the intValue () method of this object is called to return the corresponding int value.

 
 
  1. eg2: float f=Float.valueOf(“123”).floatValue()  

JSP data type description: In the above example, a string is converted into a Float object, and then the corresponding float value is returned by calling the floatValue () method of this object.

 
 
  1. eg3: boolean b=Boolean.valueOf(“123”).booleanValue()  

JSP data type description: In the preceding example, a string is converted into a Boolean object, and then the corresponding boolean value is returned by calling the booleanValue () method of this object.

 
 
  1. eg4:double d=Double.valueOf(“123”).doubleValue()  

JSP data type description: In the preceding example, a string is converted into a Double object, and then the corresponding double value is returned by calling the doubleValue () method of this object.

 
 
  1. eg5: long l=Long.valueOf(“123”).longValue()  

JSP data type description: In the preceding example, a string is converted into a Long object, and then the longValue () method of the object is called to return the corresponding long value.

 
 
  1. eg6: char=Character.valueOf(“123”).charValue()  

JSP data type description: In the above example, a string is converted into a Character object, and then the charValue () method of this object is called to return the corresponding char value.

Conversion from basic type to string

Forward conversion of JSP data types:

For example:

 
 
  1. int a=12;   
  2. String b;b=a+””;  

Reverse conversion of JSP data types:

Package through class

 
 
  1. eg1:int i=Integer.parseInt(“123”)  

JSP data type description: This method can only be used to convert strings into integer variables.

 
 
  1. eg2: float f=Float.valueOf(“123”).floatValue()  

JSP data type description: In the above example, a string is converted into a Float object, and then the corresponding float value is returned by calling the floatValue () method of this object.

 
 
  1. eg3: boolean b=Boolean.valueOf(“123”).booleanValue()  

JSP data type description: In the preceding example, a string is converted into a Boolean object, and then the corresponding boolean value is returned by calling the booleanValue () method of this object.

 
 
  1. eg4:double d=Double.valueOf(“123”).doubleValue()  

JSP data type description: In the preceding example, a string is converted into a Double object, and then the corresponding double value is returned by calling the doubleValue () method of this object.

 
 
  1. eg5: long l=Long.valueOf(“123”).longValue() 

JSP data type description: In the preceding example, a string is converted into a Long object, and then the longValue () method of the object is called to return the corresponding long value.

 
 
  1. eg6: char=Character.valueOf(“123”).charValue()  

JSP data type description: In the above example, a string is converted into a Character object, and then the charValue () method of this object is called to return the corresponding char value.

  1. Two JSP Architectures
  2. Analyze JSP Background File Management source code
  3. Solution to Chinese garbled JSP found in MySQL Manual
  4. JSP Chinese garbled Problem description and Solution
  5. How to call JSP to read images from the database and display them on the page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.