Introduction to Java Programming: Features, Applications, and Key Concepts, Lecture notes of Java Programming

A comprehensive introduction to java programming, covering its history, features, applications, and key concepts. It explains the differences between jdk, jre, and jvm, and how they contribute to the development and execution of java applications. The document also discusses java's platform independence, security features, and object-oriented nature, making it a valuable resource for understanding the fundamentals of java programming. It is suitable for beginners and those looking to deepen their understanding of java's core principles and functionalities. The document also touches on the evolution of java, highlighting key milestones and the ongoing development of the language. It serves as a foundational guide for anyone interested in learning java and its role in modern software development.

Typology: Lecture notes

2024/2025

Available from 11/02/2025

blackpink-diaries
blackpink-diaries 🇮🇳

1 document

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
OOPs (Object Oriented Programming System)
Procedural Programming
It is defined as a programming language derived from the structure programming and based on
calling procedures. The procedures are the functions, routines, or subroutines that consist of the
computational steps required to be carried. Why C is called a structured programming language?
C is a structured programming language because it divides a large problem into smaller modules
called functions or procedures, each of which handles a specific responsibility.
-It is structure/procedure-oriented. All data stored in one place.
-It follows a top-down approach.
-In procedural programming, data moves freely within the system from one function to another.
-Examples of Procedural programming include C, Fortran, Pascal, and VB.
Problem
1-Data is not secure
2- Change in data design, affects all function.
3- Debugging is difficult.
4- Maintenance (Periodic modification)
OOPs (Object Oriented Programming System)
Object-Oriented Programming is a methodology or paradigm to design a program using
classes and objects. The programming paradigm where everything is represented as an object is
known as truly or pure object-oriented programming language. Smalltalk is considered as the
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Introduction to Java Programming: Features, Applications, and Key Concepts and more Lecture notes Java Programming in PDF only on Docsity!

OOPs (Object Oriented Programming System)

Procedural Programming

It is defined as a programming language derived from the structure programming and based on calling procedures. The procedures are the functions, routines, or subroutines that consist of the computational steps required to be carried. Why C is called a structured programming language? C is a structured programming language because it divides a large problem into smaller modules called functions or procedures, each of which handles a specific responsibility.

  • It is structure/procedure-oriented. All data stored in one place.
  • It follows a top-down approach.
  • In procedural programming, data moves freely within the system from one function to another.
  • Examples of Procedural programming include C, Fortran, Pascal, and VB.

Problem

1 - Data is not secure 2 - Change in data design, affects all function. 3 - Debugging is difficult. 4 - Maintenance (Periodic modification)

OOPs (Object Oriented Programming System)

Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. The programming paradigm where everything is represented as an object is known as truly or pure object-oriented programming language. Smalltalk is considered as the

first truly object-oriented programming language. It simplifies the software development and maintenance by providing some concepts(features): o Object o Class o Inheritance o Polymorphism o Abstraction o Encapsulation

Object

Any entity that has state and behavior is known as an object. For example: chair, pen, table, keyboard, bike etc. It can be physical and logical. An Object is an instance of a Class. Each object contains data and function to manipulate the data For example “Dog” is a real-life Object, which has some characteristics like color, Breed, Bark, Sleep, and Eats. Object

Class

Collection of objects is called class. It is a logical entity. A class is a user-defined data type. It consists of data members and member functions, which can be accessed and used by creating an instance of that class. It represents the set of properties or methods that are common to all objects of one type. A class is like a blueprint for an object. Take the class of cars as an example. Even if different names and brands may be used for different cars, all of them will have some characteristics in common, such as four wheels, a speed limit, a range of miles, etc. In this case, Car is the class, and wheels, speed limits, mileage are their properties.

Inheritance

When one object acquires all the properties and behaviours of parent object i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism. So when we create a class, we do not need to write all the properties and functions again and again, as

There are the following advantages of abstraction: o It reduces complexity. o It avoids delicacy. o Eases the burden of maintenance o Increase security and confidentially.

Encapsulation

Encapsulation is a mechanism that allows us to bind data and functions of a class into an entity. For example: capsule, it is wrapped with different medicines. It protects data and functions from outside interference and misuse. Therefore, it also provides security. A class is the best example of encapsulation.

As in encapsulation, the data in a class is hidden from other classes, so it is also known as data-hiding.

Benefits of OOP

o Modular, scalable, extensible, reusable, and maintainable. o It models the complex problem in a simple structure. o Object can be used across the program. o Code can be reused. o We can easily modify, append code without affecting the other code blocs. o Provides security through encapsulation and data hiding features. o Beneficial to collaborative development in which a large project is divided into groups. o Debugging is easy.

Limitations of OOP

o Requires intensive testing processes. o Solving problems takes more time as compared to Procedure Oriented Programming. o The size of the programs created using this approach may become larger than the programs written using the procedure-oriented programming approach. o Software developed using this approach requires a substantial amount of pre-work and planning. o OOP code is difficult to understand if you do not have the corresponding class documentation. o In certain scenarios, these programs can consume a large amount of memory. o Not suitable for small problems. o Takes more time to solve problems. According to the TIOBE index, the top twenty OOP languages are Java, C++, C#, Python, R, PHP, Visual Basic.NET, JavaScript, Ruby, Perl, Object Pascal, Objective-C, Dart, Swift, Scala, Kotlin, Common Lisp, MATLAB, and Smalltalk.

  1. Robotics
  2. Games, etc.

Types of Java Applications

There are the following 4-types of applications that can be created using Java programming:

1) Standalone Application

Standalone applications are also known as desktop applications or window-based applications. These are traditional software that we need to install on every machine. Examples of standalone application are Media player, antivirus, etc. AWT and Swing are used in Java for creating standalone applications.

2) Web Application

An application that runs on the server side and creates a dynamic page is called a web application. Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc. technologies are used for creating web applications in Java.

3) Enterprise Application

An application that is distributed in nature, such as banking applications, etc. is called an enterprise application. It has advantages like high-level security, load balancing, and clustering. In Java, EJB is used for creating enterprise applications.

4) Mobile Application

An application which is created for mobile devices is called a mobile application. Currently, Android and Java ME are used for creating mobile applications.

Java Platforms / Editions

There are 4 platforms or editions of Java:

1) Java SE (Java Standard Edition)

It is a Java programming platform. It includes Java programming APIs such as java.lang, java.io, java.net, java.util, java.sql, java.math etc. It includes core topics like OOPs, String, Regex, Exception, Inner classes, Multithreading, I/O Stream, Networking, AWT, Swing, Reflection, Collection, etc.

2) Java EE (Java Enterprise Edition)

It is an enterprise platform that is mainly used to develop web and enterprise applications. It is built on top of the Java SE platform. It includes topics like Servlet, JSP, Web Services, EJB, JPA, etc.

3) Java ME (Java Micro Edition)

It is a micro platform that is dedicated to mobile applications.

4) JavaFX

It is used to develop rich internet applications. It uses a lightweight user interface API.

History of Java

Java was developed by James Gosling, who is known as the father of Java, in 1995. James Gosling and his team members started the project in the early '90s. Currently, Java is used in internet programming, mobile devices, games, e-business solutions, etc. Following are given significant points that describe the history of Java.

  1. James Gosling, Mike Sheridan , and Patrick Naughton initiated the Java language project in June
  1. The small team of sun engineers called Green Team.
  1. Initially it was designed for small, embedded systems in electronic appliances like set-top boxes.
  2. Firstly, it was called "Greentalk" by James Gosling, and the file extension was .gt.
  3. After that, it was called Oak and was developed as a part of the Green project.

Why Java was named as "Oak"?

  1. Java SE 8 (18th Mar 2014)
  2. Java SE 9 (21st Sep 2017)
  3. Java SE 10 (20th Mar 2018)
  4. Java SE 11 (September 2018)
  5. Java SE 12 (March 2019)
  6. Java SE 13 (September 2019)
  7. Java SE 14 (Mar 2020)
  8. Java SE 15 (September 2020)
  9. Java SE 16 (Mar 2021)
  10. Java SE 17 (September 2021)
  11. Java SE 18 (to be released by March 2022) Since Java SE 8 release, the Oracle corporation follows a pattern in which every even version is release in March month and an odd version released in September month.

Features of Java

. The features of Java are also known as Java buzzwords. A list of the most important features of the Java language is given below. 1. Simple 2. Object-Oriented 3. Portable 4. Platform independent 5. Secured 6. Robust 7. Architecture neutral 8. Interpreted 9. High Performance 10. Multithreaded 11. Distributed 12. Dynamic Simple Java is very easy to learn, and its syntax is simple, clean and easy to understand. According to Sun Microsystem, Java language is a simple programming language because: o Java syntax is based on C++ (so easier for programmers to learn it after C++). o Java has removed many complicated and rarely-used features, for example, explicit pointers, operator overloading, etc. o There is no need to remove unreferenced objects because there is an Automatic Garbage Collection in Java. AD

Object-oriented Java is an object-oriented programming language. Everything in Java is an object. Object-oriented means we organize our software as a combination of different types of objects that incorporate both data and behavior. Object-oriented programming (OOPs) is a methodology that simplifies software development and maintenance by providing some rules. Basic concepts of OOPs are:

  1. Object
  2. Class
  3. Inheritance
  4. Polymorphism
  5. Abstraction
  6. Encapsulation Platform Independent Java is platform independent because it is different from other languages like C, C++, etc. which are compiled into platform specific machines while Java is a write once, run anywhere language. A platform is the hardware or software environment in which a program runs. There are two types of platforms software-based and hardware-based. Java provides a software-based platform. The Java platform differs from most other platforms in the sense that it is a software-based platform that runs on top of other hardware-based platforms. It has two components:
  7. Runtime Environment
  8. API(Application Programming Interface)

Robust The English mining of Robust is strong. Java is robust because: o It uses strong memory management. o There is a lack of pointers that avoids security problems. o Java provides automatic garbage collection which runs on the Java Virtual Machine to get rid of objects which are not being used by a Java application anymore. o There are exception handling and the type checking mechanism in Java. All these points make Java robust. AD Architecture-neutral Java is architecture neutral because there are no implementation dependent features, for example, the size of primitive types is fixed. In C programming, int data type occupies 2 bytes of memory for 32-bit architecture and 4 bytes of memory for 64 - bit architecture. However, it occupies 4 bytes of memory for both 32 and 64 - bit architectures in Java. Portable Java is portable because it facilitates you to carry the Java bytecode to any platform. It doesn't require any implementation. High-performance Java is faster than other traditional interpreted programming languages because Java bytecode is "close" to native code. It is still a little bit slower than a compiled language (e.g., C++). Java is an interpreted language that is why it is slower than compiled languages, e.g., C, C++, etc. Advertisement AD Distributed Java is distributed because it facilitates users to create distributed applications in Java. RMI and EJB are used for creating distributed applications. This feature of Java makes us able to access files by calling the methods from any machine on the internet. Multi-threaded A thread is like a separate program, executing concurrently. We can write Java programs that deal with many tasks at once by defining multiple threads. The main advantage of multi-threading is that it doesn't occupy memory for each thread. It shares a common memory area. Threads are important for multi- media, Web applications, etc.

Dynamic Java is a dynamic language. It supports the dynamic loading of classes. It means classes are loaded on demand. It also supports functions from its native languages, i.e., C and C++. Java supports dynamic compilation and automatic memory management (garbage collection).

C++ vs Java

There are many differences and similarities between the C++ programming language and Java. A list of top differences between C++ and Java are given below: Platform-independent C++ is platform-dependent. Java is platform-independent. Mainly used for C++ is mainly used for system programming. Java is mainly used for application programming. It is widely used in Windows-based, web-based, enterprise, and mobile applications. Design Goal C++ was designed for systems and applications programming. It was an extension of the C programming language. Java was designed and created as an interpreter for printing systems but later extended as a support network computing. It was designed to be easy to use and accessible to a broader audience. Goto C++ supports the goto statement. Java doesn't support the goto statement. Multiple inheritance C++ supports multiple inheritance. Java doesn't support multiple inheritance through class. It can be achieved by using interfaces in

Virtual Keyword C++ supports virtual keyword so that we can decide whether or not to override a function. Java has no virtual keyword. We can override all non-static methods by default. In other words, non-static methods are virtual by default. unsigned right shift >>> C++ doesn't support >>> operator. Java supports unsigned right shift

operator that fills zero at the top for the negative numbers. For positive numbers, it works same like >> operator. Inheritance Tree C++ always creates a new inheritance tree. Java always uses a single inheritance tree because all classes are the child of the Object class in Java. The Object class is the root of the inheritance tree in java. Hardware C++ is nearer to hardware. Java is not so interactive with hardware. Object-oriented C++ is an object-oriented language. However, in the C language, a single root hierarchy is not possible. Java is also an object- oriented language. However, everything (except fundamental types) is an object in Java. It is a single root hierarchy as everything gets derived from java.lang.Object. Note o Java doesn't support default arguments like C++. o Java does not support header files like C++. Java uses the import keyword to include different classes and methods.

Differences between JDK, JRE and JVM

 Understanding the difference between JDK, JRE, and JVM plays a very important role in understanding how Java works and how each component contributes to the development and execution of Java applications. The main difference between JDK, JRE, and JVM is:  JDK: Java Development Kit is a software development environment used for developing Java applications and applets.  JRE: JRE stands for Java Runtime Environment and it provides an environment to run only the Java program onto the system.  JVM: JVM stands for Java Virtual Machine and is responsible for executing the Java program.

JDK vs JRE vs JVM

Aspect JDK JRE JVM Purpose Used to develop Java applications Used to run Java applications Responsible for running Java code Platform Dependency Platform-dependent Platform-dependent Platform-Independent Includes It includes development tools like (compiler) + JRE It includes libraries to run Java application + JVM It runs the java byte code and make java application to work on any platform. Use Case Writing and compiling Java code Running a Java application on a system Convert bytecode into native machine code

Note : From above, media operation computing during the compile time can be interpreted. The following actions occur at runtime as listed below:  Class Loader  Byte Code Verifier  Interpreter o Execute the Byte Code o Make appropriate calls to the underlying hardware JRE((Java Runtime Environment) The JRE is an installation package that provides an environment to only run(not develop) the Java program (or application) onto your machine. JRE is only used by those who only want to run Java programs that are end-users of your system. Working of JRE When you run a Java program, the following steps occur:  Class Loader : The JRE’s class loader loads the .class file containing the bytecode into memory.  Bytecode Verifier : The bytecode verifier checks the bytecode for security and correctness.  Interpreter : The JVM interprets the bytecode and executes the program.  Execution : The program executes, making calls to the underlying hardware and system resources as needed. JVM (Java Virtual Machine) The JVM is a very important part of both JDK and JRE because it is contained or inbuilt in both. Whatever Java program you run using JRE or JDK goes into JVM and JVM is responsible for executing the java program line by line, hence it is also known as an interpreter.

Working of JVM It is mainly responsible for three activities.  Loading  Linking  Initialization