Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Java learning problems encountered     - How to use jgit to manage Git submodule (Linux)

- Update GAMIT10.6 command (Linux)

- How to generate Linux, random password encryption or decryption (Linux)

- C ++: Postmodern systems programming language (Programming)

- Python programming style (Programming)

- How to use the DM-Crypt encryption Linux File System (Linux)

- Java Collections Framework interfaces map (Programming)

- Ubuntu 14.04 build Android 5.1 development environment and compiler (Linux)

- Experts teach you safety precautions Linux Sniffer (Linux)

- Terminal Linux command prints - echo (Linux)

- To configure parameter configuration and software installation and uninstallation under Linux (Linux)

- Linux Systems Getting Started Learning: Configuration PCI passthrough on a virtual machine (Linux)

- TOAD connect DB2 error SQL1460N solve (Database)

- Ubuntu 14.04 LTS compiler installation R Source Code (Linux)

- Source Analysis: Java object memory allocation (Programming)

- Revised OpenJDK Java Memory Model (Programming)

- 4 lvcreate example commonly used commands (Linux)

- shell script: the number of characters in the text to print no more than 6 words (Programming)

- Ubuntu 14.04 installed VirtualBox 4.3 appears vboxdrv: Unknown symbol mcount (Linux)

- GlusterFS distributed storage deployment (Server)

  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.
- NIC configuration parameters under Linux (Linux)
- Examples of Python any parameters (Programming)
- Physical structure and process disk IO (Linux)
- Linux firewall security (Linux)
- Oracle archive log deletion (Database)
- Linux basis: a comprehensive study pwd command (Linux)
- Getting Started with Linux system to learn: how to check memory usage of Linux (Linux)
- Rails 4.1.6 start being given Could not find a JavaScript runtime (Linux)
- Linux System Getting Started Tutorial: How to find the maximum memory your system supports (Linux)
- Linux Command Tutorial: cat command to view the contents of the file (Linux)
- Linux under DB2SQL1024N A database connection does not exist. SQLS (Database)
- Oracle SQL statement tracking (Database)
- Linux system - The understanding cpu load (Linux)
- Using Linux command line and execute PHP code (Programming)
- CentOS6.6 ordinary users to use sudo command to borrow root user privileges (Linux)
- The best tools and techniques to find data on a Unix system (Linux)
- SSH service configuration to use a certificate login Linux server (Server)
- ActionContext and ServletActionContext Summary (Programming)
- RedHat yum configuration and the prompt (Linux)
- Through eight skills to let you become a super Linux end-user (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.