Command-Line Arguments (C vs Java)


/* command line arguments in C */
void main(int argc, char** argv)
{
    char name[128]; 
    int age = 0; 
    if (argc >= 2) { 
        strcpy(name, argv[1]); 
        age = atoi(argv[2]); 
        printf("%s, name = %s, age = %d\n", argv[0], name, age); 
    } 
}

~>person.exe Park 20

argv[0] = “person.exe”

argv[1] = “Park”

argv[2] = “20”

 


// command line arguments in Java
public class Person {
    public static void main(String[] args) {
        String name = ""; 
        int age = 0; 
        if (args.length >= 2) { 
            name = args[0]; 
            age = Integer.parseInt(args[1]); 
            System.out.printf("name = %s, age = %d\n", name, age); 
        } 
    }
}

~>java Person Park 30

args[0] = “Park”

args[1] = “30”

 

Java Tutorial

Oracle Java Tutorial
http://docs.oracle.com/javase/tutorial/tutorialLearningPaths.html

Dotnetperls Java Tutorial
http://www.dotnetperls.com/java

Java2s Java Tutorial
http://www.java2s.com/Tutorial/Java/CatalogJava.htm

생활코딩 동영상 Java Tutorial
https://opentutorials.org/module/516/4551
https://opentutorials.org/course/1223

Tutorialspoint Java Tutorial
https://www.tutorialspoint.com/java/

JavaTPoint Java Tutorial
https://www.javatpoint.com/java-tutorial

Java Tutorial: Learn Java Programming with examples
https://beginnersbook.com/java-tutorial-for-beginners-with-examples/