§ 瀏覽學位論文書目資料
  
系統識別號 U0002-2601202621192100
DOI 10.6846/tku202600063
論文名稱(中文) 由 Java 到 JavaScript 的改寫—以魔術方塊的模擬程式進行驗證
論文名稱(英文) Rewriting from Java to JavaScript—Verified by a Rubik's Cube Simulator
第三語言論文名稱
校院名稱 淡江大學
系所名稱(中文) 資訊管理學系碩士班
系所名稱(英文) Department of Information Management
外國學位學校名稱
外國學位學院名稱
外國學位研究所名稱
學年度 114
學期 1
出版年 115
研究生(中文) 林冠妤
研究生(英文) Guan-Yu Lin
學號 612630268
學位類別 碩士
語言別 繁體中文
第二語言別
口試日期 2026-01-10
論文頁數 70頁
口試委員 指導教授 - 廖賀田(htliaw@mail.tku.edu.tw)
口試委員 - 魏世杰(sekewei@mail.tku.edu.tw)
口試委員 - 壽大衛(shou@utaipei.edu.tw)
口試委員 - 廖賀田(htliaw@mail.tku.edu.tw)
關鍵字(中) Java
JavaScript
程式語言轉換
程式庫模擬
互動繪圖
關鍵字(英) Java
JavaScript
programming language translation
library simulation
interactive graphihics
第三語言關鍵字
學科別分類
中文摘要
本論文為廖蔓瑄碩士論文[1](以下簡稱廖論文[1])之延伸研究,旨在深入探討 Java 與 JavaScript 兩種語言在語法結構與語意上的差異,並進一步完成廖論文[1]先前尚未實作的魔術方塊程式之轉換與驗證。本研究除了補充與修正原有廖論文[1]中遺漏的演算法與模擬函式庫之外,亦著重於轉換過程中實際運作的可行性與模擬Java限制bit-數的行為,能夠處理複雜的溢位與位元運算,在語意上與Java 語意接近並使得在數學運算上不會因為些許誤差影響程式的最終結果。
在轉換實作方面,主要依據廖論文[1]中所提出的程式轉換架構為基礎,遵循其既定的語法對應規則與轉換策略,採用手動方式進行原始碼轉換。透過實際改寫與執行魔術方塊程式,驗證原有轉換機制的可行性與完整性,並進一步釐清在類別繼承、事件處理、圖形繪製及元件互動等層面上,Java 與 JavaScript 之間的實際差異與對應方法。
此外,本研究亦針對轉換過程中遇到的語言特性差異(如Overloading、多維陣列的宣告)進行更細緻的探討與實作,並提出具體的改良方案,使轉換後的程式架構更加符合物件導向設計的原則。最終,本研究期望能提供一套更完整且具延展性的 Java-to-JavaScript 改寫參考模型,作為後續自動化轉換系統開發與跨語言應用研究的重要基礎。
英文摘要
This thesis is an extension of the study presented in [1] and aims to further investigate the syntactic and semantic differences between Java and JavaScript. Building upon the work in [1], this study completes the transformation and validation of the Rubik’s Cube program that was not fully implemented in the previous research. In addition to supplementing and correcting the algorithms and simulated libraries omitted in [1], this research places particular emphasis on the practical feasibility of the transformation process and on simulating Java’s fixed bit-width numerical behavior. The proposed approach is capable of handling complex overflow and bitwise operations, achieving semantic consistency with Java and preventing minor numerical discrepancies from affecting the final computational results.
Regarding the implementation of the transformation, this study is primarily based on the program transformation framework proposed in [1], adhering to its established syntactic mapping rules and transformation strategies, and adopts a manual source-code conversion approach. Through the actual rewriting and execution of the Rubik’s Cube program, the feasibility and completeness of the original transformation mechanism are validated. Furthermore, the study clarifies the practical differences and corresponding solutions between Java and JavaScript in aspects such as class inheritance, event handling, graphical rendering, and component interaction. 
In addition, this research conducts a more detailed examination and implementation of language feature differences encountered during the transformation process, such as method overloading and multidimensional array declarations, and proposes concrete improvement strategies to ensure that the transformed program structure more closely adheres to object-oriented design principles. Ultimately, this study aims to provide a more comprehensive and extensible Java-to-JavaScript transformation reference model, serving as an important foundation for the development of future automated transformation systems and cross-language application research.
第三語言摘要
論文目次
目錄
第一章  緒論	1
1.1 研究背景與動機	1
1.2 研究目的	1
1.3 論文組織	2
第二章 文獻探討	3
2.1 Java 與 JavaScript 的語法差異	3
2.2 Java的JFrame	3
2.2.1 JFrame的repaint() 運作原理	4
2.3 ES6(ECMAScript 2015)	4
2.4 TypeScript	5
2.5 由 Java 到 JavaScript 的自動轉換	5
2.6 在瀏覽器製作其他語言的直譯器	6
2.7 先前的廖論文[1]	6
2.7.1廖論文[1]中做轉換的前置處理	7
2.7.2 廖論文[1]Java 標準函式庫的模擬策略	8
2.7.3廖論文[1]中的新增程式庫	8
2.7.4 Overloading的處理	9
2.7.5關於ctor method的轉換法	9
2.7.6 關於廖論文[1]的限制	10
三 研究方法	12
3.1 現存問題	12
3.1.1 數值精度問題	13
3.1.2 多物件群組的3D變換穩定性的結構複雜度問題	13
3.1.3 廖論文[1]缺漏的演算法	13
3.2 基於物件導向封裝的 Java 語意高保真模擬策略	15
3.2.1  Java型態系統的仿真	16
3.2.2 Java與JavaScript基本型態的差異	19
3.2.3 實作Java整數型基本型態所對應的JavaScript類別	20
3.2.4 實作Java浮點數型基本型態	23
3.2.5 實作Java字元型基本類別	24
3.2.6 實作Java布林型基本類別	27
3.3 轉寫JDK的基本類別	28
3.3.1 增補JvObject	29
3.3.2 增補JvPrintStream	31
3.3.3 增補JvSystem	32
3.4 增補Java Swing程式庫	32
3.4.1 增補JvJMenuItem	33
3.4.2 增補JvJCheckBoxMenuItem	34
3.4.3增補JvJRadioButtonMenuItem	35
3.4.4 增補JvJMenu	35
3.4.5 增補JvJMenuBar	36
3.4.6 增補對話框-JvJOptionPane	36
3.5 TwFC 向量、仿射變換系統模擬與管理圖形物件	37
3.5.1 TwFC 向量系統模擬	37
3.5.2 TwFC仿射變換系統模擬	37
3.5.3 管理圖形物件	37
3.5.4 3D事件的處理	38
3.5.5 承接與拓展 TwFC 的 3D 互動能力	38
3.5.1.1 TwFC 核心類別的應用驗證與測試強化	38
3.5.5.2 3D 事件處理的完整性拓展:左右鍵分離與準確抓取	39
3.6 增補轉換演算法	39
3.6.1 本論文的前置處理	40
3.6.2 debug[1]	40
3.6.2.1 Suffix bug	40
3.6.2.2 static syntax	41
3.6.2.3修改/增補函數	41
3.6.2.4增補類別	42
3.6.3 多維陣列結構的仿真	42
3.6.3.1 解析Java的陣列宣告形式	42
3.6.3.2 多維陣列的在轉換上的處理	44
3.6.4 關於System與打結現象	46
3.6.4.1 雙親委派模型與 JavaScript 載入順序差異	47
3.6.4.2 如何處理”打結現象”	47
3.6.5欄位	49
3.6.5.1 欄位與初始值	49
3.6.5.2 關於static 與const	51
3.6.5.3 本論文關於ctor 轉換演算法的補充	52
3.6.6 Overloading的處理	54
四 專案轉換的實驗	57
4.1 廖論文[1]的繪圖邏輯	58
4.2 魔術方塊的滾動、轉動	60
4.3 搭配MenuBar提供多種魔術方塊互動選項	61
4.3.1 魔術方塊的核心操作	61
4.3.2 視圖配置與展示選單	62
4.3.3 說明與資訊選單	64
五 結論與未來展望	65
結論	65
未來展望	66
參考文獻	67

表目錄
表3-1 系統遷移架構圖	15
表3-2 以class模擬的Java基本型態	16
表3-3 整數型基本類別	17
表3-4 浮點數型基本型態	17
表3-5 字元型基本型態	17
表3-6 布林型基本型態	18
表3-7  JavaScript的基本型態	19
表3-8 增補Java中的一些重要類別	29
表3-9 將魔術方塊程式中無父類別的class改成繼承 JvObject之虛擬碼	31
表3-9 解析Java的陣列宣告之演算法	43
表3-10 建立JavaScript多維陣列	45
表3-11 將Java各個欄位依型態給予預設值	50
表3-12移除final宣告之虛擬碼:	51
表3-13 檢查JavaScript ctor method之Algorithm:	54
表3-14 生成不含_suffix的method虛擬碼:	55
表4-1 File選單的核心功能	62
表4-2 View選單功能描述	63

圖目錄
圖 3-1 先前研究與待解決問題	12
圖 3-2 廖論文[1]的繼承關係	30
圖 3-3 繼承新建的JvObject後的繼承關係	30
圖 3-4 選單列相關類別繼承與原生Java類別對應關係	33
圖 4-1 執行期層次架構圖	58
圖 4-2 廖論文[1]Java版立體方塊的執行畫面	59
圖 4-3 廖論文[1]JavaScript版立體方塊的執行畫面	59
圖 4-4  Java版魔術方塊的執行畫面	60
圖 4-5  JavaScript版魔術方塊的執行畫面	61
圖 4-6  File選單-Scramble(打亂)	62
圖 4-7  View選單-取消edge cell展示	63
圖 4-8  Help選單-Manual展示	64
參考文獻
參考文獻
[1]	廖蔓瑄, “由Java 到 JavaScript 的改寫 以 3D 互動繪圖為例,” Jun. 2023.
[2]	“The Java® Language Specification.” Accessed: Oct. 19, 2025. [Online]. Available: https://docs.oracle.com/javase/specs/jls/se8/html/index.html
[3]	“ECMAScript® 2021 Language Specification.” Accessed: Oct. 20, 2025. [Online]. Available: https://262.ecma-international.org/12.0/index.html
[4]	H.T.Liaw, “The TwFC library for java,” Unpublished manuscript.
[5]	A. M. Fard and A. Mesbah, “JSNOSE: Detecting javascript code smells,” IEEE 13th International Working Conference on Source Code Analysis and Manipulation, SCAM 2013, pp. 116–125, 2013, doi: 10.1109/SCAM.2013.6648192.
[6]	D. Winkler, S. Biffl, and J. (Eds. ). Bergsmann, “Software Quality: The Complexity and Challenges of Software Engineering and Software Quality in the Cloud,” vol. 338, 2019, doi: 10.1007/978-3-030-05767-1.
[7]	A. Saboury, P. Musavi, F. Khomh, and G. Antoniol, “An empirical study of code smells in JavaScript projects,” SANER 2017 - 24th IEEE International Conference on Software Analysis, Evolution, and Reengineering, pp. 294–305, Mar. 2017, doi: 10.1109/SANER.2017.7884630.
[8]	“Chapter 4. Types, Values, and Variables.” Accessed: Oct. 20, 2025. [Online]. Available: https://docs.oracle.com/javase/specs/jls/se8/html/jls-4.html#jls-4.12.5
[9]	“undefined - JavaScript | MDN.” Accessed: Oct. 20, 2025. [Online]. Available: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined
[10]	“JFrame (Java Platform SE 8 ).” Accessed: Oct. 20, 2025. [Online]. Available: https://docs.oracle.com/javase/8/docs/api/javax/swing/JFrame.html
[11]	“RepaintManager (Java Platform SE 8 ).” Accessed: Oct. 20, 2025. [Online]. Available: https://docs.oracle.com/javase/8/docs/api/javax/swing/RepaintManager.html
[12]	“Painting in AWT and Swing.” Accessed: Oct. 20, 2025. [Online]. Available: https://www.oracle.com/java/technologies/painting.html
[13]	“The TC39 Process.” Accessed: Oct. 19, 2025. [Online]. Available: https://tc39.es/process-document/
[14]	K. Paltoglou, V. E. Zafeiris, N. A. Diamantidis, and E. A. Giakoumakis, “Automated refactoring of legacy JavaScript code to ES6 modules,” Journal of Systems and Software, vol. 181, p. 111049, Nov. 2021, doi: 10.1016/J.JSS.2021.111049.
[15]	A. Paltoglou, V. E. Zafeiris, E. A. Giakoumakis, and N. A. Diamantidis, “Automated refactoring of client-side JavaScript code to ES6 modules,” 25th IEEE International Conference on Software Analysis, Evolution and Reengineering, SANER 2018 - Proceedings, vol. 2018-March, pp. 402–412, Apr. 2018, doi: 10.1109/SANER.2018.8330227.
[16]	A. Fain and an O. M. Company. Safari, “TypeScript Quickly,” p. 488, Accessed: Oct. 19, 2025. [Online]. Available: https://www.manning.com/books/typescript-quickly
[17]	J. Bogner and M. Merkel, “To Type or Not to Type? A Systematic Comparison of the Software Quality of JavaScript and TypeScript Applications on GitHub,” Proceedings - 2022 Mining Software Repositories Conference, MSR 2022, pp. 658–669, Mar. 2022, doi: 10.1145/3524842.3528454.
[18]	David Leopoldseder, Lukas Stadler, Christian Wimmer, and Hanspeter Mössenböck, “Java-to-JavaScript translation via structured control flow reconstruction of compiler IR,” ACM SIGPLAN Notices, vol. 51, no. 2, pp. 91–103, Oct. 2015, doi: 10.1145/2936313.2816715.
[19]	A. Puder, V. Woeltjen, and A. Zakai, “Cross-compiling Java to JavaScript via tool-chaining,” ACM International Conference Proceeding Series, pp. 25–34, 2013, doi: 10.1145/2500828.2500831.
[20]	H. T. Liaw and S. C. Wei, “Obfuscation for object-oriented programs,” Software—Practice & Experience, vol. 44, no. 9, pp. 1077–1104, Sep. 2014, doi: 10.1002/SPE.2193.
[21]	J. Vilk and E. D. Berger, “DOPPIO: Breaking the browser language barrier,” ACM SIGPLAN Notices, vol. 49, no. 6, pp. 508–518, Jun. 2014, doi: 10.1145/2594291.2594293.
[22]	N. Shrestha, C. Botta, T. Barik, and C. Parnin, “Here We Go Again: Why Is It Difficult for Developers to Learn Another Programming Language?,” Commun. ACM, vol. 65, no. 3, pp. 91–99, Feb. 2022, doi: 10.1145/3511062.
[23]	H. T. Liaw, “Obfuscation for object‐oriented programs: dismantling encapsulation.,” Unpublished manuscript., 2023.
[24]	“Primitive Data Types (The JavaTM Tutorials > Learning the Java Language > Language Basics).” Accessed: Dec. 11, 2025. [Online]. Available: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
[25]	“語法與型別 - JavaScript | MDN.” Accessed: Dec. 11, 2025. [Online]. Available: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Guide/Grammar_and_types
[26]	“JMenuItem (Java Platform SE 8 ).” Accessed: Dec. 11, 2025. [Online]. Available: https://docs.oracle.com/javase/8/docs/api/javax/swing/JMenuItem.html
[27]	“JCheckBoxMenuItem (Java Platform SE 8 ).” Accessed: Dec. 11, 2025. [Online]. Available: https://docs.oracle.com/javase/8/docs/api/javax/swing/JCheckBoxMenuItem.html
[28]	“JRadioButtonMenuItem (Java Platform SE 8 ).” Accessed: Dec. 11, 2025. [Online]. Available: https://docs.oracle.com/javase/8/docs/api/javax/swing/JRadioButtonMenuItem.html
[29]	“JMenu (Java Platform SE 8 ).” Accessed: Dec. 11, 2025. [Online]. Available: https://docs.oracle.com/javase/8/docs/api/javax/swing/JMenu.html
[30]	“JMenuBar (Java Platform SE 8 ).” Accessed: Dec. 11, 2025. [Online]. Available: https://docs.oracle.com/javase/8/docs/api/javax/swing/JMenuBar.html
[31]	“JavaScript execution model - JavaScript | MDN.” Accessed: Dec. 11, 2025. [Online]. Available: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Execution_model
[32]	“this - JavaScript | MDN.” Accessed: Oct. 20, 2025. [Online]. Available: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
[33]	“Working with objects - JavaScript | MDN.” Accessed: Oct. 20, 2025. [Online]. Available: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_objects
[34]	“Scope - Glossary | MDN.” Accessed: Oct. 20, 2025. [Online]. Available: https://developer.mozilla.org/en-US/docs/Glossary/Scope
[35]	“Chapter 5. Loading, Linking, and Initializing.” Accessed: Oct. 20, 2025. [Online]. Available: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html
[36]	“ClassLoader (Java Platform SE 8 ).” Accessed: Oct. 20, 2025. [Online]. Available: https://docs.oracle.com/javase/8/docs/api/java/lang/ClassLoader.html
[37]	“<script>: The Script element - HTML | MDN.” Accessed: Oct. 20, 2025. [Online]. Available: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script
[38]	“HTML Standard, Edition for Web Developers.” Accessed: Oct. 20, 2025. [Online]. Available: https://html.spec.whatwg.org/dev/scripting.html
[39]	“null - JavaScript | MDN.” Accessed: Oct. 20, 2025. [Online]. Available: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/null
論文全文使用權限
國家圖書館
同意無償授權國家圖書館,書目與全文電子檔於繳交授權書後, 於網際網路立即公開
校內
校內紙本論文立即公開
同意電子論文全文授權校園內公開
校內電子論文立即公開
校外
同意授權予資料庫廠商
校外電子論文立即公開

如有問題,歡迎洽詢!
圖書館數位資訊組 (02)2621-5656 轉 2487 或 來信