Unit 4.1
Unit 4.1
What is Java?
• Developed by Sun Microsystems in 1995, Java is a highly
popular, object-oriented programming language.
• This platform independent programming language is utilized
for Android development, web development, artificial
intelligence, cloud applications, and much more.
• Java is one of the most popular and widely used
programming languages and platforms.
• Java is fast, reliable, and secure.
• Steps to Implement Java Program
Implementation of a Java application program involves the
following step. They include:
1. Creating the program
2. Compiling the program
3. Running the program
Introduction to OOP concepts in java
• Object-oriented programming aims to
implement real-world entities like inheritance,
hiding, polymorphism, etc. in programming..
1.Data Abstraction is the property by virtue of which
only the essential details are displayed to the user.
2.Encapsulation
• It is defined as the wrapping up of data under a single
unit.
3.Inheritance is an important pillar of OOP (Object
Oriented Programming). It is the mechanism in Java by
which one class is allowed to inherit the features (fields
and methods) of another class.
6. ClassPath: The classpath is the file path where the java runtime
and Java compiler look for .class files to load. By default, JDK
provides many libraries. If you want to include external libraries they
should be added to the classpath.
Primary/Main Features of Java
1. Platform Independent: Compiler converts source code to bytecode and
then the JVM executes the bytecode generated by the compiler. This
bytecode can run on any platform be it Windows, Linux, or macOS which
means if we compile a program on Windows, then we can run it on Linux
and vice versa. Each operating system has a different JVM, but the output
produced by all the OS is the same after the execution of the bytecode.
That is why we call java a platform-independent language.
3. Simple: Java is one of the simple languages as it does not have complex
features like pointers, operator overloading, multiple inheritances, and Explicit
memory allocation.
4. Robust: Java language is robust which means reliable. It is
developed in such a way that it puts a lot of effort into checking errors
as early as possible, that is why the java compiler is able to detect
even those errors that are not easy to detect by another programming
language. The main features of java that make it robust are garbage
collection, Exception Handling, and memory allocation.
characters representation of
‘a’, ‘\u0041’, ‘\101’, ‘\\’, ‘\’, ‘\n’,
char Unicode character \u0000 16 bits
‘β’
ASCII values
0 to 255
-2,147,483,648
int twos-complement intger 0 32 bits -2,-1,0,1,2 to
2,147,483,647
-9,223,372,036,854,775,808
long twos-complement integer 0 64 bits -2L,-1L,0L,1L,2L to
9,223,372,036,854,775,807
1.23456e300d ,
double IEEE 754 floating point 0.0 64 bits
-123456e-300d , 1e1d
upto 16 decimal digits
Non-Primitive Data Type
1. Strings
Strings are defined as an array of characters.
Syntax: Declaring a string
<String_Type> <string_variable> = <sequence_of_string>”;
2. Class
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.
• Modifiers: A class can be public or has default access. Refer to access
specifiers for classes or interfaces in Java
• Class name: The name should begin with an 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 is surrounded by braces, { }.
3. Object
• An Object is a basic unit of Object-Oriented Programming and
represents 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 the attributes of an object. It also reflects
the properties of an object.
• Behavior: It is represented by the methods of an object. It also
reflects the response of an object to other objects.
• Identity: It gives a unique name to an object and enables one
object to interact with other objects.
4. Interface
• Like a class, an interface can have methods and variables, but the
methods declared in an interface are by default abstract (only
method signature, no body).
5. Array
• An Array is a group of like-typed variables that are referred to by a
common name