Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between Java, VisualBasic & C

 
Devaraj Rajakumar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I�m new to programming and as well to this forum. Can some one please tell me the difference between Java, VisualBasic & �C�(other than java is object-oriented)?

Thank you
Devaraj
 
Sidd Kulk
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most important difference is quoted by you. As far as other differences are concerned:
1. Java doesn't need a special editor to write code, unlike C and visual basic. java can be written in any text editor.
2.Java is platform independent. Unlike C, java needs to be compiled only once, and then it can run on any machine having a JVM. So it follows the compile once, run anywhere model.
3. java provides more functionalities and API than C(duh!!). But it might be a bit slower than C. java also provides exception handling and all.
4. Many other high level differences, which i am sure will be quoted by others...


Njoy!!
Sid
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15203
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"1. Java doesn't need a special editor to write code, unlike C and visual basic. java can be written in any text editor."

That's not true. C and Visual Basic source code is also just plain text which you can edit with any text editor.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java missed out some of the complications found in C and C++; you can find a full list on the Java website; try this White Paper. As far as I remember they missed out
  • Pointers
  • Overloaded operators (except "+" with Strings)
  • Function prototypes
  • Full compilation (Java bytecode is interpreted in most cases)
  • Generics
  • Assertions
  • Unsigned numbers
  • and there are lots more in the White Paper, section 2.2
  • In later versions generics and assertions were re-introduced.

    One new peculiarity of Java is the absence of any methods to alter a String. This means that String objects can be shared; if one declares the String "Campbell" twice in an application the JVM will use two references to the same object. I don't know whether that applies to any other languages.
     
    Campbell Ritchie
    Sheriff
    Posts: 48363
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    More about Sidd Cool's no 2.
    Java is not a language, but a platform. It consists of the language called Java, a compiler, and a Java virtual machine (and lots more components), and something like 3800 ready-made classes in the API and lots of other classes available elsewhere (eg Jakarta Commons, although they are not strictly part of the core of Java). Since there are different virtual machines and run-time environments available for different computers (eg Windows, Linux, Max, Intel chips [use i386], SPARC chips), the same Java language code will run on different computers with only the tiniest changes to the code.

    Platform-independence and lack of pointers makes Java unsuitable for writing operating systems, something done much better in C and C++.
     
    Campbell Ritchie
    Sheriff
    Posts: 48363
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    More that I have remembered.

  • Default values. Each field in Java has a default value which is usually changed in the constructor; C has un-initialised variables "indeterminate."
  • Lack of default values in local variables. But the compiler won't allow you to use an uninitialised local variable.
  • If you look in the White Paper I quoted you see support for "goto" is removed.
  •  
    Anand Hariharan
    Rancher
    Posts: 272
    C++ Debian VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Campbell Ritchie:

    Java is not a language, but a platform. It consists of the language called Java, a compiler, and a Java virtual machine ...

    ... Since there are different virtual machines and run-time environments available for different computers (eg Windows, Linux, Max, Intel chips [use i386], SPARC chips), the same Java language code will run on different computers with only the tiniest changes to the code.


    Could you please elaborate? When would changes to code be necessary when "porting" (*) it to different host-platforms?

    - Anand

    (*): One might have said "executing" or "running", but in context of your statement, it seems that maybe I should use "porting".
     
    David McCombs
    Ranch Hand
    Posts: 212
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    .Java is platform independent. Unlike C, java needs to be compiled only once, and then it can run on any machine having a JVM. So it follows the compile once, run anywhere model.


    C is not only platform independent but runs on far more platforms then Java.
     
    Jesper de Jong
    Java Cowboy
    Saloon Keeper
    Posts: 15203
    36
    Android IntelliJ IDE Java Scala Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by David McCombs:
    C is not only platform independent but runs on far more platforms then Java.

    But ofcourse you do not have "compile once, run anywhere" when you're programming in C. To make a C program work on any platform, you need a C compiler for that specific platform to compile your source code to native machine code for that platform.

    With Java, you just need to compile your source code once - and you can run it on any platform for which there is a JVM.

    Also, C programs usually tend to be not as easily portable as you think. The language itself might be standard, but programs in C almost always use platform-specific libraries and APIs which will make porting the program to different platforms very difficult. There isn't a standard GUI API for C, for example, like we have AWT and Swing in Java.
    [ April 17, 2007: Message edited by: Jesper Young ]
     
    David McCombs
    Ranch Hand
    Posts: 212
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    That is true about C, but remember a java program doesn't always run on any JVM
     
    Campbell Ritchie
    Sheriff
    Posts: 48363
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The differences between Java programming on different platforms are few. There are about four I can actually remember:-
  • You use different line-ends; using the %n formatting combination available in J5 and J6 will automatically choose the correct characters
  • Most platforms use ctrl-D (with or without \n) for end-of-file; Windows and DOS use ctrl-Z
  • Windows uses \ as a file separator, other platforms use /. There is a field called something like fileSeparator in the java.io.File class which will find it automatically
  • Windows uses ; as a path separator and other platforms use :. Again you can find a path separator somewhere (not sure, maybe in java.lang.System.getProperty("separator")??) to sort it out.
  • And any platform-sensitive calls (eg to .exe files in Windows, when Linux doesn't use the .exe extension) will need to be changed by platform.
     
    fred rosenberger
    lowercase baba
    Bartender
    Posts: 12083
    29
    Chrome Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by David McCombs:
    That is true about C, but remember a java program doesn't always run on any JVM


    NO C program will run on more than one platform without being recompiled. You need a different distribution package for every platform you support (i believe) without exception.

    "Platform independant" is an overloaded term.
     
    Anand Hariharan
    Rancher
    Posts: 272
    C++ Debian VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Campbell Ritchie:
    The differences between Java programming on different platforms are few. There are about four I can actually remember:-
  • You use different line-ends; using the %n formatting combination available in J5 and J6 will automatically choose the correct characters
  • Most platforms use ctrl-D (with or without \n) for end-of-file; Windows and DOS use ctrl-Z
  • Windows uses \ as a file separator, other platforms use /. There is a field called something like fileSeparator in the java.io.File class which will find it automatically
  • Windows uses ; as a path separator and other platforms use :. Again you can find a path separator somewhere (not sure, maybe in java.lang.System.getProperty("separator")??) to sort it out.
  • And any platform-sensitive calls (eg to .exe files in Windows, when Linux doesn't use the .exe extension) will need to be changed by platform.

    IIUC, to paraphrase you, there are two instances where special attention is to be given to Java code that will be running on different platforms:

  • I/O handling - specifically EOF and EOL
  • Platform specific calls


  • Let us say that I am running my code on a Windows JVM, but trying to open a text file created in UNIX (with its EOL and EOF preserved). Should I expect a problem?

    - Anand
     
    Campbell Ritchie
    Sheriff
    Posts: 48363
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You shouldn't have a problem with text files cross-platform. It is not usual to search for EOF in Java (it would be in C using the feof() function).
    There are actually a selection of end of line characters: the JFlex manual gives: \r|\n|\r\n|\u2028|\u2029|\u000B|\u000C|\u0085. You will find that the classes Java uses to scan text files (BufferedReader and fileReader or java.util.Scanner) recognise all the common combinations.
    To recognise end of file use this sort of code:but leave out "&& line.length() > 0" if there are any zero-length lines in the file. The problem is inserting line ends. As I said the %n formatting combination will sort the problem out automatically.
     
    Devaraj Rajakumar
    Greenhorn
    Posts: 6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,
    I would like to thank everyone who really helped me clear my doubt.

    regards
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic