Java的位元組碼和ABAP load的比較
I use this small blog to help my new colleagues on board who have Java programming background to understand the hello world example written in ABAP.
Hello World example in Java
The following example could be done in pure text editor without Java IDE. You should have JDK installed as prerequisite and corresponding environment variable setup correctly.
Once done, type javac -version in command line, you should see the following output: ( result may vary based on your JDK version )
In my laptop the javac.exe is in this folder:
(1) Create a folder in c:\temp\testPackage. (2) Create a file HelloWorld.java in text editor with source code below:
package testPackage;import tool.Tools;public class HelloWorld {
public HelloWorld() {
}
static public void main(String[] arg){
System.out.println("Hello World");
Tools.Print();
}}
Create another folder in C:\temp\tool. And another Tools.java:
package tool;public class Tools{
static public void Print(){
System.out.println("I am tool!");
}}
This example shows that the HelloWorld class has dependency on Tools class.
(1) Now compile HelloWorld class via javac:
Once done, HelloWorld.class is generated:
Also the same for Tools.class, even though we do NOT manually compile Tools.java via javac.
(2) Now make some change on Tools.java:
And execute HelloWorld, still the old string before change is printed:
(3) Compile Tools.java again, new version of Tools.class is generated.
This time execute HelloWorld and you could observe the new string printed out.
And the byte code for HelloWorld is still unchanged.
Byte Code in ABAP – ABAP Load
The following texts are copied from ABAP help:
Result of generating an ABAP program using ABAP Compiler. The statements in the byte code are associated with C functions. When the ABAP program is executed, the byte code is loaded into the PXA as the program load and interpreted by the ABAP runtime environment (virtual machine), which accesses the associated C functions.
Let’s repeat the same test in ABAP.
(1) Create a new include ZTOOL and activate it:
form print.
WRITE: / 'Hello World.'.endform.
And create a new HelloWorld report and activate it as well.
REPORT ZHELLOWORLD.INCLUDE ztool.START-OF-SELECTION.PERFORM print.
(2) Execute report RSDEPEND to analyze the dependency of report ZHELLOWORLD. ( You can find some examples how to use this report RSDEPEND from blog Use report RSDEPEND to analyze ABAP load dependencies )
The result shows that ZHELLOWORLD has dependency on ZTOOL. The timestamp of ZHELLOWORLD is larger than ZTOOL since it is activated later than ZHELLOWORLD.
(3) Make some changes on ZHELLOWORLD, for example add one line comment and activate it again.
This time the timestamp of ZHELLOWORLD changes, however ZTOOL remains unchanged.
(4) Now make changes on ZTOOL, activate the change. Don’t touch ZHELLOWORLD.
This time the timestamp of ZHELLOWORLD is also changed which equals exactly to the change timestamp of ZTOOL.
The generated ABAP load for a given report could be found from table REPOLOAD:
Further reading
I have written a series of blogs which compare the language feature among ABAP, JavaScript and Java. You can find a list of them below:
- Lazy Loading, Singleton and Bridge design pattern in JavaScript and in ABAP
- Functional programming – Simulate Curry in ABAP
- Functional Programming – Try Reduce in JavaScript and in ABAP
- Simulate Mockito in ABAP
- A simulation of Java Spring dependency injection annotation @Inject in ABAP
- Singleton bypass – ABAP and Java
- Weak reference in ABAP and Java
- Fibonacci Sequence in ES5, ES6 and ABAP
- Java byte code and ABAP Load
- How to write a correct program rejected by compiler: Exception handling in Java and in ABAP
- An small example to learn Garbage collection in Java and in ABAP
- String Template in ABAP, ES6, Angular and React
- Try to access static private attribute via ABAP RTTI and Java Reflection
- Local class in ABAP, Java and JavaScript
- Integer in ABAP, Java and JavaScript
- Covariance in Java and simulation in ABAP
- Various Proxy Design Pattern implementation variants in Java and ABAP
- Tag(Marker) Interface in ABAP and Java
- Bitwise operation ( OR, AND, XOR ) on ABAP Integer
- ABAP ICF handler and Java Servlet
- ADBC and JDBC
- CL_ABAP_CORRESPONDING, CL_JAVA_CORRESPONDING and CL_JS_CORRESPONDING
- Build an Cross Site Scripting example in Java and ABAP
- Play around with JSONP in nodeJS server and ABAP server
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2714076/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Dalvik 和 Java 位元組碼的比較Java
- java位元組流和字元流的比較哦啊Java字元
- ABAP SICF服務和Java Servlet的比較JavaServlet
- SAP ABAP ADBC和Java JDBC的使用比較JavaJDBC
- ABAP, Java和JavaScript三種語言的比較JavaScript
- Java位元組流檔案複製及效率比較Java
- Java的魔力:位元組碼(轉)Java
- Java 位元組碼Java
- Java的位元組流,字元流和緩衝流對比探究Java字元
- Java位元組碼指令Java
- ABAP OPEN SQL裡OPEN CURSOR和SELECT的比較SQL
- JAVA動態位元組碼Java
- 【Java】JVM位元組碼分析JavaJVM
- ABAP的include關鍵字,Java的import, C的include和C4C ABSL 的import比較JavaImport
- Hibernate學習(四)get和Load比較
- Java和JavaSciprt比較Java
- 字元,位元組和編碼字元
- Java位元組碼指令表Java
- 輕鬆看懂Java位元組碼Java
- Java位元組碼忍者禁術Java
- Java™ 教程(比較字串和字串的部分)Java字串
- 使用javap分析Java位元組碼的一個例子Java
- 從位元組碼視角看java字串的拼接Java字串
- initialize方法與load方法比較
- Java 位元組的常用封裝Java封裝
- ASM位元組碼操作類庫(開啟java語言世界通往位元組碼世界的大門)ASMJava
- ASM位元組碼操作類庫:開啟java語言世界通往位元組碼世界的大門ASMJava
- 開啟java語言世界通往位元組碼世界的大門——ASM位元組碼操作類庫JavaASM
- Java,Go和Rust之間的比較 - DexterJavaGoRust
- Java物件之間的比較之equals和==Java物件
- 例項分析理解Java位元組碼Java
- Java位元組碼增強技術Java
- cmd下檢視java位元組碼Java
- 如何閱讀JAVA 位元組碼(一)Java
- 你需要知道的那些 Java 位元組碼知識Java
- 教你用Java位元組碼做點有趣的事Java
- Java 動態性(4) – 位元組碼操作Java
- 從 Java 位元組碼到 ASM 實踐JavaASM