Java basic knowledge, do you really know it


Java basic knowledge

  • Math.round (VaR);   for rounding
  • If (1) is not allowed in Java, C / C + + can.
  • Void is also one of the basic data types.
  • All basic data types have an initial value of 0 or 0.0, and the initial value of reference type is null.
  • This can only be used inside a method to represent a reference to “the object calling this method.”.
  • This can also call other constructors, such as this (a, b); but it can only be used once and placed in the first line of the method.
  • Static can be understood simply. It is global and has only one copy. It is initialized only once when the class is loaded. There is no this. You can’t directly call non static variables or methods (you can refer to parameters and then create new objects in them).
  • Variable parameters… Principle: compiler help package into an array.
  • Package name must be all lowercase letters.
  • The default modifier visibility is only available in the current package.
  • Protected visibility in the current package and all subclasses. See another person’s blog: access modifier protected
  • A file can only have one public class. (public interface)
  • Tostring() method. The base class is object. When the compiler needs string and you only have objects, tostring() will be called.
  • Final keyword:

    • Variable: unchangeable constant
    • Parameter: the object to which the reference refers cannot be changed within a method.
    • Method: override is not allowed in subclasses. (private adds final by default, which cannot be inherited and cannot be overridden naturally)
    • Class: not inheritable.
  • An internal class, which potentially inherits a class or interface, is an upload type.
  • Finalize() method, a class can have this method (object’s method) for JVM to recycle, but it can’t be called directly!
  • System.gc (); used to recycle runtime.
  • Initialization sequence:

Parent static variable — parent static code block — subclass static variable — subclass static code block — parent non static variable (and parent non static code block) — parent constructor — subclass non static variable (and subclass non static code block) — subclass constructor

Pithy formula:
First static, then non static (including constructors).
First parent class, then child class.
First variable, then code block.
Note:Class loading process, first load all static, in theCreating subclass objectsNon static will be loaded only when.That is to say, the parent class and the child class will not be initialized statically until the child class object is created.In addition, when multiple inheritance relationships occur, they will recurse to the root first, and then return to execution.

  • Enum:
public enum name{

Class: values(), returns an array
Non static method: ordinal(), returns declaration order

GC adaptive algorithm

  • reference counting : if the object has a reference connection, the counter will be + 1; if the object is disconnected, it will be minus 1. When the counter is 0, recycle is started.
  • Stop copy(copy and stop): pause the program first and move the “live” objects in the heap to another heap.
  • Mark scan(mark and swap): the same way to pause a program is to find all the “live” objects, mark them, and then clean up the unmarked objects after marking.

Java basic knowledge, do you really know it
Adaptive, generational, stop copy, mark scan garbage collection period….

JIT (just in time) compiler: compiles programs into machine code to improve program speed.

There are two strategies for class loading

  1. Let JIT compile all the code. Disadvantages: expansion machine code is much larger than byte code, resulting in slow program speed.
  2. Lazy evaluation: let JIT work when necessary, and never compile code that never executes.

Hotspot uses a technology similar to method 2 for optimization. Put the class bytecode and machine code into the cache, the more times of execution, the faster.

Recommended Today

Review of SQL Sever basic command

catalogue preface Installation of virtual machine Commands and operations Basic command syntax Case sensitive SQL keyword and function name Column and Index Names alias Too long to see? Space Database connection Connection of SSMS Connection of command line Database operation establish delete constraint integrity constraint Common constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT […]