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
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 AnalyticsMS 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 Administration | STEMMS 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 Master of Business Administration-90 ECTSMSc International Business ManagementMS Data Science 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 MediaMSc Sustainable Tourism and Event ManagementMSc in Circular Economy and Sustainable InnovationMSc in Impact Finance and Fintech ManagementMS Computer ScienceMS in Applied StatisticsMaster 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 ManagementMSc Digital MarketingMBA Business and MarketingMaster of Business AdministrationMSc in Sustainable Global Supply Chain ManagementMSc 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 AdministrationMaster of Business AdministrationMSc in International FinanceMSc in International Management and Global LeadershipMaster of Business AdministrationBachelor of BusinessMaster of Business Administration 60 ECTSMaster of Business Administration 90 ECTSMaster of Business Administration 90 ECTSBachelor of Business AnalyticsBachelor of Information TechnologyMaster of Business AdministrationMBA Business AnalyticsMSc in Marketing Analytics and Data IntelligenceMS Biotechnology Management and EntrepreneurshipMSc in Luxury and Fashion ManagementMaster of Business Administration (90 ECTS)Bachelor of Business Administration (180 ECTS)B.Sc. Computer Science (180 ECTS) MSc in International Corporate Finance MSc in Sustainable Luxury and Creative IndustriesMSc Digital MarketingMSc Global Supply Chain Management (PGMP)MSc Marketing (PGMP)MSc Corporate Finance (PGMP)MSc Data Analytics for Business (PGMP)MS Business AnalyticsMaster of Business AdministrationMS Quantitative FinanceMS Fintech Management
For College Students

Errors and Debugging in Java

$$/$$

Let us now talk about the kinds of errors you can make while writing code.

$$/$$

Video Transcript

 

Let us now try to see the two different kinds of errors which might creep into your programs. One such error is known as the compile time error. So compile time errors are those errors which hinder the compilation of your file. This actually means that the file itself would not compile if you have any compile time errors. So the basic process of running a file is basically the file first compiles and then it runs. So if the file fails to compile in the first step itself, it is an example of a compile time error. As an example, consider that I have declared a marks error like this, which consists of marks of three students. Now here, if I try to write a print statement like this and perhaps if I forget to add a semicolon, then you would see there is a curly red line which appears and which indicates that there is an error. Here it shows that a semicolon is expected. Suppose I don't correct this mistake and I try to run this file. 

 

Then you can see that there is an error which is getting thrown here. It shows that error occurred while compiling this particular file. So this basically is an example of a compile time error which occurs even before the file can be compiled because of some syntax error or other issues. So this is an example of a compile time error. Other examples of compile time error might be that if there is an extra bracket here, then also the file wouldn't compile because the syntax is not correct. So usually all the examples of syntax errors come under the category of compile time errors. Another type of error which might occur is known as the runtime error. So basically, runtime errors do not show up when the file is compiled, but they show up when the file is actually run and executed. So it is not possible to find runtime errors before even beginning to run the file. So basically, runtime errors are much harder to figure out as compared to compile time errors. As an example here, consider that I have a marks array which consists of three elements. But here I am trying to print the element at index number four. Clearly there is no index four which exists inside this array. So this is an invalid statement. But you will see that there is no red curly line which is appearing here, which basically means that the IDE is not able to figure out that this is an invalid statement. So when you run this file, you would see that there is an array out of bounds exception which is thrown. So this exception or this error is actually indicated when the file is run. So this example is of a runtime error. This is an invalid statement because here I am trying to access an element which does not even exist inside the array. However, there is no SYNT tax problem in this statement. And thus it does not show up during the compile time. But an error is thrown only after the file is run and executed. 

 

Video Recap

 

  • There are two types of errors that can occur in programs: compile-time errors and runtime errors.

  • Compile-time errors hinder the compilation of a file, meaning that the file itself will not compile if there are any compile-time errors.

  • Syntax errors, such as missing semicolons or extra brackets, fall under the category of compile-time errors.

  • Runtime errors occur when a file is executed and are much harder to figure out than compile-time errors.

  • Invalid statements that don't have syntax problems can lead to runtime errors, such as trying to access an element that does not exist inside an array.

  • Runtime errors are only indicated when the file is run and executed.

A run-time error will only occur when the code is actually running. These errors are the most difficult as they lead to unexpected program crashes and bugs in your code, both of which can be hard to track down and fix.

 

However, syntax errors are compile-time errors. Compile-time errors occur when codes are written in ways in which the Java compiler does not recognise. The compiler will display errors to alert you about something that will not compile and, therefore, cannot be run.

 

You can refer to this link to read more about these errors.

 

Let us try to understand how we can fix these errors or “debug” the code.

$$/$$

You now know how to debug a code.

 

You can see the step-by-step execution of the code by running it in debug mode; you can also see where you made a logical error or an error of another kind, which is preventing you from getting the desired output. In fact, a bug is a particular case of a run-time error.