Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Java learning problems encountered     - How to configure security services under Linux (Linux)

- RPM package management tools under Linux (Linux)

- Git Tutorial Comments (Linux)

- Nmcli based network management command-line tool (Linux)

- Network security system (Network)

- The multiplexed signal driving IO (Programming)

- Automated Password Generator: Linux under a special password generator (Linux)

- IOwait Linux system monitoring diagnostic tools (Linux)

- MongoDB3.0.x version of the user authorization profile (stand-alone environment) (Database)

- Loop arrays in C language is not easy to find a bug (Programming)

- Differential test piece using MongoDB performance YCSB (Database)

- Kibana use installation (Linux)

- Bubble Sort Algorithms (Programming)

- Cool Android realization SVG animation (Programming)

- Java Foundation - implicit conversion vs cast (Programming)

- Linux / Unix system-level IO (Linux)

- Automatic Clear date directory shell script (Linux)

- cat command uses the Linux redirection merge files (Linux)

- Type Linux commands (Linux)

- Linux Security Setup Guide (Linux)

  Java learning problems encountered
  Add Date : 2017-08-31      
  First Java generics how to compare the size of the inheritance Comparable class, then the only way to achieve its compareTo ():

1 public class GenericClass < E extends Comparable < E >> {
2 public int com (E e1, E e2) {
3 return e1.compareTo (e2);

Second Java parameters pass by value or reference semantics:

When passed by value means that when a parameter passed to a function, the function receives a copy of the original value. Thus, if a function modifies the parameters, change only the copy, and the original value remains unchanged.

When passed by reference means that when a parameter passed to a function, the function receives a copy of the original value of the memory address, rather than a copy of the value. Thus, if a function modifies the parameter, the calling code of the original value has changed. But the point to the original object reference does not change!

The following from the assignment list of methods and parameters of java two aspects are described as:


When Object type assignment is passed by reference; when the eight basic types (int, long, double, float, byte, boolean, char) object assignment is passed by value;

StringBuffer s = new StringBuffer ( "good");
StringBuffer s2 = s; // passed by reference, s and s2 points to the same memory address
s2.append ( "afternoon!");
System.out.println (s); // good afternoon

int i = 5;
int i2 = i; // passed by value
i2 = 6;
System.out.println (i); // 5

Java method parameter list:

Parameter list, the object type of object is passed by reference, but no matter what kind of operation carried out in vivo method, the argument does not change the reference object;

Eight basic types (int, long, double, float, byte, boolean, char) object is passed by value;

public class test {
    public static void main (String [] args) {
        StringBuilder s = new StringBuilder ( "good"); // good
        StringBuilder s2 = new StringBuilder ( "bad"); // bad
        test (s, s2); // copy passed by reference, but an internal matter test () method of s, the contents of the object pointed to by s2 made what changes to the object pointed to by s2 and s will not change
// Popular point is this: the s and s2 seen as a pointer, a pointer to the contents of an object regardless of the change, s and s2 pointer will not change
        System.out.println (s); // goodhah2, here is the content of the object pointed to by s from the good into the goodhah2
        System.out.println (s2); // bad
    public static void test (StringBuilder s, StringBuilder s2) {
        System.out.println (s); // good
        System.out.println (s2); // bad
        s2 = s; // copy passed by reference
        s = new StringBuilder ( "new"); // s point to a new object
        System.out.println (s); // new
        System.out.println (s2); // good
        s.append ( "hah");
        s2.append ( "hah2");
        System.out.println (s); // newhah
        System.out.println (s2); // goodhah

[to sum up]:

1. Whatever the type of Java parameters that will be passed a copy of the parameters. If Java is passed by value, then passed a copy of the value; if Java is passed by reference, then passed a copy of references.

2. Regardless of the assignment, or java method parameter list, the basic data types are passed by value (a copy), the type of object passed by reference (copy).

Triple comparator. Equals () and == of

1. equals method is to compare the contents of the string, it is more and it points to an object (reference address) are the same for non-string it is.

== Comparison operator whether the object is relatively the same point, that is, objects in memory in the first address.

2. equals method is java.lang.Object class method, Object class equals method is used to compare the "address", but the String class is redefined equals this method, but the comparison is a value, instead of the address.

3. If it is a basic type (byte, short, int, long, float, double, char, boolean) comparison, it can only be used == to compare, you can not use equals ();

4. For basic types of packaging types, such as Boolean, Character, Byte, Shot, Integer, Long, Float, Double, etc. reference variables, == is to compare address, and equals is more content.

5. Note that a basic principle: the definition of a class, if it comes to compare object should override equals () method.

IV. The java heap, stack, constant pool

Stack: eight basic types of data storage and object references, but the object itself is not stored on the stack, but stored in the heap

Heap: new store data generated by the garbage collector is responsible for the

[Stack variable to point to heap memory variables, which is a pointer in Java Thought]

Static field: located in a static object using the definition of static members

Constant pool: storage of constants. Constant pool (constant pool) refers is determined at compile time, and saved some data compiled .class file. In addition to all the basic type contains the code defined (such as int, long, etc.) and object type (such as String and Array) constant value (final) also contains some symbolic references in text form, such as: classes and interfaces the fully qualified name; field names and descriptors; the methods and the names and descriptors. The virtual machine must maintain a constant pool for each type is loaded. The constant pool is the type used in an ordered set of constants and including direct constants (string, integer and floating point constants) and references to other types of symbols, fields and methods. For String constant whose value is in the constant pool.

[to sum up]:

a. stack used to store some of the original data and the data type of the local variable references to objects (String, array. objects, etc.), but does not store the contents of the object

b. heap storage use new keyword to create the objects.

c. String is a special wrapper class whose reference is stored in the stack, and the contents of the object to be created in different ways according to fixed (constant pool and heap). compile some already created and stored in a string constant pool while some are run only be created using the new keyword, stored in a heap.
- Using Oracle for Oracle GoldenGate to achieve a one-way data synchronization (Database)
- SUSE Firewall Configuration (Linux)
- C # assembly calls across constants, variables and functions (Programming)
- Binary Packages Golang (Linux)
- How to make Linux a non-root user uses less than 1024 ports (Linux)
- Heartbeat cluster components Overview (Server)
- Elasticsearch Kibana installation notes (Linux)
- Understanding Linux firewall Iptables (Linux)
- Docker command Detailed (Linux)
- Ubuntu 14.10 installation SecureCRT 7.3 (Linux)
- UUID in Java (Programming)
- ORA-12537: TNS: connection closed error process (Database)
- Spacewalk Linux system configuration and installation (Linux)
- Linux disk partition, format, mount the directory (Linux)
- Linux shell script to adjust the Task Scheduler (Linux)
- JBPM6 Tutorial - taught you how to install JBPM (Linux)
- CentOS7 build GlusterFS (Linux)
- Java reflection summary (Programming)
- Detailed LVM2 (Linux)
- Du and df show disk space usage inconsistent Causes and Treatment (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.