SlideShare a Scribd company logo
1 of 18
Java Essence part1
- String, enum
Bram
Outline
 String
 enum
String
 String str = "Java";
 String str = new String("Java");
 String temp = "Java";
String str = new String(temp);
 String str1 = "Java";
String str2 = new String(str1);
System.out.println(str1 == str2); // false
 Str1 is not the same object of str2
String
 String (Intern) Pool
 preserving immutable strings in pool
 one instance of the same string
 String str1 = "Java";
String str2 = "Java";
System.out.println(str1 == str2); // true
 String str1 = "a" + "bc";
String str2 = "ab" + "c";
System.out.println(str1 == str2); // true
String
 String.intern()
 If pool has this string, return it directly
otherwise, add to pool and return
 s.intern() == t.intern() is true
if and only if s.equals(t) is true
 String str1 = "Java";
String str2 = new String(str1);
System.out.println(str1 == str2.intern()); //true
String
 String.intern()
 Use only if needing to compare a lot of String
 Improve by == to replace equals()
 no way to de-intern
 In general,
not to call intern() on user-generated strings
 In JDK 7
 interned strings aren‟t allocated in the permanent
generation, but in the main part of the Java heap
String
 String.substring()
 Instead of creating an new char array,
just „reuse‟ the old one
 Only the offset and count changes
 public final class String{
private final char value[];
private final int offset;
private final int count;
public String substring(int beginIndex, int endIndex)
{
return new String (offset + beginIndex,
endIndex - beginIndex, value);}
}
}
enum
 Without Enum
 public interface Position {
public static final int TOP = 0;
public static final int RIGHT = 1;
public static final int LEFT = 2;
public static final int BOTTOM = 4;
}
 Valuables in Interface
 public : open for others to understand
 static : there is no instances, so it must belong to Class
 final : regards Interface as treaty
– Add by compiler even not declare those key-words
enum
 After JDK5
 enum is available
 public enum Position {
TOP, RIGHT, LEFT, BOTTOM
}
 “enum” declare special class
 Inherit from java.lang.Enum
– CANNOT extent directly
enum
 After Decompile
 public final class Position extends Enum {
…….
private Position(String s, int i) {
super(s, i);
}
public static final Position TOP;
public static final Position RIGHT;
public static final Position LEFT;
public static final Position BOTTOM;
...
static {
TOP = new Position("TOP", 0);
RIGHT = new Position("RIGHT", 1);
LEFT = new Position("LEFT", 2);
UP = new Position("UP", 3);
...
}
}
enum
 java.lang.Enum
 public abstract class Enum<E extends Enum<E>>
implements Comparable<E>, Serializable {
…..
private final String name;
private final int ordinal;
protected Enum(String name, int ordinal) {
this.name = name;
this.ordinal = ordinal;
} // ordinal is the enum order with beginning of 0
…
}
 http://grepcode.com/file/repository.grepcode.com/java/root/jdk/
openjdk/7-b147/java/lang/Enum.java
enum
 Extended enum
 public enum MethodSet {
INIT (“init”, -1),
START(“start”, 1),
STOP(“stop”, 0);
….
private string method;
private int value;
private MethodSet(string method, int value) {
this.methid = method;
this.value = value;
}
public string method() {
return method;
}
public int value() {
return value;
}
}
enum
 After decompile
 public final class MethodSet extends Enum {
...
private MethodSet(String s, int i, string method, int value) {
super(s, i);
this.methid = method;
this.value = value;
}
public int value() {
return value;
}
...
public static final MethodSet INIT;
public static final MethodSet START;
public static final MethodSet STOP;
private string method;
private int value;
private static final MethodSet $VALUES[];
enum
 continue.
 static
{
INIT = new MethodSet("INIT", 0, "init", -1);
START = new MethodSet("START", 1, "start", 1);
STOP = new MethodSet("STOP", 2, "stop", 0);
$VALUES = (new MethodSet[] {
INIT, START, STOP
});
}
}
enum
 More Extended enum, v1
 public enum Action implements Command {
STOP, RIGHT, LEFT;
public void execute() {
switch(this) {
case STOP:
System.out.println(“Animation Stop");
break;
case RIGHT:
System.out.println(“Animation Right");
break;
case LEFT:
System.out.println(“Animation Left");
break;
}
}
}
enum
 More Extended enum, v2
 public enum Action implements Command {
STOP {
public void execute() {
System.out.println(“Animation Stop");
}
},
RIGHT {
public void execute() {
System.out.println(“Animation Right");
}
},
LEFT {
public void execute() {
System.out.println(“Animation Left");
}
};
}
enum
 After decompile
 public abstract class Action extends Enum implements Command {
...
static
{
STOP = new Action("STOP", 0) {
public void execute() {
System.out.println("u64AD…xxxxx");
}
};
RIGHT = new Action("STOP", 1) {
public void execute() {
System.out.println("u64AD…xxxxx");
}
};
...
}
...
}
Java Decompiler
 http://java.decompiler.free.fr/
 JD-GUI
– http://java.decompiler.free.fr/?q=jdgui
 JD-Eclipse
 JD-Core

More Related Content

What's hot

Let's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java APILet's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java APIMario Fusco
 
Javaz. Functional design in Java 8.
Javaz. Functional design in Java 8.Javaz. Functional design in Java 8.
Javaz. Functional design in Java 8.Vadim Dubs
 
Python Closures Explained | What are Closures in Python | Python Closures
Python Closures Explained | What are Closures in Python | Python ClosuresPython Closures Explained | What are Closures in Python | Python Closures
Python Closures Explained | What are Closures in Python | Python ClosuresIntellipaat
 
Tiger: Java 5 Evolutions
Tiger: Java 5 EvolutionsTiger: Java 5 Evolutions
Tiger: Java 5 EvolutionsMarco Bresciani
 
Overview of verilog
Overview of verilogOverview of verilog
Overview of verilogRaghu Veer
 
2 kotlin vs. java: what java has that kotlin does not
2  kotlin vs. java: what java has that kotlin does not2  kotlin vs. java: what java has that kotlin does not
2 kotlin vs. java: what java has that kotlin does notSergey Bandysik
 
Iterarators and generators in python
Iterarators and generators in pythonIterarators and generators in python
Iterarators and generators in pythonSarfaraz Ghanta
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming iiPrashant Kalkar
 
Object Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. PolymorphismObject Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. PolymorphismAndiNurkholis1
 
Advance topics of C language
Advance  topics of C languageAdvance  topics of C language
Advance topics of C languageMehwish Mehmood
 
Life & Work of Robin Milner | Turing100@Persistent
Life & Work of Robin Milner | Turing100@PersistentLife & Work of Robin Milner | Turing100@Persistent
Life & Work of Robin Milner | Turing100@PersistentPersistent Systems Ltd.
 

What's hot (20)

Let's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java APILet's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java API
 
C q 3
C q 3C q 3
C q 3
 
Javaz. Functional design in Java 8.
Javaz. Functional design in Java 8.Javaz. Functional design in Java 8.
Javaz. Functional design in Java 8.
 
OOP and FP
OOP and FPOOP and FP
OOP and FP
 
Python Closures Explained | What are Closures in Python | Python Closures
Python Closures Explained | What are Closures in Python | Python ClosuresPython Closures Explained | What are Closures in Python | Python Closures
Python Closures Explained | What are Closures in Python | Python Closures
 
Tiger: Java 5 Evolutions
Tiger: Java 5 EvolutionsTiger: Java 5 Evolutions
Tiger: Java 5 Evolutions
 
Loops_in_Rv1.2b
Loops_in_Rv1.2bLoops_in_Rv1.2b
Loops_in_Rv1.2b
 
Overview of verilog
Overview of verilogOverview of verilog
Overview of verilog
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
2 kotlin vs. java: what java has that kotlin does not
2  kotlin vs. java: what java has that kotlin does not2  kotlin vs. java: what java has that kotlin does not
2 kotlin vs. java: what java has that kotlin does not
 
Iterarators and generators in python
Iterarators and generators in pythonIterarators and generators in python
Iterarators and generators in python
 
Advance python
Advance pythonAdvance python
Advance python
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
Function in C++
Function in C++Function in C++
Function in C++
 
Object Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. PolymorphismObject Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. Polymorphism
 
Erlang session2
Erlang session2Erlang session2
Erlang session2
 
Advance topics of C language
Advance  topics of C languageAdvance  topics of C language
Advance topics of C language
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Life & Work of Robin Milner | Turing100@Persistent
Life & Work of Robin Milner | Turing100@PersistentLife & Work of Robin Milner | Turing100@Persistent
Life & Work of Robin Milner | Turing100@Persistent
 

Similar to Java essence part 1

OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdfakkhan101
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfarjuncorner565
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerAiman Hud
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodecamp Romania
 
Game unleashedjavascript
Game unleashedjavascriptGame unleashedjavascript
Game unleashedjavascriptReece Carlson
 
import java.awt.LinearGradientPaint; public class searchComparis.pdf
import java.awt.LinearGradientPaint; public class searchComparis.pdfimport java.awt.LinearGradientPaint; public class searchComparis.pdf
import java.awt.LinearGradientPaint; public class searchComparis.pdfanugrahafancy
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory archana singh
 
05a-enum.ppt
05a-enum.ppt05a-enum.ppt
05a-enum.pptMuthuMs8
 
Programing with java for begniers .pptx
Programing with java for begniers  .pptxPrograming with java for begniers  .pptx
Programing with java for begniers .pptxadityaraj7711
 
Scala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timeScala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timekarianneberg
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdfarshiartpalace
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldBTI360
 
Hey Kotlin, How it works?
Hey Kotlin, How it works?Hey Kotlin, How it works?
Hey Kotlin, How it works?Chang W. Doh
 

Similar to Java essence part 1 (20)

OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
Class 3 2ciclo
Class 3 2cicloClass 3 2ciclo
Class 3 2ciclo
 
Class 3 2ciclo
Class 3 2cicloClass 3 2ciclo
Class 3 2ciclo
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
 
Core C#
Core C#Core C#
Core C#
 
14 thread
14 thread14 thread
14 thread
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
Game unleashedjavascript
Game unleashedjavascriptGame unleashedjavascript
Game unleashedjavascript
 
import java.awt.LinearGradientPaint; public class searchComparis.pdf
import java.awt.LinearGradientPaint; public class searchComparis.pdfimport java.awt.LinearGradientPaint; public class searchComparis.pdf
import java.awt.LinearGradientPaint; public class searchComparis.pdf
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory
 
05a-enum.ppt
05a-enum.ppt05a-enum.ppt
05a-enum.ppt
 
Programing with java for begniers .pptx
Programing with java for begniers  .pptxPrograming with java for begniers  .pptx
Programing with java for begniers .pptx
 
Scala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timeScala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en time
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
 
Java interface
Java interfaceJava interface
Java interface
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
Hey Kotlin, How it works?
Hey Kotlin, How it works?Hey Kotlin, How it works?
Hey Kotlin, How it works?
 
PathOfMostResistance
PathOfMostResistancePathOfMostResistance
PathOfMostResistance
 

Recently uploaded

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Recently uploaded (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Java essence part 1

  • 1. Java Essence part1 - String, enum Bram
  • 3. String  String str = "Java";  String str = new String("Java");  String temp = "Java"; String str = new String(temp);  String str1 = "Java"; String str2 = new String(str1); System.out.println(str1 == str2); // false  Str1 is not the same object of str2
  • 4. String  String (Intern) Pool  preserving immutable strings in pool  one instance of the same string  String str1 = "Java"; String str2 = "Java"; System.out.println(str1 == str2); // true  String str1 = "a" + "bc"; String str2 = "ab" + "c"; System.out.println(str1 == str2); // true
  • 5. String  String.intern()  If pool has this string, return it directly otherwise, add to pool and return  s.intern() == t.intern() is true if and only if s.equals(t) is true  String str1 = "Java"; String str2 = new String(str1); System.out.println(str1 == str2.intern()); //true
  • 6. String  String.intern()  Use only if needing to compare a lot of String  Improve by == to replace equals()  no way to de-intern  In general, not to call intern() on user-generated strings  In JDK 7  interned strings aren‟t allocated in the permanent generation, but in the main part of the Java heap
  • 7. String  String.substring()  Instead of creating an new char array, just „reuse‟ the old one  Only the offset and count changes  public final class String{ private final char value[]; private final int offset; private final int count; public String substring(int beginIndex, int endIndex) { return new String (offset + beginIndex, endIndex - beginIndex, value);} } }
  • 8. enum  Without Enum  public interface Position { public static final int TOP = 0; public static final int RIGHT = 1; public static final int LEFT = 2; public static final int BOTTOM = 4; }  Valuables in Interface  public : open for others to understand  static : there is no instances, so it must belong to Class  final : regards Interface as treaty – Add by compiler even not declare those key-words
  • 9. enum  After JDK5  enum is available  public enum Position { TOP, RIGHT, LEFT, BOTTOM }  “enum” declare special class  Inherit from java.lang.Enum – CANNOT extent directly
  • 10. enum  After Decompile  public final class Position extends Enum { ……. private Position(String s, int i) { super(s, i); } public static final Position TOP; public static final Position RIGHT; public static final Position LEFT; public static final Position BOTTOM; ... static { TOP = new Position("TOP", 0); RIGHT = new Position("RIGHT", 1); LEFT = new Position("LEFT", 2); UP = new Position("UP", 3); ... } }
  • 11. enum  java.lang.Enum  public abstract class Enum<E extends Enum<E>> implements Comparable<E>, Serializable { ….. private final String name; private final int ordinal; protected Enum(String name, int ordinal) { this.name = name; this.ordinal = ordinal; } // ordinal is the enum order with beginning of 0 … }  http://grepcode.com/file/repository.grepcode.com/java/root/jdk/ openjdk/7-b147/java/lang/Enum.java
  • 12. enum  Extended enum  public enum MethodSet { INIT (“init”, -1), START(“start”, 1), STOP(“stop”, 0); …. private string method; private int value; private MethodSet(string method, int value) { this.methid = method; this.value = value; } public string method() { return method; } public int value() { return value; } }
  • 13. enum  After decompile  public final class MethodSet extends Enum { ... private MethodSet(String s, int i, string method, int value) { super(s, i); this.methid = method; this.value = value; } public int value() { return value; } ... public static final MethodSet INIT; public static final MethodSet START; public static final MethodSet STOP; private string method; private int value; private static final MethodSet $VALUES[];
  • 14. enum  continue.  static { INIT = new MethodSet("INIT", 0, "init", -1); START = new MethodSet("START", 1, "start", 1); STOP = new MethodSet("STOP", 2, "stop", 0); $VALUES = (new MethodSet[] { INIT, START, STOP }); } }
  • 15. enum  More Extended enum, v1  public enum Action implements Command { STOP, RIGHT, LEFT; public void execute() { switch(this) { case STOP: System.out.println(“Animation Stop"); break; case RIGHT: System.out.println(“Animation Right"); break; case LEFT: System.out.println(“Animation Left"); break; } } }
  • 16. enum  More Extended enum, v2  public enum Action implements Command { STOP { public void execute() { System.out.println(“Animation Stop"); } }, RIGHT { public void execute() { System.out.println(“Animation Right"); } }, LEFT { public void execute() { System.out.println(“Animation Left"); } }; }
  • 17. enum  After decompile  public abstract class Action extends Enum implements Command { ... static { STOP = new Action("STOP", 0) { public void execute() { System.out.println("u64AD…xxxxx"); } }; RIGHT = new Action("STOP", 1) { public void execute() { System.out.println("u64AD…xxxxx"); } }; ... } ... }
  • 18. Java Decompiler  http://java.decompiler.free.fr/  JD-GUI – http://java.decompiler.free.fr/?q=jdgui  JD-Eclipse  JD-Core