เพื่อน ๆ ที่เขียนโปรแกรมด้วย Java หลาย ๆ คนอาจจะยังไม่รู้จักว่า JVM นั้นมันคืออะไร... ทำงานอย่างไร...
.
วันนี้แอดจะมาสรุปวิธีการทำงานของ JVM ให้เพื่อน ๆ พอที่จะเห็นภาพกัน หาพร้อมแล้วไปอ่านกันนนน
.
🔹 JVM (Java Virtual Machine) - เป็นเอ็นจิ้นที่จัดเตรียมสภาพแวดล้อมเพื่อรันโค้ด Java ซึ่ง JVM มีหน้าที่รับผิดชอบในการแปลง Bytecode เป็นรหัสเฉพาะเครื่อง ซึ่งเจ้า JVM นี้จะสามารถติดตั้งได้บนทุก Platform ไม่ว่าจะเป็น Unix, Linux หรือ Windows
.
⚙️ วิธีการทำงานของ JVM แบ่งได้ดังนี้
🌟 Class Loader Subsystem
เป็นส่วนที่ใช้จัดการ Class Loader Subsystem โดยจะอ่านไฟล์ .class และสร้างเป็น Bytecode บันทึกไว้ใน Method Area จากนั้นจะสร้าง Object เพื่อเป็นตัวแทนไฟล์ไว้ใน Heap Memory
.
🌟 Runtime Data Area (JVM Memory)
ส่วนนี้จะเป็นการจัดสรรพื้นที่ของ Memory ให้เหมาะสม เพื่อนำไปใช้งานในแต่ละส่วน ได้แก่ Method Area , Heap Area, Stack Area, PC Register, Native Method Stack นั่นเอง
.
🌟 Execution Engine
เป็นส่วนที่ใช้ควบคุมกระบวนการทำงานต่าง ๆ ซึ่ง Bytecode ที่อยู่ใน Runtime Data Area จะถูกประมวลผลด้วย Execution Engine โดยจะอ่าน Bytecode และประมวลผลทีละบรรทัด
.
🌟 Native Method Interface
เป็น Interface ที่ใช้โต้ตอบกับ Native Method Library ทำให้ JVM สามารถเรียกใช้งาน C/C++ library ได้นั่นเอง
🌟 Native Method Library
เป็นที่รวบรวม Native Library ที่จำเป็นต่อการใช้งานใน Native Method Interface นั่นเอง
.
จบกันไปแล้วววว! หากใครมีอะไรเพิ่มเติม สามารถคอมเมนต์พูดคุยกันได้เลยน้าาา และหวังว่าจะเป็นประโยชน์กับเพื่อน ๆ นะคร้าบบบบ 🥰
.
borntoDev - 🦖 สร้างการเรียนรู้ที่ดีสำหรับสายไอทีในทุกวัน
同時也有1部Youtube影片,追蹤數超過12萬的網紅prasertcbs,也在其Youtube影片中提到,การสร้าง Class library (JAR: Java ARchive) ============ ดาวน์โหลดไฟล์ตัวอย่างได้ที่ http://goo.gl/G5BNCN ============ playlist สอนการเขียนโปรแกรมเชิ...
「java library class」的推薦目錄:
- 關於java library class 在 BorntoDev Facebook 的精選貼文
- 關於java library class 在 BorntoDev Facebook 的最佳貼文
- 關於java library class 在 โปรแกรมเมอร์ไทย Thai programmer Facebook 的精選貼文
- 關於java library class 在 prasertcbs Youtube 的最讚貼文
- 關於java library class 在 Java Class Librares - YouTube 的評價
- 關於java library class 在 Java - Define a common interface for classes from an external ... 的評價
- 關於java library class 在 When creating a library, is there a way to make certain classes ... 的評價
- 關於java library class 在 CodeQL library for Java - GitHub 的評價
- 關於java library class 在 Library (JNA API) 的評價
java library class 在 BorntoDev Facebook 的最佳貼文
🔥 "เรื่องอื่นอาจจะประนีประนอมได้ .. แต่เขียนโค้ดสไตล์มั่วซั่ว ประนีประนอมไม่ได้เด็ดขาดดด !"
.
หลายคนน่าจะเคยเจอปัญหากันมาบ้างไม่ว่าจะเป็น
.
🤣 "เมื่อวันก่อนตรูเขียนอะไรลงไปเนี่ยยย !?" จนไปถึง "งงจัด เมื่อเพื่อนร่วมทีมส่งงานมาให้ช่วยดู"
.
ปัญหานี้จะหมดไปถ้าเรารู้ และ เข้าใจสิ่งที่เรียกว่า Coding Style ซึ่งจริง ๆ แล้วในหลาย ๆ ภาษาก็มีให้เราได้อ่านอยู่
.
✅ โดยเจ้าสิ่งนี้จะเป็น "คำแนะนำ" ในการเขียนโค้ดที่ดีของแต่ละภาษา หรือ แต่ละองค์กร ที่ได้มีเกณฑ์ต่าง ๆ กำหนดไว้แล้วนั่นเอง
.
ไม่ว่าจะเป็นเรื่องทั่วไปอย่าง
.
▶️ ควรตั้งชื่อตัวแปรแบบไหน ? ชื่อฟังก์ชันควรเป็นอะไรดี ?
.
▶️ การ Import ของจากข้างนอกมาใช้ อะไรควรทำก่อน หลัง หรือ ไม่ควร ?
.
▶️ จนไปถึง การออกแบบเงื่อนไขการทำงานควรออกแบบอย่างไร ?
.
ซึ่งแน่นอนว่าคำแนะนำที่ดีเหล่านี้จะช่วยให้โปรเจคของเราผ่านไปได้โดยราบลื่นนั่นเอง หากนำมาใช้ในทีมด้วยก็ยิ่งทำให้พวกเราเข้าใจตรงกันได้มากขึ้น
.
"มันเลยเปรียบเสมือนข้อตกลงในการทำงานร่วมกันนั่นเอง <3"
.
แต่จะต้องบอกก่อนนะว่า ไม่ใช่ทุกงานที่เหมาะกับ Coding Style นั้น ๆ หรือ ไม่ใช่ทุกปัญหาจะมีใน Coding Style บอกว่าแก้ไขยังไง หลายครั้งเราอาจจะต้องเพิ่มเติมเอาเอง
.
⚠️ "แต่สิ่งที่เพิ่มเติมจะต้องคุยกันในทีมให้เคลียร์ก่อนเสมอนะ !"
.
ดังนั้นวันนี้เรามาดู Coding Style Guide ของแต่ละภาษาไปพร้อมกันเลยดีกว่า !! (บางภาษาอาจมีตัวน่าสนใจมากกว่า 1 ตัว แอดก็รวมไว้ให้แล้วจ้า)
.
👉 ภาษา Java
.
http://www.oracle.com/technetwork/java/codeconventions-150003.pdf
https://google.github.io/styleguide/javaguide.html
.
👉 ภาษา C
.
http://www.maultech.com/chrislott/resources/cstyle/indhill-annot.pdf
http://www.maultech.com/chrislott/resources/cstyle/Peter_CStyleGuide.pdf
.
👉 ภาษา C++
.
http://www.maultech.com/chrislott/resources/cstyle/Wildfire-C++Style.html
http://www.maultech.com/chrislott/resources/cstyle/CppCodingStandard.html
.
👉 ภาษา Python
.
https://www.python.org/dev/peps/pep-0008/
.
👉 ภาษา C#
https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/index
.
👉 ภาษา JavaScript
.
https://github.com/airbnb/javascript
http://google.github.io/styleguide/javascriptguide.xml
https://www.w3schools.com/js/js_conventions.asp
.
👉 ภาษา Dart
https://dart.dev/guides/language/effective-dart/style
.
👉 ภาษา PHP
http://www.php-fig.org/psr/psr-1/
http://pear.php.net/manual/en/standards.php
.
👉 ภาษา Objective-C
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html
.
👉 ภาษา Kotlin
https://kotlinlang.org/docs/reference/coding-conventions.html
.
👉 ภาษา Swift
https://github.com/raywenderlich/swift-style-guide
.
👉 ภาษา Visual Basic.NET
https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/index
.
👉 ภาษา Ruby
https://github.com/bbatsov/ruby-style-guide
https://github.com/airbnb/ruby
.
👉 ภาษา R
http://web.stanford.edu/class/cs109l/unrestricted/resources/google-style.html
.
👉 ภาษา Go
https://golang.org/doc/effective_go.html
.
"เรียบร้อย ครบจบทุก Guideline ใครที่อยากทำงานกับทีมง่าย ๆ แนะนำให้ลองใช้กันดูได้เลยจ้า" <3 <3 <3
.
#borntoDev - 🦖 สร้างการเรียนรู้ที่ดีสำหรับสายไอทีในทุกวัน
java library class 在 โปรแกรมเมอร์ไทย Thai programmer Facebook 的精選貼文
หนึ่งในปัญหาคลาสิก เวลาเขียนโปรแกรมที่ทุกคนต้องเจอเลย
ก็คือการบวกลบเลขทศนิยมในภาษาโปรแกรม ของบางภาษา นี้แหละ
เช่น JavaScript, Python, Perl, C#, C, C++, Java, PHP, Fortran
(และอื่นๆ อีกหลายภาษาที่ไม่ได้กล่าวถึง)
.
หลายครั้งที่มันอาจเพี้ยนได้ เช่น
👉 0.1+0.2 ไม่ได้เท่ากับ 0.3
แต่ได้เป็น 0.30000000000000004
.
👉 หรือ 0.1 บวกกัน 10 ครั้ง ก็ไม่ได้เป็น 1
แต่ได้เป็น 0.9999999999999999
.
คนเขียนโปรแกรมเจอแบบนี้เข้าไป
ก็เหมือนมวยโดนหมัดน๊อคมึนงงในดงโค้ด
:
:
แต่ใช่ว่ามันจะเพี้ยนทุกครั้ง ซะเมื่อไร เช่น
0.5+0.5 = 1 (ถูกต้องเป๊ะ)
0.2+0.3 = 0.5 (บังเอิญไม่เพี้ยน)
.
สำหรับ กรณี 0.2 กับ 0.3 มันถูกตัดเศษเหลือเป็น
0.2000000000000000111022302462515654042363166809082031250
กับ
0.2999999999999999888977697537484345957636833190917968750
พอบวกกันจึงได้ 0.5 พอดี แบบฟลุ๊คๆๆ ซึ่งไม่ควรทำได้
(ตรงสอบดูได้ 0.2+0.3 == 0.5 ได้ค่าออกมาเป็น true)
:
:
สาเหตุที่เป็นเช่นนี้
ก็เพราะว่าคอมพิวเตอร์มันรู้จักแต่ เลขฐาน2 อะนะ
ต่อให้เราเขียนโค้ดใช้เลขฐาน10 ก็ตาม
สุดท้ายเวลาโค้ดมันถูกรัน ก็จะกลายเป็นเลขฐาน 2 อยู่ดี
.
😨 แล้วก็เป็นความซวยที่จะมาเยือนคนเขียนโปรแกรม
เพราะเวลาแปลงเลขฐาน10 ไปเป็นเลขฐาน 2
บางกรณีมันแปลงแล้ว ดันได้ตัวเลขที่ไม่รู้จบเสียด้วยซิ
จึงทำให้การเก็บทศนิยมผิดเพี้ยนไปได้
.
สำหรับรูปแบบการจัดเก็บเลขทศนิยม ในหลายภาษา
เขาจะนิยมใช้มาตรฐาน IEEE-754 floating point
เช่น 0.1 จะถูกมองว่าคือ 1/10
.
เมื่อเก็บเป็นเลขทศนิยมฐานสอง
ตามมาตรฐาน IEEE-754 floating point จะได้เป็น
0.0001100110011001100110011001100110011001100110011...
เป็นทศนิยมไม่รู้จบในรูปเลขฐานสอง ....นี้คือสิ่งที่คอมมองเห็น
.
พอคอมแปลงกลับมาเป็นทศนิยม เพื่อให้มนุษย์โลกอ่านเข้าใจ
ในรูปฐาน 10 ก็จะได้เป็น
0.1000000000000000055511151231257827021181583404541015625
ทว่าคอมมันจะตัดให้เหลือแค่ 0.1 (คนจึงเห็นแค่นี้)
:
🤔 ซึ่งความเพื้ยนแบบนี้
แน่นอนทำให้เกิดบั๊กเวลาคำนวณตัวเลข
- ยิ่งงานต้องการคำตอบที่ละเอียดมาก เช่น งานธนาคาร ก็จะประสบปัญหา เป็นต้น
- หรือเวลานำไปใช้ในเงื่อนไขเปรียบเทียบพวก if, while ฯลฯ ก็อาจมีบั๊กเกิดขึ้นได้ เป็นต้น
.
😀 แต่ไม่ต้องห่วง ในหลายๆ ภาษาเขาจะมีวิธีแก้ปัญหานี้อยู่ครับ
ป้องกันการคำนวณตัวเลข ไม่ให้คลาดเคลื่อน เช่น
- ใน Java ก็จะมีคลาส BigDecimal เอาไว้บวกลบคูณหาร สำหรับเลขทศนิยมโดยเฉพาะ
- ใน Python ก็จะมีคลาสคล้ายๆ กัน เช่น Decimal
- ส่วนใน JavaScript อาจใช้ไลบรารี่ ซึ่งมีให้เลือกเยอะเช่น
https://github.com/MikeMcl/decimal.js/
https://github.com/MikeMcl/bignumber.js/
https://github.com/MikeMcl/big.js/
- ภาษาอื่นที่เหลือลองไปศึกษาเองดูนะครับ
.
.
เรื่องบวกลบคูณหาร เลขทศนิยม ถือเป็นเรื่องสำคัญที่ไม่ควรมองข้าม
โดยส่วนตัวก็เคยเจอความเผลอเรอตรงนี้
ในระดับโปรเจคระดับธนาคาร ก็เคยพลาดมาแล้ว
สุดท้ายต้องมาไล่นั่งแก้โค้ดหลายบรรทัด
เสียเวลานั่งไล่ test ใหม่อีกรอบอีก
.
หมายเหตุเห็นคอมเมนต์สงสัยว่า
PHP กับ C# รอดชะตากรรมเดียวกันไหม ?
ก็บอกว่าไม่รอดครับ
.
// ลองดูตัวอย่างโค้ด C#
Console.WriteLine( ((0.1+0.2) == 0.3)); // False
Console.WriteLine( ((0.1+0.2) == 0.30000000000000004)); // True
// ลองดูตัวอย่างโค้ด PHP
echo number_format(0.1+0.2 , 17);
.
++++++
เขียนโดย โปรแกรมเมอร์ไทย thai programmer
อ่านเรื่อง IEEE-754 floating point ได้ที่
https://th.wikipedia.org/wiki/จำนวนจุดลอยตัว
One of the programming time class issues that everyone needs to encounter.
It's a positive, negative, decimal number in the programming language of some languages.
เช่น JavaScript, Python, Perl, C#, C, C++, Java, PHP, Fortran
(And many other languages not mentioned)
.
So many times it can be crazy like
👉 0.1 + 0.2 is not equal to 0.3
But got to be 0.30000000000000004
.
👉 or 0.1 plus 10 times. It's not 1
But got to be 0.9999999999999999
.
The programmers found this.
It's like boxing. I got a punch. I'm confused in the code.
:
:
But it's not crazy every time.
0.5 0.5 0.5 0.5 1 (Exactly correct)
0.2 0.2 0.3 0.3 0.5 (accidentally not crazy)
.
For 0.2 and 0.3 cases, it was cut as debris.
0.2000000000000000111022302462515654042363166809082031250
With
0.2999999999999999888977697537484345957636833190917968750
Let's be positive. I got 0.5 fits. Fluke which I shouldn't do.
(I can see the exam. 0.2 + 0.3 == 0.5 I got the value to be true)
:
:
The cause is like this
It's because computer only knows the base number 2
Even if we write code, use base number 10
Finally, when the code is run, it will become the base number 2 anyway.
.
😨 and it's bad luck to visit the programmers.
Because time converts base number 10 to base number 2
In some cases, it's converted. I get an endless number.
So that the decimal collection is wrong.
.
For decimal numbers storage in multiple languages
He will be popular with IEEE-754 floating point standards.
For example, 0.1 will be seen as 1/10
.
When it's kept as a decimal number, binary digits.
According to IEEE standards-754 floating point will be.
0.0001100110011001100110011001100110011001100110011...
It's an endless decimal in the second base number.... This is what the computer sees.
.
When the computer comes back to a decimal, so that the world can read and understand.
In the base photo, 10 will be.
0.1000000000000000055511151231257827021181583404541015625
But the computer will cut it down to 0.1 (that's all I see)
:
🤔 This kind of friendship
Definitely make a time bug. Calculates numbers.
- The more jobs require a detailed answer, such as banking job, the problem is etc.
- or time to apply in comparison terms. If, while etc, there may be a buck happening. etc.
.
😀 But don't worry. In many languages, there will be a solution to this problem.
Prevent calculation of numbers from discrepancy, e.g.
- In Java, there will be a BigDecimal class. Plus, multiply, multiply for decimal numbers.
- In Python there are similar classes like Decimal
- Parts in JavaScript may use a lot of library to choose from, e.g.
https://github.com/MikeMcl/decimal.js/
https://github.com/MikeMcl/bignumber.js/
https://github.com/MikeMcl/big.js/
- Other languages. Let's study it yourself.
.
.
A positive, multiply, digging, decimal numbers are important things that shouldn't be overlooked.
Personally, I have experienced the accident.
Bank level project. I have already missed it.
Finally, I have to sit and solve many lines of code.
Waste of time. Sit to chase the new test again.
.
Note, see comments, wonder if
PHP and C #survive the same fate?
I told you that you won't survive.
.
// Check out the C code trailer #
Console.WriteLine( ((0.1+0.2) == 0.3)); // False
Console.WriteLine( ((0.1+0.2) == 0.30000000000000004)); // True
// Check out the PHP code trailer
echo number_format(0.1+0.2 , 17);
.
++++++
Written by Thai programmer thai coder
Read IEEE-754 floating point at
https://th.wikipedia.org/wiki/จำนวนจุดลอยตัวTranslated
java library class 在 prasertcbs Youtube 的最讚貼文
การสร้าง Class library (JAR: Java ARchive)
============
ดาวน์โหลดไฟล์ตัวอย่างได้ที่ http://goo.gl/G5BNCN
============
playlist สอนการเขียนโปรแกรมเชิงวัตถุด้วย Java เบื้องต้น
https://www.youtube.com/watch?v=zC_0xOSX1dY&list=PLoTScYm9O0GEvHKqqib-AdVFwVe_2ln8W
============
playlist สอนภาษาจาวา Java เบื้องต้น
https://www.youtube.com/watch?v=O3rW9JvADfU&list=PLoTScYm9O0GF26yW0zVc2rzjkygafsILN
============
playlist สอนจาวา Java FileIO การอ่านเขียนไฟล์
https://www.youtube.com/watch?v=y4dfsuShUaw&list=PLoTScYm9O0GEsSpaLgFDuPWzUEZdtnuWs
============
playlist สอนจาวา Java การใช้ Collections ต่าง ๆ เช่น ArrayList, Map, Set, Stack
https://www.youtube.com/watch?v=JYTIQip_pak&list=PLoTScYm9O0GEskLFgdC02Swit1fcDWspM
============
playlist สอนการทำ Unit Test ภาษาจาวา Java
https://www.youtube.com/watch?v=R11yg8hKApU&list=PLoTScYm9O0GHiK3KNdH_PrNB0G3-kb1Bi
============
playlist สอนภาษา C เบื้องต้น
https://www.youtube.com/watch?v=Z_u8Nh_Zlqc&list=PLoTScYm9O0GHHgz0S1tSyIl7vkG0y105z
============
playlist สอนภาษา C# เบื้องต้น
https://www.youtube.com/watch?v=hhl49jwOIZI&list=PLoTScYm9O0GE4trr-XPozJRwaY7V9hx8K
============
playlist สอนภาษา C++ เบื้องต้น
https://www.youtube.com/watch?v=_NHyJBIxc40&list=PLoTScYm9O0GEfZwqM2KyCBcPTVsc6cU_i
============
playlist สอนภาษาไพธอน Python เบื้องต้น
https://www.youtube.com/watch?v=DI7eca5Kzdc&list=PLoTScYm9O0GH4YQs9t4tf2RIYolHt_YwW
============
playlist สอนภาษาไพธอน Python การเขียนโปรแกรมเชิงวัตถุ (OOP: Object-Oriented Programming)
https://www.youtube.com/watch?v=4bVBSluxJNI&list=PLoTScYm9O0GF_wbU-7layLaSuHjzhIRc9
============
playlist สอนภาษา R เบื้องต้น
https://www.youtube.com/watch?v=oy4qViQLXsI&list=PLoTScYm9O0GF6qjrRuZFSHdnBXD2KVICp
============
playlist สอนภาษา PHP เบื้องต้น
https://www.youtube.com/watch?v=zlRDiXjYVo4&list=PLoTScYm9O0GH_6LARFxozL_viEsXV2wgO
============
เชิญสมัครเป็นสมาชิกของช่องนี้ได้ที่
https://www.youtube.com/subscription_center?add_user=prasertcbs
![post-title](https://i.ytimg.com/vi/2vG5zP8GY0M/hqdefault.jpg?sqp=-oaymwEbCKgBEF5IVfKriqkDDggBFQAAiEIYAXABwAEG&rs=AOn4CLAkxGiueTQYjynE_QLUrRsDKBlhgA)
java library class 在 Java - Define a common interface for classes from an external ... 的推薦與評價
... <看更多>
java library class 在 When creating a library, is there a way to make certain classes ... 的推薦與評價
Use package-private , which is what you get when you specify no access modifier at all. It limits a class or method to only be visible to ... ... <看更多>
java library class 在 Java Class Librares - YouTube 的推薦與評價
Learn what are packages in Java and how to use Math methods with example programsFor Notes on ... For Questions on Library classes click on ... ... <看更多>