Java的字节码和ABAP load的比较

简介: 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 )


image.png

image.pngIn my laptop the javac.exe is in this folder:image.png(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:

image.pngOnce done, HelloWorld.class is generated:image.pngAlso the same for Tools.class, even though we do NOT manually compile Tools.java via javac.image.png(2) Now make some change on Tools.java:image.pngAnd execute HelloWorld, still the old string before change is printed:image.png(3) Compile Tools.java again, new version of Tools.class is generated.

image.pngThis time execute HelloWorld and you could observe the new string printed out.image.pngAnd the byte code for HelloWorld is still unchanged.image.pngByte 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.


image.pngLet’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.

image.png(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.



image.png

image.png(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.


image.pngThe generated ABAP load for a given report could be found from table REPOLOAD:image.pngFurther 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


相关文章
|
4月前
|
Java Windows
查看java文件汇编代码与字节码
查看java文件汇编代码与字节码
46 0
|
存储 缓存 Java
万洋《Java动态编译》
我们都知道Java属于编译型语言,即源码需要经过编译成字节码然后运行于JVM 我们也知道,代码一旦编写完成,编译出的.class文件是一定的。这里也就是静态编译。 那我们需要在运行时编译并加载应该怎么办呢,存在如下场景  我们熟知的类似LeetCode这种测评平台,需要执行用户输入的代码。  服务器需要动态加载某些类文件进行编译。 那么我们就要使用Java的动态编译能力,在运行时编译代码并加载进jvm。
374 0
万洋《Java动态编译》
|
Java 容器
动态编译生成Java类
动态创建bean,前面一篇介绍了通过cglib来创建的方式,虽然实现了动态创建java bean,但是有一个问题,java bean中的field name和我们预期的不太一致 接下来我们介绍一种直接通过拼接java代码,然后再将其编译成class并加载,从而实现动态类的创建
403 0
|
Java Linux C语言
java高级用法之:在JNA中将本地方法映射到JAVA代码中
java高级用法之:在JNA中将本地方法映射到JAVA代码中
|
存储 Java 程序员
JVM详解之:java class文件的密码本
JVM详解之:java class文件的密码本
JVM详解之:java class文件的密码本
|
前端开发 安全 Java
Java Class 加载过程| Java Debug 笔记
Java Class 加载过程| Java Debug 笔记
|
Java 缓存 测试技术
Groovy&Java动态编译执行
Groovy&Java动态编译执行 工作中,遇到部分业务经常动态变化,或者在不发布系统的前提下,对业务规则进行调整。那么可以将这部分业务逻辑改写成Groovy脚本来执行,那么就可以在业务运行过程中动态更改业务规则,达到快速响应。
1948 0
|
存储 Java API
一个 Java 字节码类库!
Java 字节码以二进制的形式存储在 .class 文件中,每一个 .class 文件包含一个 Java 类或接口。
145 0
一个 Java 字节码类库!
|
JavaScript 前端开发 Java
Java的字节码和ABAP load的比较
Java的字节码和ABAP load的比较
108 0
Java的字节码和ABAP load的比较
|
Java 编译器 Android开发
3种骚操作,教你查看 Java 字节码!
在我们工作、学习、以及研究 JVM 过程当中,不可避免的要查看 Java 字节码,通过查看字节码可以了解一个类的编译结果,也能通过编译器层面来分析一个类的性能。
3种骚操作,教你查看 Java 字节码!