Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Java learning problems encountered     - Linux systems use logwatch log file monitoring (Linux)

- Confrontation dragged Library - Web front-end encryption slow (Linux)

- MySQL + Heartbeat + DRBD deployment architecture (Server)

- Exploring the Android Listview display confusion (Programming)

- Ubuntu dual-card system configuration method (Server)

- Via Twitter how open source library to be used anywhere Emoji emoticons (Linux)

- How Bluetooth turned off by default in Ubuntu 14.04 (Linux)

- Linux Quick Install MongoDB (Database)

- Variables Python variables (Programming)

- MySQL Slave synchronization problem solving (Database)

- CentOS install Redis (Database)

- Easily solve the MySQL database connection error too many (Database)

- Chromium Install Flash Official Guide (Linux)

- The Definitive Guide to Linux NAT network connection (Linux)

- Linux shared libraries .so file name and Dynamic Link (Linux)

- To install the Contiki development toolchain on Ubuntu (Linux)

- When Linux Detailed time zone and common function of time (Linux)

- Sniffer install applications in Linux supplement (Linux)

- GNU Linux system variables (sysctl configuration commands) integrated use (Linux)

- Python script running in the background (Programming)

  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.
- To resolve Ubuntu 14.04 Unity Desktop Environment Login freeze problem (Linux)
- Oracle PL / SQL selective basis (IF CASE), (LOOP WHILE FOR) (Database)
- Installation and deployment of MariaDB under CentOS (Database)
- Cygwin install Python MySQLdb (Linux)
- Linux operating system security can not be ignored (Linux)
- Ubuntu 14.04 install PostgreSQL 9.2 (Database)
- MongoDB polymerization being given (Database)
- OpenGL shadow map (Programming)
- How to add a new resolution VirtualBox (Linux)
- Vim useful plugin: vundle (Linux)
- CentOS installation pycurl (Linux)
- Execute command sentence can result in equipment permanently bricked in Linux laptop (Linux)
- How to publish projects to the Jcenter repository using Gradle in Android Studio (Programming)
- Oracle Client + PL SQL Developer enables remote access to the Oracle database (Database)
- Java rewrite the hashcode method (Programming)
- Android View event delivery (Programming)
- To_teach you three strategies to prevent the LAN IP address theft (Linux)
- JavaScript event handling Detailed (Programming)
- Linux Network Programming - signal blocking and shielding (block, unblock) (Programming)
- A command to install Sublime Text 3 on Manjaro / Archlinux (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.