Java What To Expect
Java What To Expect
cpp
This is a more comprehensive breakdown of how the languages differ, Java is
strikingly similar to cpp and much of what work with java will work in cpp.
In terms of studying you will be utilizing a similar book in order to learn the
language quickly. Then you will also be using the activities of the same cpp
150 course for this one. Be aware of that.
Declarations Abound
Much like cpp, java is a statically bound language. Meaning that every
special symbol must be declared and properly used or it will cause errors.
The compiler will keep track of this and will not allow you to deviate what
made that special symbol in the first place. An important point here is that
these errors will be caught at compile time, and they will always be
caught.
int sum = 0;
sum += a[i];
return sum;
}
Files and Directories
File Names
File names of java are very specific much like when dealing with a multifile systems with
user defined header files. Remember this is all in classes meaning that all of your file
names have more purpose then just syntax.
Say you create Java class file, AdditionUtilities, where can we put
it?
This is the same for cpp. However the application is a bit more restrictive for
java unlike cpp.
In Java a public class (that is not nested within another class) must be
stored in a .java file with a name exactly matching the name of the
class.
This being the case with the idea that the class has the function stored
with in it and the file itself .java is the class.
So, if you want to use a function it must be used within class as a
method. Essentially java doesn’t have functions it only has methods
That also means because the main function is a method it only has
member variables as well
4.2 Directories
But wait, there’s more!
To avoid the possibility that someone else might have used the name
“addEvenNumbers” in their own code, particularly in a library that we might
someday combine into our own project, classes are often “packaged up”.
You are certainly familiar with the name space std, if only as a source of
annoyance because you need to take extra steps to use symbols from within
the C++ standard library.
But, the truth is, most C++ programmers don’t make nearly as much use of
namespaces as the probably should.
Packages is our cpp equalavent to headers files; however, they are also
tied with namespaces.
This is #include and #import to be clear is the header file comparison.