Common variables in jsp

Source: Internet
Author: User

In the jsp tutorial, there are five definitions of variables: Local range, page range, request range, session range, and application range ).

The following describes variable access methods in various technologies.


Dynamic initialization variable

Public class mainclass {
Public static void main (string args []) {
Double a = 3.0, B = 4.0;

// C is dynamically initialized
Double c = math. sqrt (a * a + B * B );

System. out. println ("hypotenuse is" + c );
  }
}

Variable generation time

Public class mainclass {
Public static void main (string args []) {
Int x;

For (x = 0; x <3; x ++ ){
Int y =-1; // y is initialized each time block is entered
System. out. println ("y is:" + y); // this always prints-1
Y = 100;
System. out. println ("y is now:" + y );
    }
  }
}


Demonstrate how to use the correct method to declare a class variable called hellomessage

 

Public class mainclass
{
Static string hellomessage;

Public static void main (string [] args)
    {
Hellomessage = "hello, world! ";
System. out. println (hellomessage );
    }
}

Static variables
Before variables or methods, it indicates they belong to the class;
Static variables are shared among instances. If they are public static variables, other classes can access them without instantiation;
Static methods are called class methods, so they can be called without instantiation (process-oriented)
Methods of an object can access data members of an object, although they are not local variables of the method. Methods of a class can only access their own local variables.

 

Public class mainclass
{
Public static void main (string [] args)
    {
Hellomessage = "hello, world! ";
System. out. println (hellomessage );
    }

Static string hellomessage;
}

Local variable instance

Public, protected, and private modifiers for variables and methods:
Public: any other class or object that can see this class can access the data of the variable or use the method.

Public class mainclass
{
Public static void main (string [] args)
    {
String hellomessage;
Hellomessage = "hello, world! ";
System. out. println (hellomessage );
    }
}

Related Article

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.