From d97cb40de36cc542aac9dfa9b547462f61bd0694 Mon Sep 17 00:00:00 2001 From: uvhareesh Date: Tue, 13 May 2025 18:56:40 +0530 Subject: [PATCH 1/2] Data Types Concept --- src/coreJava/DataTypes.java | 90 +++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/coreJava/DataTypes.java diff --git a/src/coreJava/DataTypes.java b/src/coreJava/DataTypes.java new file mode 100644 index 0000000..7b09fc9 --- /dev/null +++ b/src/coreJava/DataTypes.java @@ -0,0 +1,90 @@ +package coreJava; + +public class DataTypes { + + public static void main(String[] args) { + // Numeric Data Types + + int a=100, b=200; + System.out.println("The vlaue of a is :"+a); + System.out.println("The vlaue of b is :"+b); + System.out.println(a+b); + System.out.println("The sum of an and b is : "+(a+b)); + + byte by=125; + System.out.println(by); + + short sh=32767; + System.out.println(sh); + + long l=21212121234443534L; // literal is needed + // L should add, it can be lower or uppercase + System.out.println(l); + + // Decimal numbers - float, double + + float item_price=15.5f; // literal is needed + //f should add, it can be lower or uppercase + System.out.println(item_price); + + double dbl=1234.4343412; + System.out.println(dbl); + + // characters + + char grade='A'; // single character in single quotes - '' + System.out.println(grade); + + String name="Harish"; // String is non-premitive type and multiple characters with double quotes - "" + System.out.println(name); + + //char ch='abc'; //invalid + //Stirng ch='abc';//invalid + //String ch='A';//invalid + String ch="A"; //valid + System.out.println(ch); + + boolean bl=true; //allows only true or false + System.out.println(bl); + + boolean bl1=false;//allows only true or false + System.out.println(bl1); + + //boolean bl="true";//invalid + //boolean bl="false";//invalid + + //String bl=true;//invalid + String bl2="true";//valid + + //difference between variable and const/final + int x=100; + System.out.println(x); + x=200; + System.out.println(x); + + final int y=300; + System.out.println(y); + // y=400;// not allowed + //System.out.println(y); + + // variables declaration without final keyword we can change the values but wiht final keyword we cnat chaneg the value. in javascript instea dof final, const keyword is used. + + //java is statistically typed programming language + //python is dynamically typed programming language + //javascript is dynamically typed scripting language + + //Example : + + int q=100; + //x="welcome";//it is not allowed in java but in javascript and python it is allowed + //in python or javascript we no need to specify the data types explicitly. + + /* + r=100; + r="welcome"; + */ + //it is allowed in dynamically typed programming language - javascript / python + + } + +} From 6fbcc4ac72542b4e403ea1edcc05e5cef823d071 Mon Sep 17 00:00:00 2001 From: uvhareesh Date: Tue, 13 May 2025 19:24:40 +0530 Subject: [PATCH 2/2] Variables concept added in Data types.java file --- src/coreJava/DataTypes.java | 49 +++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/coreJava/DataTypes.java b/src/coreJava/DataTypes.java index 7b09fc9..6f0e47c 100644 --- a/src/coreJava/DataTypes.java +++ b/src/coreJava/DataTypes.java @@ -3,11 +3,54 @@ public class DataTypes { public static void main(String[] args) { + + //variables + + //int s; //declaration + //s=100; //assignment + + int s=100; // declaration+assignment + System.out.println(s); + + s=200; + System.out.println(s); + + /* + // approach1 // if all the variables belongs to different data types + int p=1; + int o=2; + int i=3; + */ + + /* approach2 // only if allthe variable are belongs to same data type + int p,o,i; + p=1; + o=2; + i=3; + */ + + // approach3 //only if all the variable are belongs to same data type + int p=1,o=2,i=3; + + //for meaningful message in print statement we can use concatenation method + System.out.println("The Value of p is :"+p); + System.out.println("The Value of o is :"+o); + System.out.println("The Value of i is :"+i); + + // in single line we printed all variable values + System.out.println(p+""+o+""+i+""); + + // in print statement we used join method for each value with "" + + +//-------------------------------------------------------------------------- + // Data types + // Numeric Data Types int a=100, b=200; - System.out.println("The vlaue of a is :"+a); - System.out.println("The vlaue of b is :"+b); + System.out.println("The Value of a is :"+a); + System.out.println("The Value of b is :"+b); System.out.println(a+b); System.out.println("The sum of an and b is : "+(a+b)); @@ -56,6 +99,8 @@ public static void main(String[] args) { //String bl=true;//invalid String bl2="true";//valid + //---------------------------------------------------------------------- + //difference between variable and const/final int x=100; System.out.println(x);