Java overview
Java overview
About JAVA
Writing in the Java programming language is the primary way to produce code that will be
deployed
as Java bytecode, though there are compilers available for other languages such as
JavaScript,
Python and Ruby, and a native Java scripting language called Groovy. Java syntax
borrows heavily
from C and C++ but it eliminates certain low-level constructs such as pointers and
has a very simple
memory model where every object is allocated on the heap and all variables of object types are
references. Memnory management is handled through integrated automatic garbage collection
performed by the Java Virtual Machine (JVM).""
OOP is a particular style of programming which involves a particular way of designing solutions to
particular problems. Most modern programming languages, including Java, support this paradigm.
When speaking about O0P one has to mention:
Inheritance
Modularity
Polymorphism
Encapsulation (binding code and its data)
However at this point it is too early to try to fully understand these concepts.
This guide is divided into two major sections, the first section is an introduction to the language and
llustrates various examples of code while the second part goes into more detail.
Variables and Data Types
Variables
Avariable is a place where the program stores data temporarily. As the name implies the value
stored in such a location can be changed while a program is executing (compare with constant).
class Example2 {
public static void main (String args 0) {
Predicted Output:
The above program uses two variables, var1 and var2. var1 is assigned a value directly while var2 is
filled up with the result of dividing var1 by 2, I.e. var2 = var1/2. The words int refer to a particular
data type, i.e. integer (whole numbers).
Hints:
Predicted Output:
x and y: 10 20
x is 40
If we had to remove the comment marks from the line, y=100; we would get an error during
compilation as y is not known since it only exists within the block of code following the 'if
statement.
The next program shows that y is initialized each time the code belonging to the looping sequence is
executed; therefore y is reset to -1 each time and then set to 100. This operation is repeated for
three (3) times.