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 ManagementMS Computer Science with AIML ConcentrationMBA 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 Management
For College Students

Understanding Java Functions

$$/$$

You must have used the word ‘function’ a number of times. In general usage, it means to operate in a particular way. For example, the function of a pencil is to write. This function is specific and clearly defined.

Let’s learn what functions broadly represent.

$$/$$

Video Transcript

 

Hi. We covered conditional statements and loops in the previous lectures. You also wrote the code and saw how lengthy it became at several stages. If you are required to use the same loops again and again in the program, should you write the entire thing again? In this session, you will learn how to use functions to make your code more efficient. Let's take the example of a company with different departments. There is a head and there are multiple teams. You have production, you have sales, you have service, et cetera. Once production is done, the head of the department calls the sales head and tells him to begin sales. Each time a product is made, the sales team is called in to sell it. The function of the sales team is to sell the product. You aren't concerned about how they will go about selling the product. They have their own internal rules and standards that people outside the sales team are not concerned about. Similarly, in computer science, there are pieces of code called functions. 

 

You aren't always interested in knowing how they go about getting you the required results. You simply use the anytime and anywhere you wish to get the desired results. Now, let's look at this in detail. But first think about how a function should be. It should have some name, as the term function suggests it should do something. It should be called that is, it should show up only when you want it and where you want it to. 

 

Video Recap

 

  • Functions in programming can make code more efficient.

  • Functions are like pieces of code that can be reused multiple times in a program.

  • The example given is a company with different departments and teams that have their own functions to perform.

  • A function should have a name, perform a specific task, and be called only when needed.

  • Using functions in programming can make code easier to read and maintain.

 

So, a function basically has a defined name and needs to be called when an action is required.  Now, let’s look at functions in Java. 

 

Note: You can download the following Java files to practise the codes while watching the video. Right-click on the Java files and open them with IntelliJ. Please be careful with the name of each file. The name should be exactly the same as the class name inside it, for the code to run. So make the changes accordingly.

$$/$$

You saw how functions are defined in Java. Defining a function is important as it determines what the function will be able to do. When you use ‘void’ in the function definition, you cannot use the function to return a value.

 

 

When you wish to return a value, you define its data type in the function definition.

 

 

Let’s now look at some of the important considerations you need to take into account when creating functions that return values. 

 

Note: You can download the following Java files to practise the codes while watching the video below:

$$/$$

Till now, the functions that you saw could print a statement or return a value that could be used in some other operation. But these functions were not interacting with the code. You will want your function to take values from the code itself: e.g. a user input. In the next lecture, you will learn how to modify your function definition to make it interact with the code.