To run a Java program using the command line

Source: Internet
Author: User

I now have a lot of people around to learn Java, as long as a mention of learning the Java language, we immediately think of the tool is Eclipse,myeclipse,netbeans and so on.

Perhaps we are used to the VC, the integrated development environment has too many dependencies. However, I personally feel that it is necessary for a developer to be familiar with a variety of development tools, but also to try the most primitive development tools, that is, the command line.

At the same time, I also found that the command line more to the Java syntax has a deeper understanding, rather than just stay on the memory level of memorization.

Let's first introduce the commonly used commands;

①CD Command---switch directories; e.g. CD SRC

②javac command---Compile Java source program e.g. Javac Person.java

③java Command---Run Java program e.g. Java person

Let's use the example below to illustrate:

0) First set up the SRC folder on the D disk, which is used to store the Java source files and Java compiled. class files;

1) Set up text documents, rename them to Person.java and Teacher.java respectively, and edit them with Notepad open;

2) The editing work is finished, we can compile them;

3) If the compilation is successful, the next step is to run the program;

4) If the compilation fails, the system will error, we compare the two methods of error results; e.g. we comment on the super (Name,gender) statement in the teacher constructor.

The code is as follows:

1  Public classPerson {2 String name;3     Chargender; 4     5Person (String name,Chargender) {6          This. name=name;7          This. gender=gender;8     }9     voiddisplay () {TenSystem.out.println ("My name is" +name+ One". \nmy gender is" +gender+ "."); A     } -}
1  Public classTeacherextendsperson{2 String title;3     intsalary;4     5Teacher (String name,Chargender,string title,intsalary) {6         Super(Name,gender);7          This. title=title;8          This. salary=salary;9     }Ten     voiddisplay () { One         Super. Display (); ASystem.out.println ("My title is" +title+ -". \nmy salary is" +salary+ "rmb/month."); -     } the      -      Public Static voidmain (String [] args) { -Teacher T =NewTeacher ("Yang Yuan", ' m ', "Professor", 7000); - T.display (); +     } -}

As follows:

Note: 1) More Java command Reference other materials, blog Park website has a lot of writing this blog, look very helpful.

2) Here is just an example, after all, the command line running Java program is very interesting, we have to learn in the comparison.

For programmers, it's always good to have access to more development tools.

To run a Java program using the command line

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.