wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes difference between Java, VisualBasic & C Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "difference between Java, VisualBasic & C" Watch "difference between Java, VisualBasic & C" New topic
Author

difference between Java, VisualBasic & C

Devaraj Rajakumar
Greenhorn

Joined: Apr 16, 2007
Posts: 6
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

Joined: Feb 20, 2007
Posts: 152
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

Joined: Aug 16, 2005
Posts: 14274
    
  21

"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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
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

    Joined: Oct 13, 2005
    Posts: 39436
        
      28
    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

    Joined: Oct 13, 2005
    Posts: 39436
        
      28
    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

    Joined: Aug 22, 2006
    Posts: 257

    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".


    "Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
    David McCombs
    Ranch Hand

    Joined: Oct 17, 2006
    Posts: 212
    .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.


    "Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
    Jesper de Jong
    Java Cowboy
    Saloon Keeper

    Joined: Aug 16, 2005
    Posts: 14274
        
      21

    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

    Joined: Oct 17, 2006
    Posts: 212
    That is true about C, but remember a java program doesn't always run on any JVM
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 39436
        
      28
    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

    Joined: Oct 02, 2003
    Posts: 11422
        
      16

    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.


    There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
    Anand Hariharan
    Rancher

    Joined: Aug 22, 2006
    Posts: 257

    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

    Joined: Oct 13, 2005
    Posts: 39436
        
      28
    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

    Joined: Apr 16, 2007
    Posts: 6
    Hi,
    I would like to thank everyone who really helped me clear my doubt.

    regards
     
    wood burning stoves
     
    subject: difference between Java, VisualBasic & C