2. Java Programming Language
• Java is one of the most popular and widely used programming language.
• Java has been one of the most popular programming language for many years.
• Java is Object Oriented. However it is not considered as pure object oriented as it provides support for primitive data types (like
int, char, etc)
• The Java codes are first compiled into byte code (machine independent code). Then the byte code is run on Java Virtual Machine
(JVM) regardless of the underlying architecture.
• Java syntax is similar to C/C++. But Java does not provide low level programming functionalities like pointers. Also, Java codes
are always written in the form of classes and objects.
• Java is used in all kind of applications like Mobile Applications (Android is Java based), desktop applications, web applications,
client server applications, enterprise applications and many more.
• When compared with C++, Java codes are generally more maintainable because Java does not allow many things which may lead
bad/inefficient programming if used incorrectly. For example, non-primitives are always references in Java. So we cannot pass
large objects (like we can do in C++) to functions, we always pass references in Java. One more example, since there are no
pointers, bad memory access is also not possible.
• When compared with Python, Java kind of fits between C++ and Python. The programs written in Java typically run faster than
corresponding Python programs and slower than C++. Like C++, Java does static type checking, but Python does not.
3. About Java
• Java is a simple language: Java is easy to learn and its syntax is clear and concise. It is based on C++ (so it is easier for
programmers who know C++). Java has removed many confusing and rarely-used features e.g. explicit pointers, operator
overloading, etc. Java also takes care of memory management and it also provides an automatic garbage collector. This
collects the unused objects automatically.
• Java is a platform-independent language: The programs written in Java language, after compilation, are converted into
an intermediate level language called the bytecode which is a part of the Java platform irrespective of the machine on
which the programs run. This makes java highly portable as its bytecodes can be run on any machine by an interpreter
called the Java Virtual Machine(JVM) and thus java provides ‘reusability of code’.
• Java is an object-oriented programming language: OOP makes the complete program simpler by dividing it into a
number of objects. The objects can be used as a bridge to have data flow from one function to another. We can easily
modify data and function’s as per the requirements of the program.
• Java is a robust language: Java programs must be reliable because they are used in both consumer and mission-critical
applications, ranging from Blu-ray players to navigation systems.
• Java is a multithreaded language: Java can perform many tasks at once by defining multiple threads. For example, a
program that manages a Graphical User Interface (GUI) while waiting for input from a network connection uses another
thread to perform and wait’s instead of using the default GUI thread for both tasks. This keeps the GUI responsive.
• Java programs can create applets: Applets are programs that run in web browsers. But applets support was deprecated
in Java 9 release and has been removed in Java 11 release due to warning browser support for the Java plugin.
• Java does not require any preprocessor: It does not require inclusion of header files for creating a Java application.
• Therefore, Java is a very successful language and it is gaining popularity day by day.
5. Loops in Java
• Java provides three ways for executing the loops. While all the ways provide similar
basic functionality, they differ in their syntax and condition checking time.
while loop: A while loop is a control flow statement that allows code to be executed
repeatedly based on a given Boolean condition. The while loop can be thought of as a
repeating if statement.
for loop: for loop provides a concise way of writing the loop structure. Unlike a while
loop, a for statement consumes the initialization, condition and increment/decrement in
one line thereby providing a shorter, easy to debug structure of looping.
do while: do while loop is similar to while loop with only difference that it checks for
condition after executing the statements, and therefore is an example of Exit Control
Loop.
Infinite loop: One of the most common mistakes while implementing any sort of looping
is that that it may not ever exit, that is the loop runs for infinite time. This happens when
the condition fails for some reason
6. Classes and Objects in Java
A class is a user defined blueprint or prototype from which objects are created. It
represents the set of properties or methods that are common to all objects of one type.
In general, class declarations can include these components, in order:
Modifiers : A class can be public or has default access .
class keyword: class keyword is used to create a class.
Class name: The name should begin with a initial letter (capitalized by convention).
Superclass(if any): The name of the class’s parent (superclass), if any, preceded by the
keyword extends. A class can only extend (subclass) one parent.
Interfaces(if any): A comma-separated list of interfaces implemented by the class, if
any, preceded by the keyword implements. A class can implement more than one
interface.
Body: The class body surrounded by braces, { }.
7. Object
• It is a basic unit of Object Oriented Programming and represents the real life
entities. A typical Java program creates many objects, which as you know, interact by
invoking methods. An object consists of :
State : It is represented by attributes of an object. It also reflects the properties of an
object.
Behavior : It is represented by methods of an object. It also reflects the response of an
object with other objects.
Identity : It gives a unique name to an object and enables one object to interact with
other objects.
8. OOP concepts
• Inheritance in Java
• Encapsulation in Java
• Abstraction in Java
• Method Overloading
• Input and Output
• Input and Output
• Constructors