A program that is open source is a program (or software in general) that allows users to access its source code, not only the final binary code.
It's like having the recipee. There is a subset of open source programs that are "FOSS" Free Open Source Software
There are 2 main types of variables in Java.
Primitives and the rest. The rest are called "reference variables".
Primitives are this options:
byte: integer numbers. It has a minimum value of -128 and a maximum value of 127 (inclusive).
short: integer numbers . It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive).
int: integer numbers. By default, the int data type is a 32-bit signed two's complement integer, which has a minimum value of and a maximum value of . In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of .
long: integer numbers. The long data type is a 64-bit two's complement integer. The signed long has a minimum value of and a maximum value of . In Java SE 8 and later, you can use the long data type to represent an unsigned 64-bit long, which has a minimum value of 0 and a maximum value of . Use this data type when you need a range of values wider than those provided by int.
float: decimal values. As with the recommendations for byte and short, use a float (instead of double) if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency.
double: decimal values. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.
boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined.
char. Characters encoded with numbers. The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).
More info on data types here:
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
In IB CS you don't need to deep dive into de nuances of the specifics of these types. It's ok if you remember int, double, boolean and String
Something that is missing from the primitives in java are the Strings that for java they are actually an object.
We usually thing of a variable of something that just has a value. It has a name, a space in memory and inside it has the value that we can read/write.
And this is true for primitives. We can think of them as something like this:
But when we have reference types (such a String or any object) we have something like this. Let's supose that we have a String with the name of myString and the value "tomato"
The variable myString is actually a pointer to the address in memory where we have the value ("tomato")
If we have an object is easier to see. Let's have this object "Watch" with this easy implementation
If we have another class (the main) class and we execute this lines
we will have something like this:
If then we say this line:
Then we are not creating a new instance, we're just pointing to the already existing watch.
If we write something like this we're going to use the same instance for both variables.
This would output 22. And this would be the diagram of the memory contents.
For Java watch1 and watch3 are equal because they are the same instance.
If we change watch 2 to have the same brand and same color they (by default) still not be the same thing because they are not the same instance.
In this case watch1 and watch3 are the same thing but not with watch2.
To solve this nuance many objects implements the method equals(). The method equals is a method that is going to compare 1 object with another and if, by the context, are the same thing, it's going to return true.
If in this case we consider that the watch is the same if they have the same brand and color (depends on the scenario) the use of the method would be like this
Is common to see it in string methods to return true if they have the same content.
In the case of modeling people, in some context we can use that if 2 people have the same name they are the same. But usually go that if 2 people have the same ID number (DNI in Spain) they are the same person.
If a variable is not initialized or it has losed their reference, the value that they store by default is null
. This means that the reference doesn't go to anywhere
If we write
We will have something like this:
Here watch3 is not pointing anywhere because we said so (assigning the null vaue) and watch4 is not pointing anywhere because we didn't create a new instance or linked anything.
This is is useful to detect empty spaces in an array or a collection
https://www.educative.io/answers/what-is-the-scope-of-a-variable-in-java
//TO-DO
//TO-DO