Yesterday I read a book titled 16 lessons to break through the basic skills of programmers. I personally think it is okay. I mainly gave some in-depth explanations on Java skills, this gives me a new understanding of class initialization and object creation.
I. class initialization
Class initialization: class initialization is generally only performed once, and class initialization is mainly used to initialize static member
Preface because the constructor involves the super keyword and the this keyword. This indicates the reference of the current object, and super indicates the reference of the parent class object in the current object. So before writing the body, let's talk about the Super keyword. Supper1. use super in java to reference the components of the base class: 1) the super keyword is used to implement subclass access to the parent class, because after the sub
variables:void Func (){static int s_value = 0;}A static variable within its scope, which accesses the same variable in multithreaded situations, retains the memory of the static variable because the function call ends, and thus can be used as the location for some dynamic variable return values:const char * func (){string s = "ABCD";static Char msg[256];strcpy (msg, s);return msg;}Cannot directly return s, because it is dynamic; otherwise it will result in a classic memory problem (don't let me
There are 2 main types of main variables in Java:Basic data Types : Byte, short, int, long and float, double, or master data typeAndReference data Types : Arrays, classes, interfaces; Reference variables save the reference only, not the object itself ;Reference passing is the use of a memory, a piece of memory can be used by many people;because the " array is an object " in
Java (2) -- Build and install JDK in the development environment and configure environment variables and jdk Environment Variables
1. Install JDK
Http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
The downloaded jdkis the executable file with the extension name ".exe". Just like instal
I. class initialization
Class initialization: class initialization is generally only performed once, and class initialization is mainly used to initialize static member variables.
Class compilation determines the class initialization process.
The class file generated by the compiler mainly changes the class defined in the source file as follows:
1) Declare the member variables in the class according to the
Variables | optimization
Java programs contain a large number of objects, we need to understand where they are accessed, and where the variables are stored can have a significant effect on the performance of the program-especially if some variables need to be accessed frequently.
We write a
nullSystem.out.println (num); SYSTEM.OUT.PRINTLN (name); } Public voidMethodB (intparam) { //the parameter of the method is the local variableSystem.out.println (param);//parameter is also a local variable, why not assign a value can be output? //because parameters are bound to be assigned when the method is called. Do not pass parameters will be error. intAge ; //System.out.println (age);//An unassigned value cannot be used and must be assigned//System.out.println (num);/
Before the environment variable is configured, executing the Java file with CMD requires that the Java executable be indicated, otherwise it will not run.The environment is configured to facilitate the execution and control of Java programs without having to switch the executable directory.The environment variable is to let the system directly find the executable
static variable, then more than one static variable, the memory overhead ... Especially on mobile phones.In summary, in the UI design to define a singleton mode, feel less reliable, unless there is no sub-component, or to avoid reporting to the child can only has a parent error, to constantly judge whether the children have a father, father, from the father to remove the child (because there is always a static father quoted you).Re-entry into the program, the different manifestations of
Java member variables and local variables
VcD4KPHA + PC9wPgo8aDE + s8nUsbHkwb88L2gxPgo8cD48L3A + cjxwiggfsawdupq = "left"> the member variables do not need to be displayed for initialization. As long as a class defines the class or instance attributes, the system performs default initialization during the prepar
Block B.")); - } to + Public Static voidMain (string[] args) { - NewA ();/* the * static block A. Static block B. Instance block A. Constructor A. * */ $ System.out.println ();Panax Notoginseng NewB ();/* - * Instance block A. Constructor A. Instance block B. Constructor B. the *///static members and static initialization blocks are executed only once. + } A}2, the impact on the value of the variable 2.1, the problemHow does the f
, initialization blocks, and constructors are initialized.What about the sequence between static and static initialization blocks, variables, and initialization blocks? Is the static variable always initialized before the static initialization block, and the variable always initializes before the initialization block? In fact, it depends on the order in which they appear in the class. We describe static variables
JAVA basics/Lesson 1: Teach you how to configure JDK environment variables and jdk Environment Variables
It consists of three steps: Download, configuration, and verification to explain how to configure JDK environment variables.
Jdk.rar direct (copy to address bar): http://how2j.cn/frontdownload? Bean. IDS = 249
Step
Based on relevant posts on the Internet and my own debugging, I have studied static variables, member variables, and the sequence of calling methods for the parent and child classes of the Java inheritance class. First, let's look at a program:
Class X {Y B = New Y (); // 7. initialize the parent class member variable.Static y Sb = New Y (); // 1. Static
Threadlocal is not a thread, but a local variable of thread, and perhaps naming it as threadlocalvariable is easier to understand. Therefore, the code to write thread-local variables in Java is relatively clumsy, resulting in thread-local variables not being well-popularized in Java developers. Threadlocal interface me
local variables and operating mechanism in memoryLocal variables (except formal parameters) must be explicitly initialized before they can be used, the system does not initialize the local variables, that is, after the local variables are defined, the system will not allocate memory space for the variable, until the p
There are two types of class member variables: one is a variable modified by the static keyword, called a class variable or a static variable, and the other is a variable not modified by the static keyword, it is called an instance variable.
The difference between static variables and instance variables is:
1. There is only one static variable of the class in
affect each other//so it prints 100 numbers, 0 to 49 each number is 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
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.