COURSES
MBAData Science & AnalyticsDoctorate Software & Tech AI | ML MarketingManagement
Professional Certificate Programme in HR Management and AnalyticsPost Graduate Certificate in Product ManagementExecutive Post Graduate Program in Healthcare ManagementExecutive PG Programme in Human Resource ManagementMBA in International Finance (integrated with ACCA, UK)Global Master Certificate in Integrated Supply Chain ManagementAdvanced General Management ProgramManagement EssentialsLeadership and Management in New Age BusinessProduct Management Online Certificate ProgramStrategic Human Resources Leadership Cornell Certificate ProgramHuman Resources Management Certificate Program for Indian ExecutivesGlobal Professional Certificate in Effective Leadership and ManagementCSM® Certification TrainingCSPO® Certification TrainingLeading SAFe® 5.1 Training (SAFe® Agilist Certification)SAFe® 5.1 POPM CertificationSAFe® 5.1 Scrum Master Certification (SSM)Implementing SAFe® 5.1 with SPC CertificationSAFe® 5 Release Train Engineer (RTE) CertificationPMP® Certification TrainingPRINCE2® Foundation and Practitioner Certification
Law
Job Linked
Bootcamps
Study Abroad
Master of Business Administration (90 ECTS)Master of Business Administration (60 ECTS)Master in Computer Science (120 ECTS)Master in International Management (120 ECTS)Bachelor of Business Administration (180 ECTS)B.Sc. Computer Science (180 ECTS)MS in Data AnalyticsMS in Project ManagementMS in Information TechnologyMasters Degree in Data Analytics and VisualizationMasters Degree in Artificial IntelligenceMBS in Entrepreneurship and MarketingMSc in Data AnalyticsMS in Data AnalyticsMaster of Science in AccountancyMS in Computer ScienceMaster of Science in Business AnalyticsMaster of Business Administration MS in Data ScienceMS in Information TechnologyMaster of Business AdministrationMS in Applied Data ScienceMaster of Business AdministrationMS in Data AnalyticsM.Sc. Data Science (60 ECTS)Master of Business AdministrationMS in Information Technology and Administrative Management MS in Computer Science Master of Business Administration MBA General Management-90 ECTSMSc International Business ManagementMS Data Science MBA Business Technologies MBA Leading Business Transformation Master of Business Administration MSc Business Intelligence and Data ScienceMS Data Analytics MS in Management Information SystemsMSc International Business and ManagementMS Engineering ManagementMS in Machine Learning EngineeringMS in Engineering ManagementMSc Data EngineeringMSc Artificial Intelligence EngineeringMPS in InformaticsMPS in Applied Machine IntelligenceMS in Project ManagementMPS in AnalyticsMS in Project ManagementMS in Organizational LeadershipMPS in Analytics - NEU CanadaMBA with specializationMPS in Informatics - NEU Canada Master in Business AdministrationMS in Digital Marketing and MediaMS in Project ManagementMaster in Logistics and Supply Chain ManagementMSc Sustainable Tourism and Event ManagementMSc in Circular Economy and Sustainable InnovationMSc in Impact Finance and Fintech ManagementMS Computer ScienceMS in Applied StatisticsMS in Computer Information SystemsMBA in Technology, Innovation and EntrepreneurshipMSc Data Science with Work PlacementMSc Global Business Management with Work Placement MBA with Work PlacementMS in Robotics and Autonomous SystemsMS in Civil EngineeringMS in Internet of ThingsMSc International Logistics and Supply Chain ManagementMBA- Business InformaticsMSc International ManagementMBA in Strategic Data Driven ManagementMaster of Business AdministrationMSc Digital MarketingMBA Business and MarketingMaster of Business AdministrationMSc Digital MarketingMSc in Sustainable Luxury and Creative IndustriesMSc in Sustainable Global Supply Chain ManagementMSc in International Corporate FinanceMSc Digital Business Analytics MSc in International HospitalityMSc Luxury and Innovation ManagementMaster of Business Administration-International Business ManagementMS in Computer EngineeringMS in Industrial and Systems EngineeringMSc International Business ManagementMaster in ManagementMSc MarketingMSc Business ManagementMSc Global Supply Chain ManagementMS in Information Systems and Technology with Business Intelligence and Analytics ConcentrationMSc Corporate FinanceMSc Data Analytics for BusinessMaster of Business AdministrationMaster of Business Administration 60 ECTSMaster of Business Administration 90 ECTSMaster of Business Administration 60 ECTSMaster of Business Administration 90 ECTSBachelors in International ManagementMS Computer Science with Artificial Intelligence and Machine Learning ConcentrationMaster of Business Administration
For College Students

Variables in Java - Complete Explaination

$$/$$

Now that you know all the thinking process behind using something like variables, let us move on to taking a look at how would you declare a variable in Java.

$$/$$

Video Transcript

 

So now we are going to take a look in code how you can declare these simple variables. So for example, if you wish to store the marks of atom inside containers, then what was the first step? Well, the first step was telling what kind of information you will be storing. So here 72 and 85 are the marks of this particular student are always going to be integers. So I'll say that the kind of information which I want to store is int. So you don't need to worry about it at this stage because int is a keyword which is used in Java to tell the program that you are going to store integers inside this. So now we are done with telling the computer what kind of information we'll be storing. The next step? Well, the next step is giving a name to these variables. For example, you want to say that this particular container or this particular variable, you want to call it like marks one. Then you say int marks one. So here it tells that you're going to store integers and this is the name of this particular variable. And how do you tell the computer that your statement is complete? Well, you put a semicolon after this. So this is a standard way to declare a new variable. This semicolon is necessary to tell the computer that this is the particular whole statement that it needs to evaluate. Next, suppose if you wish to store this other marks here, then how would you do that? Well, I say that I wish to store int, which is again the keyword for integers in Java. And I say marks two and I put a semicolon to complete this statement. So till this point, computer has assigned two separate boxes called marks one and marks two and it knows that they are always going to contain integers in it. Now, if ever in future you try to assign some other things inside these containers, it will throw an error. For example, if you try to store the name of these particular students in these two containers, then the program is going to throw an error.

 

Now moving on, suppose that I wish to store the name of these two students. So whenever you are storing textual information or information which is in the form of words or multiple characters, then the kind of information which you are going to store, you can tell it to the computer by saying that you are going to store a string. Here again, you need not worry about this, but for now just understand that string is a keyword which is used in Java to tell the program that you are going to store words or multiple letters in this particular variable. So now we are done with telling the computer what kind of information you're going to store. Next step is giving a name to these variables. So I say suppose Adam is my student number one. So I say string student one. And now am I missing something? Well, yes. We also have to put the semicolon here to complete this variable declaration. Similarly, now, if Lucy is student number two, then in order to declare a variable for her, I say string student two and put a semicolon. So, in this manner, I have now assigned four different containers. Two to contain the marks for Adam and two for containing the name of two students. So now we are done with learning. How do we declare variables in Java?

 

Video Recap

 

 

  • To declare variables in Java, first, specify the type of data you will be storing, such as integers or strings.

  • Integers are indicated by the keyword "int," and strings are indicated by the keyword "string."

  • Once you have specified the data type, give a name to the variable, such as "marks one" or "student one."

  • Remember to add a semicolon after the variable declaration to indicate the end of the statement.

  • If you try to store a different type of data in the variable, such as storing a name in a container for integers, the program will throw an error.

  • By following these steps, you can declare multiple variables in Java to store different types of data, such as storing marks and names of students in separate containers.

 

In Java, this is how you declare a variable:

You first tell the computer what kind of data you would be storing in the variable and then you assign a variable name to the variable. For example:

 

int distance;

Now that you are done with declaring a variable, the next logical step is to assign values to it.

This process is known as Variable Initialization.

 

In the following video, you will learn how to initialize variables in Java.

$$/$$

Initializing a variable in Java is done as follows:

<variable type> <variable name> = <value to be stored in the variable>;

For example:

 

int distance=0;

 

$$/$$

Till now you have learned the following:

  • What are variables and why do we need them?

  • Declaring variables in Java

  • Initializing variables in Java

Further on, you will learn how are the variables used in a program and some rules regarding naming variables.