Basic Concepts: I. Introduction To Java Microsystems, and Currently Owned by Oracle
Basic Concepts: I. Introduction To Java Microsystems, and Currently Owned by Oracle
Basic Concepts
I. Introduction to Java
• Java is a high level, modern programming language designed in the early 1990s by Sun
Microsystems, and currently owned by Oracle.
• Java is platform-independent, which means that you only need to write the program once to
be able to run it on a number of different platforms.
• Java is portable, robust, and dynamic, with the ability to fit the needs of virtually any type of
application.
• Java is used to develop applications for Google’s Android OS, various desktop applications,
(such as media players and antivirus programs), web applications (such as interactive content),
enterprise applications (i.e., banking), and many more.
B. Multi-Line Comments
• Java also supports comments that span multiple lines. For example:
/* This is also a
comment spanning
multiple lines */
• Note that Java does not support nested multi-line comments. However, you can nest single-
line comments within multi-line comments.
/* This is a single-line comment:
// a single-line comment
present
*/
C. Documentation Comments
• Documentation comments are special comments that have the appearance of multi-line
comments, with the difference being that they generate external documentation of your
source code.
/** This is a documentation comment */
III. Variables
• Variables store data for processing
• A variable is given a name (or identifier), such as area, age, height, and etc. The name uniquely
identifies each variable, assigning a value to the variable and retrieving the value stored.
• There are many data types for variables, some examples are:
o int – used to declare an integer (whole numbers) such as 112 and -763.
o double – for floating-point or real numbers with optional decimal points and fractional
parts in fixed or scientific notations, such as 3.1415 and -55.61.
o String – for sequence of characters such as “Hello” or “Good Morning!”. Text strings are
enclosed within straight double quotes ("").
• char – for variables that hold a single alphanumeric character, such as a, Z, or 1.
• boolean – only accepts two (2) possible values: true and false.
Examples of variable declarations:
class MyClass {
public static void main(String[ ] args) {
String name = "Archie";
int age = 18;
double score = 9.9;
char group = 'S';
boolean online = true;
}
}
• Modulo – The modulo (or remainder) math operation performs an integer (whole number)
division of one value by another, and returns the remainder of that division. The operator
for the modulo operation is the percentage (%) character.
int value = 39;
int res = value % 8; // res is 7
C. Assignment Operators
• The assignment operator (=), which assigns a value to a variable.
int value = 5;
• This assigned the value 5 to a variable called value of type int.
• Java provides a number of assignment operators to make it easier to write code.
• Addition and assignment (+=):
int num1 = 4;
int num2 = 8;
num2 += num1; // num2 = num2 + num1;
VI. Strings
A. String
• A String is an object that represents a sequence of characters. For example, “Hello” is a
string of five (5) characters.
String s = "MyMaster";
B. String Concatenation
• The + (plus sign) operator between string values adds them together to make a new
string. This process is called concatenation.
• The resulting string is the first string, put together with the second string.
String firstName, lastName;
firstName = "Aries”;
lastName = "Davis";
class MyClass {
public static void main(String[ ] args) {
Scanner myVar = new Scanner(System.in);
System.out.println(myVar.nextLine());
}
}
Reference:
Deitel, H., & Deitel, P. (2014). Java: How to program-early objects (10th ed.). Prentice Hall.
SoloLearn.com – Java Programming. Retrieved on March 07, 2018 at https://www.sololearn.com/Play/Java#