🚩 نکته : زبان جاوا به کوچک و بزرگ بودن حروف حساس هست پس یادتون باشه همیشه برای نام دادن کلاس ها حرف اولش رو بزرگ بنویسید مثل مثال تصویر بالا که برای ایجاد کلاس پیش فرض نام کلاس رو Main دادیم و اما package ها هم نوعی فضای نامی هستن که در زبان های دیگر با عنوان دیگری ازش نام بردیم
ولی برای اجرا کردن کدهامون باید یه قسمتی رو به این کلاس اضافه کنیم و اون روال اجرایی هست تا بتونیم داخل اون روال کد بنویسیم و اجراش کنیم
حالا داخل این کلاس و روال می تونین اولین برناممون رو برای شروع آموزش برنامه نویسی جاوا بنویسیم و تست کنیم و خودمون رو اماده کنیم برای تمرین روی آموزش هایی که در کانال خواهیم داد و اولین برنامه ما همون چاپ کلمه معروف hello world هست
خود در این جلسه به انواع داده ای و تعریف متغیرها با نوع داده ای مختلف در زبان جاوا می پردازیم
اگر آموزش های زبان ++c رو که قبلا در این کانال آموزش داده بودیم دنبال کرده بودید به جرات می توان گفت تقریبا اصول برنامه نویسی جاوا رو هم فرا گرفته اید چون شباهت های زیادی بین دو زبان وجود دارد
در زبان برنامه نویسی جاوا ما ۸ نوع متغیر داریم و نکته ای که در اینجا می بایست مد نظر قرار داده شود این است که هر متغیر همچون ظرفی است که می تواند صرفا نوع خاصی از Data یا داده را در خود ذخیره سازد. در طول آموزش ها با انواع متغیرها، نحوه به کار گیری آن ها، نحوه اختصاص Value یا مقدار به آن ها، به کار گیری اعمال اصلی میان آن ها مثل جمع و تفرین و ... آشنا خواهیم شد.
به منظور اختصاص دادن مقداری به یک متغیر می بایست از علامت = استفاده کرده و در نهایت یک ; قرار داد (در واقع در زبان برنامه نویسی جاوا و برخی از دیگر زبان های برنامه نویسی ; عملکردی همچون نقطه در حین نگارش یک متن فارسی دارد. به عبارت دیگر، با قرار دادن یک ; در انتهای یک دستور، به جاوا می گوییم که به پایان دستور رسیده ایم.)
در زبان جاوا نیز برای مدیریت حافظه بهتر نوع داده ای صحیح به 4 قسمت تقسیم شده است به ترتیب از ظرفیت کم به بالا شامل byte, short, int, long برای آشنایی کامل این نوع داده ای به موارد زیر توجه کنید
byte:
Byte data type is an 8-bit signed two's complement integer.
Minimum value is -128 (-2^7)
Maximum value is 127 (inclusive)(2^7 -1)
Default value is 0
Byte data type is used to save space in large arrays, mainly in place of integers, since a byte is four times smaller than an int.
Example: byte a = 100 , byte b = -50
short:
Short data type is a 16-bit signed two's complement integer.
Minimum value is -32,768 (-2^15)
Maximum value is 32,767 (inclusive) (2^15 -1)
Short data type can also be used to save memory as byte data type. A short is 2 times smaller than an int
Default value is 0.
Example: short s = 10000, short r = -20000
int:
Int data type is a 32-bit signed two's complement integer.
Minimum value is - 2,147,483,648.(-2^31)
Maximum value is 2,147,483,647(inclusive).(2^31 -1)
Int is generally used as the default data type for integral values unless there is a concern about memory.
The default value is 0.
Example: int a = 100000, int b = -200000
long:
Long data type is a 64-bit signed two's complement integer.
Minimum value is -9,223,372,036,854,775,808.(-2^63)
Maximum value is 9,223,372,036,854,775,807 (inclusive). (2^63 -1)
This type is used when a wider range than int is needed.
Default value is 0L.
Example: long a = 100000L, long b = -200000L
Byte data type is an 8-bit signed two's complement integer.
Minimum value is -128 (-2^7)
Maximum value is 127 (inclusive)(2^7 -1)
Default value is 0
Byte data type is used to save space in large arrays, mainly in place of integers, since a byte is four times smaller than an int.
Example: byte a = 100 , byte b = -50
short:
Short data type is a 16-bit signed two's complement integer.
Minimum value is -32,768 (-2^15)
Maximum value is 32,767 (inclusive) (2^15 -1)
Short data type can also be used to save memory as byte data type. A short is 2 times smaller than an int
Default value is 0.
Example: short s = 10000, short r = -20000
int:
Int data type is a 32-bit signed two's complement integer.
Minimum value is - 2,147,483,648.(-2^31)
Maximum value is 2,147,483,647(inclusive).(2^31 -1)
Int is generally used as the default data type for integral values unless there is a concern about memory.
The default value is 0.
Example: int a = 100000, int b = -200000
long:
Long data type is a 64-bit signed two's complement integer.
Minimum value is -9,223,372,036,854,775,808.(-2^63)
Maximum value is 9,223,372,036,854,775,807 (inclusive). (2^63 -1)
This type is used when a wider range than int is needed.
Default value is 0L.
Example: long a = 100000L, long b = -200000L
در موارد بالا به صورت کامل نوع های داده ای اعداد صحیح دقیقا توضیح داده شده است برای مثال ظرفیت هر نوع داده ای چقدر هست و اینکه تا چه سقف داده ای می تونیم به متغیرهایی که از آن داده ای تعریف شده اند مقدار بدیم و اما برای نوغ داده ای اعداد اعشاری نیز در زبان جاوا همین تقسیم بندی رو داریم نوع داده ای float و نوع داده ای double برای آشنا شدن با این نوع داده ای به موارد زیر توجه کنید
float:
Float data type is a single-precision 32-bit IEEE 754 floating point.
Float is mainly used to save memory in large arrays of floating point numbers.
Default value is 0.0f.
Float data type is never used for precise values such as currency.
Example: float f1 = 234.5f
double:
double data type is a double-precision 64-bit IEEE 754 floating point.
This data type is generally used as the default data type for decimal values, generally the default choice.
Double data type should never be used for precise values such as currency.
Default value is 0.0d.
Example: double d1 = 123.4
Float data type is a single-precision 32-bit IEEE 754 floating point.
Float is mainly used to save memory in large arrays of floating point numbers.
Default value is 0.0f.
Float data type is never used for precise values such as currency.
Example: float f1 = 234.5f
double:
double data type is a double-precision 64-bit IEEE 754 floating point.
This data type is generally used as the default data type for decimal values, generally the default choice.
Double data type should never be used for precise values such as currency.
Default value is 0.0d.
Example: double d1 = 123.4
در بالا توضیحات نوع های داده ای اعشاری اعم از ظرفیت که براشون تعریف شده و سقف مقداری که میشه به متغیرهایی ار این نوع های داده ای می تونیم اختصاص بدیم اشاره شده است نوع داده ای دیگری که در زبان جاوا هست نوع داده ای boolean هست مقداری که این نوع داده ای فقط می گیرد true و یا false هست ناگفته نماند هر مقداری به جز صفر به متغیرهایی از این نوع دادهای بدهیم همان نقش کلمه کلیدی را برای ما ایفا می کند
boolean:
boolean data type represents one bit of information.
There are only two possible values: true and false.
This data type is used for simple flags that track true/false conditions.
Default value is false.
Example: boolean one = true
boolean data type represents one bit of information.
There are only two possible values: true and false.
This data type is used for simple flags that track true/false conditions.
Default value is false.
Example: boolean one = true