Create a class, define two variables in the class, specify the initial value for them, and then exchange the values of the two variables. The third variable is not allowed, only an exception or operation can be used to exchange two variable values.
Import java. util. required; public class VariableExchange {public static void main (String [] args) {System. out.
One, variable:An instance variable is declared in a class and is not assigned a value, and there is an initial value.Cases:Integers 0Floating points 0.0Booleans falseReferences nullA local variable is declared in a method and is not assigned a value and does not have an initial value. Compile will error!Ii. Comparison of variablesUse = = to compare two primitive master data types, or to determine whether two references refer to the same object.Use Equals () to determine whether two objects are e
1. Member variablesdefined in the class to describe what the object will be.2. Local VariablesDefined in a method of a class to temporarily save data in a method.There are different scopes for member variables and local variables:The scope of a local variable is limited to the method that defines itThe scope of the member variable is visible throughout the interiorThe initial values are different:Java will give the member variable an initial valueJava
In the process of web development, it is unavoidable to read some custom JVM system variables or environment variables. For example, define some common log files. Or a database access path.We can use System.getproperties () to read all system variables. by System.getproperty ("name"); Get specific system variablesSystem.getenv (); Gets the environment variable. S
Class variables, class methods, instance variables, and instance methods in javaBefore understanding the class variables and class methods, read the following code:Class person {int age; string name; static int totalfee; public void showname () {system. out. print (this. name);} public static void showtotalloud () {system. out. print (total.pdf );}}Three
member VariablesMember variables do not need to be initialized, and as long as a class attribute or instance property is defined for a class, the system initializes the default during the preparation phase of the class or when an instance of the class is created, and the assignment rule for the member variable is initialized identically to the array element when the array is dynamically initialized.initialization of member
two times while (true) { System.out.println ("Hello number:" + i++); Try { thread.sleep ((Long) math.random () *); } catch (interruptedexception e) { e.printstacktrace (); } if (= = i) {break ;}}} }As noted in the note, because local variables have their own copy of the shell for each thread
Java_home
Variable name: Java_home
Variable Value: E:\java\jdk7
Purpose: Define a variable for use elsewhere
PATH
Variable name: Path
Variable value:%java_home%\bin;%java_home%\jre\bin;
Purpose: To allow the system to identify Java, Javac, JAVAP, and other commands under any path
CLASSPATH
Variable name: CLASSPATH
Variable value:.; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar;
Purpose: Tells the
Member variables:A: Outside the class methodB: In heap memoryC: As the object is created, it is destroyed as the object disappearsD: There is a default initialization valueLocal variables:A: In the method definitionB: In the occupied memoryC: As the method is called, it is destroyed as the call to the method is completeD: Value not initialized, must be defined and assigned before useBenefits of Anonymous invocation:After the call is complete, garbage can be reclaimed by garbage collector.Java me
The problem arises from the link below (http://bbs.csdn.net/topics/391908395)
public class statictest{public
static void Main (String args[]) {
staticfunction ();
}
static Statictest st = new Statictest ();
static{
System.out.println ("1");
}
Statictest () {
System.out.println ("3");
System.out.println ("a=" +a+ "b=" +b);
}
public static void Staticfunction () {
System.out.println ("4");
}
{
System.out.printl
is not clear in which memory, when running C.run (), is called function, the function of the execution is output num and color variables. Because c is called, C refers to car () in heap memory, and car () has variables num and color loaded according to the description class. When the output is called, it is natural that the data in car () is output. If the run () method already has a defined num, and the m
Variable
The JVM assigns the default value (the default) to the class's instance and static variables, including every element in the array arrays-without having to write the initialization assignment statement again.
Remember: Local variables have no default values and must be initialized manually!
This default assignment process is done before the object's constructor call, and if the program writes an in
Operation Effect:
Console effect:
==================================================
Code section
==================================================
/hello_test/src/com/b510/test/statictest.java
Copy Code code as follows:
/****/Package com.b510.test;/*** The difference when the program is running: the instance variable belongs to the property of an object, and the instance object must be created,* The instance variables will be al
JAVA Learning (III): Basic Java syntax (conversion of variables, constants, data types, operators and data types), java OperatorsBasic Java syntax (conversion of variables, constants, data types, operators, and data types)
1.
is equivalent to the constant that is accessed directly, and does not need to be determined at run time. This is a bit like a macro substitution in C language. So in the preceding section of code, because the variable B is final decorated, it is treated as a compiler constant, so where B is used, the variable b is replaced directly with its value. The access to variable D needs to be linked at run time. Presumably the difference should be understood, but note that the compiler does this only if
In the school training these days, the teacher took us to start a deep review of Java. This is the first day of the content OHFor "Java setting environment variables and running Java programs under DOS", many beginners are unfamiliar, but understanding this is very important for later learning.Http://blog.sina.com.cn/s
1 Overview of this lesson2 Course Overview3 Computer Language Overview4Java Getting Started5JDK Introduction (useful)6 Setting environment Variables (useful)7 writing the first Java programProgram Structure of 8Java9Eclipse Development Tools Overview10 Downloads Eclipse(useful)11Eclipse Development Environment Introduction (useful)12 Creating a Java Project13 Ass
After you have installed the JDK on your computer, let's set up the Java environment to use it. First right click on my Computer. Open the property. Then select "Environment Variables" in "Advanced", the system variables in the new open interface need to set three properties "Java_home", "path", "Classpath", in which the JDK is not installed in the environment. T
when the class is loaded (the first time the class is used) and are often used to initialize static variables.Example code:
Public class Demo {
public static int i;
static{
I = ten;
System. Out. println("Now in Static block.") );
}
public void Test() {
System. Out. println("Test method:i=" + i);
}
public static void main(String[] args) {
System. Out. println("demo.i=" + Demo. I);
New Demo(). Test();
}
}
The operating resu
Variables and constantsIn the program there is a large amount of data to represent the state of the program, some of the data in the course of the program's operation, the value will change, some data in the program during the operation of the value can not be changed, the data in the program is called variables and constants. In the actual program, you can choose whether to use a variable representation or
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.