Academic Tutorials



English | French | Portugese | German | Italian
Search Tutorial :

Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

Java Tutorial
Java Introduction
Object Oriented Programming Concepts
Anatomy of a Java Application
Syntax and Semantics of Java
Java Objects, Classes, and Interfaces
The String and StringBuffer Classes in Java
Setting Program Attributes in Java
Using System Resources in Java
Threads of Control in Java
Errors and Exceptions in Java
Java Input and Output Streams
Overview of Java Applet
Creating an Applet User Interface in Java
Communicating with Other Programs in Java
Overview of the Java UI
Using GUI Building Blocks in Java
Laying Out Components within a Container
Working with Graphics in Java
How Java Differs from C and C++
Java Summary

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


How Java Differs from C and C++


Previoushome Next





pointers

Java language passes all the arrays and objects by reference but will not have an explicit pointer type.

A D V E R T I S E M E N T
You cannot construct a reference to anonymous memory. In addition of making the programming easier, this prevents the common errors due to the pointer mismanagement.




structures and unions

The Java language do not support either structures or unions. Instead they use classes or interfaces to build the composite types.




The Command Line Arguments

Command line arguments passed to the Java application are different in number and in types than those passed to C or C++ programs.




Number of Parameters passed

In C and C++ when the program is invoked, the system passes two parameters to it: These arguments are shown below.

argc--the number of arguments passed on the command line
argv-- the pointer to an array of strings that contain these arguments

When we invoke a Java application, the system passes only one parameter to it:

args-- array of Strings (it is just an array and not a pointer to an array) which contain the arguments




First Command Line Argument

In C and C++ programming, the system passes the whole command line to the program as its arguments, including a name used to invoke it. Consider for example, if we invoked the C program like this: Then first argument in the argv parameter is diff.

diff file1 file2

In Java Programming, you always know the name of application because it is the name of class where the main method is been defined. So, the Java runtime system does not pass the class name we invoke to main method. Instead, the system passes only the those items on the command line which appears after the class name. Consider for example, if we invoked a Java application like this:

java diff file1 file2 The first command line argument is file1.




The Java Strings are First-Class Objects

By convention, the C and C++ strings are the null-terminated array of characters; there is no such real entity in C and C++ that is a string. The Java strings are first-class objects.




C Strings Behaves Unpredictably

To illustrate why this is one of the important feature of Java programming language, let us look at the small example. This C function will copy the contents of str1 into str2.

int myStrCopy(char *str1, char *str2)
{
for ( ; *str1 != '\0'; str1++, str2++)
*str2 = *str1;
}

In the above example, the developer uses the pointer arithmetic to step through both the strings copying one into the other. While allowing the programmers to inspect the arbitrary memory locations through pointers is the powerful tool, this power can be a source of many errors. One of the fruitful source of errors is pointers which stray off the end of the array. myStrCopy function above has such an error: the for loop in the function will not check the length of a string str2, and if the string str1 is longer compared to str2 the string copy writes right over the end of the string str2. Here is a program which tickles the bug.

main()
{
char *s = "HotJava is Cool!";
char t[] = "Java is Cool!";

printf("%s, %s\n", s, t);
myStrCopy(s, t);
printf("%s, %s\n", s, t);
}

The myStrCopy function writes over the end of string str2 thereby corrupting all that which was stored in the memory after it. NOTE: the %s, %s are the characters that happened to be stored in a memory location after the string str2 and will probably be different when we run the program on our machine.




The Java Strings are Predictable

Java strings are the first-class objects deriving either from a String class or a StringBuffer class. This makes the finding and fixing the whole class of common and frustrating programming errors such as the one illustrated the below trivial. Here is the program above (including an error) rewritten in the Java language.

class strcpy
{
public static void main(String args[])
{
String s = "HotJava is Cool!";
StringBuffer t = new StringBuffer("Java is Cool!");

System.out.println(s + ", " + t);
myStrCopy(s, t);
System.out.println(s + ", " + t);
}

static void myStrCopy(String str1, StringBuffer str2)
{
int i, len = str1.length();

for (i = 0; i < len; i++)
str2.setCharAt(i, str1.charAt(i));
}
}

Notice that this translation will do use the String class, the StringBuffer class and the methods which are appropriate to obtain a specific characters instead of the character arrays and the pointers.

Like the C version, Java programming versions of the myStrCopy method loops over the length of the str1 and never checks length of str2. Thus, when the string str1 is longer than the string str2, the method will try to obtain the characters beyond the end of the end of the str2. However, when we run the Java language version, we will see the following runtime error message.

Exception in thread "main" java.lang.StringIndexOutOfRangeException String index out of range: 13
at java.lang.Exception.< init >(Exception.java)
at java.lang.StringIndexOutOfRangeException.< init >(StringIndexOutOfRangeException.java)
at java.lang.StringBuffer.setCharAt(StringBuffer.java)
at strcpy.myStrCopy(strcpy.java:23)
at strcpy.main(strcpy.java:15)

The primary difference between the Java Programming language version of this program and the C, is that the Java program reliably and obviously will crash, where as the C program will do something obscure.



Be the first one to comment on this page.




  Java Tutorial eBooks
More Links » »
 
 Java Tutorial FAQs
More Links » »
 
 Java Tutorial Interview Questions
More Links » »
 
 Java Tutorial Articles
More Links » »
 
 Java Tutorial News
More Links » »
 
 Java Tutorial Jobs
More Links » »

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: java download, java games, javascript, sun java, download microsoft java virtual machine, sun java free download, java chat rooms, java update, yahoo java messenger, java certification

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright © 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World
Copyright © 2003-2010 Vyom Technosoft Pvt. Ltd., All Rights Reserved.