Professional Documents
Culture Documents
CHAPTER 1
INTRODUCTION TO JAVA PROGRAMMING
many set-top box projects. The language, initially called ‘Oak’ after an oak tree that
stood outside Gosling's office, also went by the name ‘Green’ and ended up later
being renamed as Java, from a list of random words.
Sun released the first public implementation as Java 1.0 in 1995. It promised Write
software under the terms of the GNU General Public License (GPL).
On 8 May, 2007, Sun finished the process, making all of Java's core code free and
open-source, aside from a small portion of code to which Sun did not hold the
copyright.
© ISBAT UNIVERSITY – 2019. 11/20/2021
Simple − Java is designed to be easy to learn. If you understand the basic concept
of OOP Java, it would be easy to master.
Secure − With Java's secure feature it enables to develop virus-free, tamper-free
systems. Authentication techniques are based on public-key encryption.
Architecture-neutral − Java compiler generates an architecture-neutral object file
format, which makes the compiled code executable on many processors, with the
presence of Java runtime system.
Portable − Being architecture-neutral and having no implementation dependent
aspects of the specification makes Java portable. Compiler in Java is written in
ANSI C with a clean portability boundary, which is a POSIX subset.
An object in Java is any real-world things that have properties and actions. In other
words, an entity that has state and behavior is known as an object. Here, State
represents the properties and Behavior represents the actions or functionality.
3. Identity: Identity represents the unique name of an object. It differentiates one object from
the other. The unique name of an object is used to identify the object
You can do that very easily. Ask two questions: What it has? (Properties) and What it does?
(Actions)
In other words, a class can also be defined as “a class is a group of objects which
are common to all objects of one type”.
A class is the type of an object.
Now, suppose iPhone has some properties such as width=”5.86 cm”, height=”12.3 cms”,
OS=”iOS”, brand=”Apple”, price=”1200$” and actions are call(), sendMessage(), browse(),
share().
Both objects have some different properties and actions but the type is the same “Phone”.
This is the class. i.e the name of the class is “Phone”.
Example:
int myNum = 15;
System.out.println(myNum);
Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Bitwise operators
!= Not equal x != y
&& Logical and Returns true if both statements are x < 5 && x < 10
true
! Logical not Reverse the result, returns false if !(x < 5 && x <
the result is true 10)
ON / OFF
TRUE / FALSE
Example
int x = 10;
int y = 9;
System.out.println(x > y); // returns true, because 10 is higher than 9
while (condition) {
// code block to be executed
}
Example
int i = 0;
while (i < 5) {
System.out.println(i);
i++;
}
Statement 3 is executed (every time) after the code block has been executed.
Example
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
© ISBAT UNIVERSITY – 2019. 11/20/2021
Java Break
The break statement can also be used to jump out of a loop.
Example
for (int i = 0; i < 10; i++) {
if (i == 4) {
break;
}
System.out.println(i);
}
System.out.println(cars[0]);
// Outputs Volvo