ប្រភេទអញ្ញាតជា Local Variables | Local Variables | Part 6.3 |JAVA ថ្នាក់ទី១ | JAVA For Beginner
#រៀនសរសេរកូដជាមួយចិត្រា #javaprogramming #javabasics #codingwithchitra #sololearncoding
ជម្រាបសួរខ្ញុំបាទចិត្រាក្នុងវីដេអូទនេះ ខ្ញុំសូមណែនាំអំពី ប្រភេទអញ្ញាតជា Local Variables | Local Variables | Part 6.3 |JAVA ថ្នាក់ទី១ | JAVA For Beginner
មុជអោយជ្រៅទៅអោយដល់
+ តើពួកវារស់នៅទីណា?
- Methods, Constructor, Block
- ពួកវារស់នៅបណ្តោះអាសន្ន។ មានន័យថានៅពេលដែល Methods, Constructor, Block អសកម្មនោះ ពួកវានឹងរលាយទៅបាត់ស្រមោល។
+ ទីចាប់ផ្តើម និងទីបញ្ចប់:អត្ថិភាពបណ្តោះអាសន្ន
- នៅពេលដែលផ្នែកកូដរបស់ពួកវាចាប់ផ្តើម អញ្ញាត Local Variable នឹងកើត។
- វានឹងស្នាក់នៅក្នុង Memory បណ្តោះអាសន្ន
- នៅពេលដែលផ្នែកនៃកូដរបស់ពួកវា ត្រូវបានបញ្ចប់ នោះ Local Variable ក៏បញ្ចប់ទៅតាមហ្នឹងដែរ ហើយ Memory និងទំនេរឡើងវិញ
+ ឯកជនភាព:វាមិនត្រូវបានចែកចាយទៅខាងក្រៅឡើយ
- វាមិនត្រូវាការ Access Modifier (public, protected, private…)
- វាប្រើបានតែនៅក្នុង Methods, Constructor , Block ដែលយើងបានប្រកាស់ប្រើ
+ Stack Life: Efficient Memory Management
- វាស្ថិតនៅក្នុង Stack LIFO (Last-In-First-Out) data structure.
- អញ្ញាតដែលប្រកាស់ក្រោយគឺស្ថិតនៅលើគេ ងាយស្រួលយកមកប្រើ ហើយវាចេញមុនគេ
+ Use It or Lose It: Initialization is Ke
- ពេលប្រកាស់វាយកមកប្រើវាមិនមានតំលៃនោះទេ(No Default Value)
ដូចនេះមុនយកវាទៅប្រើតូវតែផ្តល់តំលៃអោយវាជាមុនសិន(Inintailize value)
====================================================
លំហាត់នៅផ្ទះ
====================================================
ចូរបង្កើតកម្មវិធីមួយដោយដាក់ឈ្មោះ Class ថា CircleCalculator។ នៅក្នុង Class នោះចូលបង្កើត Method មួយឈ្មោះថា៖ calculateArea() សម្រាប់គណាផ្ទៃក្រឡារង្វង់។
រូបមន្ត Area = π x radius x radius; (π=ផៃស្មើរ 3.14, radius= កាំនៃរង្វង់)
Declare a local variable named radius of type double inside the calculateArea method.
Assign a value to the radius variable. You can choose any positive value for the radius.
Declare a local variable named area of type double to store the calculated area.
Use the formula to calculate the area and store the result in the area variable.
Print the calculated area to the console.
កម្រងវីដេអូមេរៀន|Play List 👉 https://youtube.com/playlist?list=PLSJTJj3gU6qhkjSEUmgBKGJnn0ob1NZSu&si=rcvL8CwF_5EGx_2n
YouTube Channel 👉 https://www.youtube.com/@codingwithchitra
Facebook Page 👉 https://www.facebook.com/khmshared
Telegram Channel 👉 https://t.me/codingwithchitra