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

What is Command Line in Java? Why it is Important

$$/$$

You now have everything that you need to run your first program on the command line. But before you do that, you will learn what the command line is and how to use it. The next video will help you with this. Specifically, you will learn the following in this video:

  • What is the command line?

  • How do you open it?

  • Why is the command line required to run a code written on a text editor?

  • Some basic commands used on the command line to navigate between directories and to open a file inside a directory.

Please note that you will be writing your codes on Notepad, which is the text editor on Windows. For Mac, Linux, etc. you can use the respective text editors. Please keep in mind that you cannot use MS Word as a text editor for writing codes.

$$/$$

Video Transcript

 

Well, Java programs can be written on any text editor such as Notepad. But do you really think that Notepad itself will understand Java commands and execute them? The answer is no. To run and execute Java programs written on a text editor, you need an application called the Command line. But why do you need this command line? Well, you need it because Notepad doesn't know where the Java compiler is on your computer. The Java compiler is not an icon that you click and it compiles a code to machine language. To be able to access the Java compiler, you need the Command line. It gives a command to your computer and your Notepad file can then access the compiler. The compiler then compiles it and you're sorted. However, before you start writing the code, you need to know what the command line is and where is it on your PC. You also need to know how to open it and how you can work with it. Let's learn all this. Remember, you just install JDK, which contains a few tools that are mandatory for a Java code to run the compiler and the Java runtime environment. Now, one of the ways in which the code written in text editor can access these tools is through the command line. The Command line is an application through which you can give commands or instructions to your computer for windows. To open the command line, you just need to search Command Prompts. In the Start menu you will see the Command prompt application here. When you click this, you will see a window with black background like this. This window can also tell you which version of JDK you installed. For this, type Java space and hit enter. You will see something like this. This shows that I have version eight on my PC. I have GRE and VM stands for virtual machine. In case you don't see anything like this, it means there is something wrong with your installation of JDK. Now you want to compile and run the code. In order to compile and run the code, you need to first go to the folder where the code is. So you need to tell your computer to go to the folder where the code resides. Once you're in that folder, you can tell the computer to run and compile the code. Let's see how you can do that. Let's say you're currently at C Users Videos and you want to navigate to Desktop. What you have to do is type CD Space Desktop and this will bring you to Desktop.

 

Now you can do anything you want. When you are in Desktop, you can create directories, list the contents and much more. Let's say you want to move two steps ahead. Let's say you want to go to Videos and inside Videos, you want to go to movies. You can do this in one single step. You type CD Space videos, backward slash movies. This brings you to movies inside Videos if you want to open a file in a directory, first navigate to that directory. For instance, if you have a JPEG file sun. JPEG inside User Images to open this file, you need to navigate to User Images folder and then type the file name like this it will open the file in the default program. Now to open a file, you need to navigate to the directory that contains it. For example, what if you are in user program files and you want to open a file sun. JPEG that is there on your desktop while you write sun. JPEG while in user program files, the computer will look for sun. JPEG in program files which is the current directory you are in. If it doesn't find it there, it won't open it. To open it without navigating to the desktop. What you can do is you can add desktop to your path. To know what a path is, type Path and this will appear on your screen. So this is a list that tells your computer to open a file that is not present on your current directory. It needs to look for it in these directories. So if you add desktop there after looking for sundown. JPEG in program files, it will look for it in these directories and open it. But how do you add desktop to your path? Go to Start, right click on my computer, go to Properties, go to Advanced System Settings, click on Environment Variables and there you will see the variable called Path. You can edit it like this, this and add your path to it. Now you can add desktop here like this. Now when you go back to the command line, you can open sun. JPEG without navigating to the desktop itself. 

 

Video Recap

 

  • Java programs can be written on any text editor like Notepad, but it doesn't understand Java commands and cannot execute them.

  • To run and execute Java programs, you need an application called the Command line because Notepad doesn't know where the Java compiler is on your computer.

  • The Java compiler is not an icon that you click and it compiles code to machine language; you need the Command line to access it.

  • Before writing code, you need to know what the Command line is and where to find it on your PC, as well as how to open it and work with it.

  • To access the Java compiler and Java runtime environment, you need to install JDK, which contains mandatory tools for Java code to run.

  • The Command line is an application through which you can give commands or instructions to your computer for windows.

  • To open the command line, search Command Prompts in the Start menu, and you will see a window with a black background that can tell you which version of JDK you installed.

  • To compile and run code, you need to navigate to the folder where the code is located and tell the computer to compile and run the code.

  • To navigate to a folder, type CD Space, followed by the folder name in the Command line, and to move two steps ahead, type CD Space, followed by the folder name with a backward slash.

  • To open a file, navigate to the directory that contains it and type the file name, and to open a file that's not present in the current directory, you can add the directory to your path variable in the Environment Variables settings.

 

So now you know how to use the command line. Here, a very important takeaway was the path variable. If you add a directory to the path variable, you don’t need to navigate to that directory to open any file inside it. Also, you learnt about the ‘cd’ command, which allows you to navigate between directories. Remember, all the commands we discussed in the video were for Windows.

 

For commands on Mac, you can refer to this link.

 

BE VERY CAREFUL WITH THIS. ONCE YOU ADD A DIRECTORY TO THE PATH VARIABLE, YOU NEED TO CLOSE AND RESTART COMMAND PROMPT TO SEE IT IN ACTION.

 

Let’s now move to writing a code on a text editor. You will need to use all your knowledge of the command line to execute this code.

$$/$$

You just ran your first code on the command line. One very important step here was adding the JDK to the path variable. This helps in using the Java compiler, which is contained by the JDK, without moving to the directory that contains the JDK.

 

All this needs to be done for Windows only and not for Mac.

 

These are the steps you need to follow to add the JDK to your path:

 

  1. Go to Advanced Settings in System Properties

Click on Advanced System Settings
$$/$$

2) Click on Environment Variables

Click on Environment Variables
$$/$$

3) Click on Edit after selecting the Path, or double click on Path.

Click on Edit
$$/$$

4) In the dialog box that appears, click on New.

Click on NEW
$$/$$

5) Finally, browse to C/Programs(x86)/Java/JDK/bin.

Browse
The required folder
$$/$$

6) Click OK on the current window and the previous window as well.

Click OK
One more time
$$/$$

7) Restart your command line, and you are done!

 

Now that you know the advantages of using an Integrated Development Environment (IDE), let’s download it. In the next segment, you will download an IDE called IntelliJ. You will also learn how to use it and how to write a code on it.