Chapter 3. Moving from C to Java


If you are a C programmer moving to Java, there is good news. Java is a C-based language, so much of the basic syntax is the same ”you still put semicolons at the end of statements, array indices still start at 0, and so on. Every Java program will have a main() method that serves as the starting point of the program just as in C. Some of the built-in library functions share the same names in Java and C.

While Java and C share a number of similarities, there are new concepts to learn when moving to Java. The primary shift from C to Java is that you will have to learn how to think in an object-oriented sense. A C program is a collection of functions. A Java program is a collection of classes. A class is a block of code that provides the definition, or blueprint, for an object. Your Java programs will spend a lot of their time creating and manipulating objects.

You will also find that Java is more powerful and versatile than C. You can define how your methods and data can be accessed by outside users. You can create different types of methods and variables by applying modifying keywords to them. You can build sophisticated class hierarchies where classes share and build upon the capabilities of other classes. You can take advantage of the built-in exception handling capability of Java.

This chapter will help you on your way in moving from C to Java. It will provide a top-level look at some of the important similarities and differences between Java and C. This chapter is not meant to be a comprehensive tutorial for either C or Java. For a detailed review of the core elements of the Java language, see Chapters 6 “16 of this book.

In this chapter we will discuss ”

  • Program structure

  • Basic syntax

  • Java classes versus C structs

  • Variables

  • Pointers

  • Functions and methods

  • Arrays

  • Dynamic memory allocation

  • Exception handling

  • C libraries and Java APIs

  • Strings

  • Built-in math functions

  • Basic printing

  • Input/Output capability

  • GUIs and web-based applications



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net