• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Can one not learn Java without knowing C? And C without machine & assembly languages?

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Good Evening!
Please refer to the title: Lesson:A Closer Look at the "Hello World!" Application (The Java™Tutorials > Getting Started)
Can one not learn Java without knowing the C Programming Language? Please look at this part:

The modifiers public and static can be written in either order(public static or static public), but the convention is to use public static as shown above. You can name the argument anything you want, but most programmers choose "args" or "argv".

The main method is similar to the main function in C and C++; it's the entry point for your application and will subsequently invoke all the other methods required by your program.

The main method accepts a single argument: an array of elements of type String.

public static void main(String[] args)

This array is the mechanism through which the runtime system passes information to your application. For example:

java MyApp arg1 arg2

Each string in the array is called a command-line argument. Command-line arguments let users affect the operation of the application without recompiling it. For example, a sorting program might allow the user to specify that the data be sorted in descending order with this command-line argument:

-descending

The "Hello World!" application ignores its command-line arguments, but you should be aware of the fact that such arguments do exist.


So in case of Does args mean "arg+s", i.e., argument string or a single argument of the form of an array of elements of type String? Or is it a single
argument "args": an array of elements of type string[]? Because it is said just earlier that

... most programmers choose "args" or "argv"...



When I learnt C, I was advised to follow this book: Schaum’s outline of theory and problems of programming with C, 2nd Ed., by Byron S. Gottfried Ph.D. It had an easy-to-follow pattern in the form of Questions-Answers.

Later on, I came across many books like The C Programming Language Book by Brian Kernighan and Dennis Ritchie, but this book remains my favourite!

So naturally my next question should be:
Is there a similar book in Java, following the same pattern, attempting to build our Java experience from the Grounds Up, without any dependence on C programming language, with numerous programming codes, examples and problems?

Now, I again draw your attention to the line:

java MyApp arg1 arg2
Each string in the array is called a command-line argument


The array of elements is supposed to be a,r,g,1,' ',a,r,g,2,'\0'. So are the strings supposed to be "arg1" and "arg2"?, because to me the array {a,r,g,1,' ',a,r,g,2,'\0'} appears to be a single string!

I find that learning programming in the way the college/university education system wants us to learn programming is essentially cultivating the hard way of keeping our distrust/disbelief suspended. Because while learning C I found that there are many things in C that can't be understood, but only memorised, keeping our disbelief/distrust suspended and continue with degree seeking education, unless one learns machine language, assembly language and Opt Codes! But they are taught chronologically later in computer courses!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rajib Ban wrote:So in case of Does args mean "arg+s", i.e., argument string or a single argument of the form of an array of elements of type String? Or is it a single
argument "args": an array of elements of type string[]?


"args" is just a variable name. It's presumably a shortened form of "arguments". It's a single variable, of the type String[] (array of String objects). The name isn't really important. In fact, you can name it whatever you like. Even would work.

The important part is that the method is named main and that it is public static void and that it takes one argument, which is a String[]. The name of the argument variable is not important.

You do not need to know C or C++ to learn Java. In fact, most likely most Java programmers have never programmed in C or C++. (I did, but I started programming years before Java was invented).

Just because the tutorial mentions C and C++ somewhere, it does not mean that you need to know those languages to learn Java.

Rajib Ban wrote:The array of elements is supposed to be a,r,g,1,' ',a,r,g,2,'\0'. So are the strings supposed to be "arg1" and "arg2"?, because to me the array {a,r,g,1,' ',a,r,g,2,'\0'} appears to be a single string!


I don't know where you got this a,r,g,1,' ',a,r,g,2,'\0' from but it has nothing to do with Java. Don't confuse whatever you learned about C or C++ with Java. Java is a different language, and not an extension of C++ - so it is not so that whatever exists in C++ also exists and works in the same way in Java. If you start your program with: java MyApp arg1 arg2 then the args variable of the main method will contain two String objects, with the values "arg1" and "arg2".

Rajib Ban wrote:I find that learning programming in the way the college/university education system wants us to learn programming is essentially cultivating the hard way of keeping our distrust/disbelief suspended. Because while learning C I found that there are many things in C that can't be understood, but only memorised, keeping our disbelief/distrust suspended and continue with degree seeking education, unless one learns machine language, assembly language and Opt Codes! But they are taught chronologically later in computer courses!


It would not work if you would have to start the other way around - if you would have to learn the very lowest level first, before learning the higher levels.

Note that there are even lower levels than machine language. Don't you feel that you first have to understand exactly how a CPU works before you can understand how machine language works? Don't you think you first have to understand transistors and electronic circuits to understand how a CPU works? Don't you think you have to understand particle physics and quantum mechanics first? Because in order to understand transistors, you have to understand how electrons behave in conductors and semi-conductors. Etc...
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:

Rajib Ban wrote:The array of elements is supposed to be a,r,g,1,' ',a,r,g,2,'\0'. So are the strings supposed to be "arg1" and "arg2"?, because to me the array {a,r,g,1,' ',a,r,g,2,'\0'} appears to be a single string!


I don't know where you got this a,r,g,1,' ',a,r,g,2,'\0' from but it has nothing to do with Java. Don't confuse whatever you learned about C or C++ with Java. Java is a different language, and not an extension of C++ - so it is not so that whatever exists in C++ also exists and works in the same way in Java. If you start your program with: java MyApp arg1 arg2 then the args variable of the main method will contain two String objects, with the values "arg1" and "arg2".



Well, this is *not* how C does it either. Okay, C does uses nul terminated character arrays as strings, but it is not one string; nor are the spaces passed in (unless it is quoted). With C, argv is an array of pointers to character arrays (which are char pointers), and there is also an argc parameter to return the number of parameters... so, with C, it is also separated strings.

Henry
 
Marshal
Posts: 80653
476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have often found learning C to be a hindrance to learning Java®, and of course you do not need to know any machine language nor assembler.
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, C is not needed to learn Java.
No, assembler is not needed to learn C.

Disclaimer: I started my career writing assembler and machine microcode. Then I later used higher-level languages (in order: FORTRAN, BLISS, C, C++, Java, JavaScript). But even though I learned assembler before all that, I don't think it's needed.

And while I do think that knowing Java is detrimental to learning JavaScript, I'm not sure I agree that C is detrimental to learning Java. But then, I was striving to write object-oriented C before I even knew what object orientation was, so I may be an outlier.
 
author & internet detective
Posts: 42135
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java can definitely be your first language! That one sentence about C is just a reference for one who does know C.

I learned Pascal and C++ before learning Java. I learned about assembly language after first learning Java. I developed an appreciation of low level concepts, but it wasn't essential.
 
Rajib Ban
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Dr.Jong, Dr.Wong, Dr. Richie, Dr. Bibeault, Dr.Boyarsky!
Coule I please be explained the line from http://docs.oracle.com/javase/tutorial/getStarted/application/index.html:

This array is the mechanism through which the runtime system passes information to your application. For example:

java MyApp arg1 arg2

Each string in the array is called a command-line argument.  

 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What don't you understand about that line?
 
Rajib Ban
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:What don't you understand about that line?

Please demarcate what exactly each string is, and which one is the array:

   For example:

   java MyApp arg1 arg2

   Each string in the array is called a command-line argument.


 
Bartender
Posts: 15741
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you run that command in your command line interface, it will execute "java", and pass it the command line arguments "MyApp", "arg1" and "arg2". The Java runtime then uses the "MyApp" command line argument to look for your application and initialize and start it. It looks for a class named MyApp, which contains a method

The remaining command line arguments are passed into the args parameter of the main method. So if you wrote the following program
it would print
.
 
Campbell Ritchie
Marshal
Posts: 80653
476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:. . . I'm not sure I agree that C is detrimental to learning Java. But then, I was striving to write object-oriented C before I even knew what object orientation was, so I may be an outlier.

I think it is one of those things which vary from person to person. Look at Winston's confessions about how difficult he found it to move from procedural to object languages. You were obviously different. I think the problem is that the similarity of the syntax misleads people into thinking there is a similarity in semantics and paradigm, which there isn't.

If there is a risk of confusion, it is probably better to avoid that risk.
 
Rajib Ban
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:When you run ...


No, Sir, what I was asking was with respect to that specific quote:
Please demarcate in this example:

       java MyApp arg1 arg2

       Each string in the array is called a command-line argument.

what exactly "Each String" is, and which one is "the array" ?
 
Rajib Ban
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote: ... If there is a risk of confusion, it is probably better to avoid that risk ...


Yes, Sir! That is why I said I needed a book that will deal with exclusively Java from the first principles without allusion to C programming language.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rajib Ban wrote:
No, Sir, what I was asking was with respect to that specific quote:
Please demarcate in this example:



Stephan broke down that command in exactly that way.
What bit of his explanation did you not understand?

I can't see how it can be explained in any simpler way, to be honest.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rajib Ban wrote:

Stephan van Hulst wrote:When you run ...


No, Sir, what I was asking was with respect to that specific quote: ...


Is there still something you don't understand about command line arguments? Stephan explained it very clearly. Don't get too hung up on words on one specific page.

Here is some more explanation about command line arguments: Command-Line Arguments
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rajib Ban wrote:
Yes, Sir! That is why I said I needed a book that will deal with exclusively Java from the first principles without allusion to C programming language.



The Oracle tutorials, which I think have been linked before, don't mention C, at least not that I remember.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Big fat NO . You dont need to learn C for knowing Java
 
Rajib Ban
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:The Oracle tutorials, which I think have been linked before, don't mention C, at least not that I remember.


Yes, it is! The answer is in the quote of my first post! Please search with the string:

main method is similar to the main function in C and C++

 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ha...I'm clearly being very perceptive today.


However, that is not important to the rest of the article.
It doesn't imply needing to know C or C++.  It's just information, possibly handy if you already know either of those languages.
 
Rajib Ban
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dr. Tolles and Dr. Jong,
I did not want the elaborate explanation of Dr.  Stephan van Hulst.

I wanted to be pointed out, exactly with respect to that specific quote, what exactly "Each string" is, and which one is "the array":

    in this example:

       java MyApp arg1 arg2

       Each string in the array is called a command-line argument.


snapshot001.jpeg
[Thumbnail for snapshot001.jpeg]
Exact pinpointed explanation/elaboration
 
Henry Wong
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Agreed that any programming language is not dependent on any other programming language -- or should not be. There may be some syntax in common that may make learning easier with certain languages. There may be some syntax differences that makes learning harder. And any programmer worth his/her salt should be able to learn any new language without transition through another new language first...

Henry
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rajib Ban wrote:I wanted to be pointed out, exactly with respect to that specific quote, what exactly "Each string" is, and which one is "the array":


"The array" is the String[] array that is passed to the main method.

"Each string" refers to the elements of this array.
 
Jeanne Boyarsky
author & internet detective
Posts: 42135
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The original poster is having trouble posting in this thread and asked me to post:

This thread may please be closed, as further discussions are in my next post: I found a solution to my earlier thread mentioned herein
Thanks for helping.
Regards!

 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote: I think the problem is that the similarity of the syntax misleads people into thinking there is a similarity in semantics and paradigm, which there isn't.


Yeah, that's exactly the problem when going from Java to JavaScript.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic