Home > Java > javaTutorial > java compiler features

java compiler features

PHP中文网
Release: 2017-07-06 18:12:48
Original
1684 people have browsed it

1. When both sides of an expression are literals, calculations will be performed during the compilation process and the results will be generated at the position of the expression to save computing efficiency;

ps: jvm thinks that only when it is a literal, it will compare the contents of the constant pool; if it is new, the new object is a different object.

example 1:

<span style="color: #008080">1</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args){
</span><span style="color: #008080">2</span>         String str = "123str"<span style="color: #000000">;
</span><span style="color: #008080">3</span>         String str1 = "123"+"str"<span style="color: #000000">;
</span><span style="color: #008080">4</span>         String str2 = <span style="color: #0000ff">new</span> String("123str"<span style="color: #000000">);
</span><span style="color: #008080">5</span> 
<span style="color: #008080">6</span>         System.out.println(str == str1);  <span style="color: #008000">//</span><span style="color: #008000">true</span>
<span style="color: #008080">7</span>         System.out.println(str == str2);  <span style="color: #008000">//</span><span style="color: #008000">false</span>
<span style="color: #008080">8</span>     }
Copy after login

The above is the detailed content of java compiler features. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template