0% found this document useful (0 votes)
7 views7 pages

Introduction to Java Programming Basics

The document introduces Java as a high-level, object-oriented programming language that is platform-independent due to the Java Virtual Machine (JVM). It explains the core principles of Object-Oriented Programming (OOP), including abstraction, encapsulation, inheritance, and polymorphism, and provides a guide on setting up the Java Development Kit (JDK) on Windows. Additionally, it outlines the structure of Java code and the features of Integrated Development Environments (IDEs), with examples of popular IDEs for Java development.

Uploaded by

melody.david
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

Introduction to Java Programming Basics

The document introduces Java as a high-level, object-oriented programming language that is platform-independent due to the Java Virtual Machine (JVM). It explains the core principles of Object-Oriented Programming (OOP), including abstraction, encapsulation, inheritance, and polymorphism, and provides a guide on setting up the Java Development Kit (JDK) on Windows. Additionally, it outlines the structure of Java code and the features of Integrated Development Environments (IDEs), with examples of popular IDEs for Java development.

Uploaded by

melody.david
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

🧑🏽‍🏫 Java Programming-I

📘 Session 1: Introduction to Java


Java is a high-level, object-oriented programming language developed by Sun
Microsystems (now owned by Oracle).
It's platform-independent thanks to the Java Virtual Machine (JVM), meaning you can
write code once and run it anywhere.

📱 Popular Apps Built with Java


●​ Twitter (originally built with Java on the backend)​

●​ Spotify (uses Java for backend and data processing)​

●​ Netflix (uses Java for backend microservices)​

●​ Minecraft (desktop version is built with Java)​

●​ Android Apps (many are developed in Java using Android Studio)

What is OOP?
OOP (Object-Oriented Programming) is a programming paradigm based on the concept of
"objects", which are instances of classes.

* Object​
An object is an instance of a class that holds data and behavior.​
It represents a real-world entity like a student, car, or account.​
Example of object is Dog

​ * Property - Color, Age

​ * Action - Barking, eating, running

* Class​
A class is a template or blueprint for creating objects.​
It defines variables (field), functions (method), states and behaviour of all objects
belonging to that class.
🔑 4 Core Principles of OOP:
3. Abstraction​
Abstraction hides complex implementation and shows only essential features.​
It helps reduce complexity by exposing only what’s necessary.

4. Encapsulation​
Encapsulation binds data and methods into a single unit (class).​
It restricts direct access to internal data using access modifiers (like private).

5. Inheritance​
Inheritance allows a class to inherit properties and methods from another class.​
It promotes code reuse and establishes a parent-child relationship.

6. Polymorphism​
Polymorphism means one function or object can behave in many ways.​
It enables method overriding (runtime) and method overloading (compile-time).

☕ What is JDK? - Part of Java component


JDK (Java Development Kit) is a software development kit provided by Oracle and
others that allows you to develop and run Java applications.

👉 Oracle JDK (Latest Version):​


[Link]


To set the JAVA_HOME environment variable on Windows, follow these
steps:

✅ Step-by-Step: Set JAVA_HOME on Windows


🔹 1. Find your JDK installation path
For example, it might be:

C:\Program Files\Java\jdk-21
You must copy the JDK folder path — not the bin folder.

🔹 2. Open Environment Variables


1.​ Press Windows + S, search for Environment Variables and click on:​
“Edit the system environment variables”​

2.​ In the System Properties window, click on:​


“Environment Variables…”​

🔹 3. Create the JAVA_HOME variable


Under System variables:

1.​ Click New​

In Variable name, enter:​



JAVA_HOME

2.​

In Variable value, paste the JDK path:​



C:\Program Files\Java\jdk-21

3.​
4.​ Click OK​

🔹 4. Update the Path variable


Still under System variables:

1.​ Find the variable named Path​

2.​ Select it and click Edit​

Click New and add:​



%JAVA_HOME%\bin

3.​
4.​ Click OK, then again to close all dialogs​

🔹 5. Verify it works
Open Command Prompt and run:

java -version
javac -version
echo %JAVA_HOME%

Java Structure

🧩 Structure Breakdown
1.​ Package – Organizes classes into namespaces. Optional if you're just starting.​

2.​ Import – Brings in classes from Java libraries (e.g., Scanner for user input).​

3.​ Class – Every Java code must be inside a class. It's the main container.​

4.​ Field - Store object data (e.g., name, age)​


5.​ Constructor - Initializes objects when they created​

6.​ Main Method – Java starts execution from public static void main(String[]
args).​

7.​ Statements – Your logic, like printing, calculations, or function calls.

How to save java code file


To save java code, you must use .java​
Note that it is case sensitive.​
Example- [Link].​
You can save with any name you wish, so far you add it with .java
💡 What is an IDE?
💡 What is an IDE?
IDE stands for Integrated Development Environment.

It's a software application that provides a complete set of tools to write, edit, test, and debug
code all in one place — making programming easier and faster.

🧰 Key Features of an IDE:


●​ Code Editor – where you write your code​

●​ Compiler/Interpreter – to convert your code into something the computer can run​

●​ Debugger – to find and fix errors in your code​

●​ Build Tools – to compile, run, and package your programs​

●​ Auto-complete – helps you write code faster with suggestions​

✅ Examples of IDEs:
●​ NetBeans – for Java, C++, etc.​

●​ IntelliJ IDEA – advanced Java IDE​

●​ Eclipse – widely used for Java and Android​

●​ Android Studio – for Android apps​

●​ Visual Studio – for C#, .NET, etc.​


.

We are going to use NetBeans today, but when we want to build mobile apps, we will
use Android Studio.

👉
Official download:
[Link]


Assignment..​
Read on-
1.​ Java platform and it’s component - JVM, JRE, JDK
2.​ Comments in Java

Common questions

Powered by AI

Encapsulation is key for controlling access to an object's data and methods by bundling them within a class, which minimizes interference and unintended behavior from outside code. It is implemented using access modifiers like 'private', 'protected', and 'public', which define visibility levels. By marking class variables as 'private', developers can restrict direct access and instead provide 'public' getter and setter methods to access or modify these variables. This approach maintains control over data integrity, enforces logical constraints, and protects object state, promoting secure and maintainable code .

The Java Development Kit (JDK) includes the Java Runtime Environment (JRE) and development tools necessary to write, test, and run Java programs. The JRE is a part of the JDK that allows running Java applications by providing the necessary libraries and the Java Virtual Machine (JVM). The JVM executes Java bytecode and enables the language's platform independence. The relationship between these components is hierarchical: the JDK is at the top containing both JRE and JVM, while the JRE contains the JVM .

Platform independence in Java means that Java code can run on any device that has a Java Virtual Machine (JVM), regardless of the underlying hardware and operating system. The JVM acts as an intermediary between the Java code and the machine's native code, compiling Java bytecode into machine code for the specific hardware it is running on. This allows developers to write code once and have it run anywhere that supports a JVM .

Inheritance allows classes to inherit properties and methods from other classes, which eliminates the need to write duplicate code, thus promoting code reuse. Polymorphism enables one function or object to take multiple forms, which allows for dynamic method invocation where a subclass can override a method in the superclass. This increases the flexibility and extensibility of the code, as new classes can be used without altering existing methods or compromising the overall program structure. Together, these features enhance the adaptability and maintainability of code by enabling developers to apply changes in a single place that propagate throughout the inherited structures .

The core principles of OOP, specifically abstraction and encapsulation, optimize Java application development by reducing complexity and enhancing code maintainability. Abstraction allows developers to hide complex implementation details and expose only essential features, making it easier to manage large systems. Encapsulation binds data and methods within a class, restricting access to internal data and enhancing security by using access modifiers. Together, these principles promote cleaner, more modular code, which is easier to understand, debug, and modify .

Constructors in Java are specialized methods used to initialize new objects. They are called when an object is instantiated using the 'new' keyword. Unlike regular methods, constructors do not have a return type, and their primary role is to set up initial states by assigning values to class fields. This process is crucial as it ensures objects are in a valid state before they are used. Unlike default initialization or standard methods, constructors provide a structured approach to initializing objects with specific parameters, thus enabling customization and promoting robust application design .

NetBeans and Android Studio are both popular Integrated Development Environments (IDEs) for Java development, each with strengths suited to specific contexts. NetBeans is known for its extensibility, support for multiple languages, and built-in tools for desktop and web applications, making it versatile for general-purpose Java development. In contrast, Android Studio is specifically tailored for Android app development, offering features such as an Android emulator, code templates for Android components, and integration with Google Cloud Messaging. While NetBeans excels in flexibility and support for a broad range of projects, Android Studio provides specialized tools and interfaces that significantly streamline Android app creation and testing, making it the preferred choice for mobile app developers .

Method overriding in Java is an example of runtime polymorphism where a subclass provides a specific implementation of a method already defined in its superclass. This process allows a subclass to tailor inherited methods to fit its needs, which is essential for dynamic method dispatch. When overridden, the method invoked is determined by the type of the object at runtime, rather than the type of reference at compile time. This is significant as it enables Java programs to execute code based on actual object types, enhancing flexibility and scalability by allowing developers to create varied behavior in an organized and efficient manner .

Setting the JAVA_HOME environment variable on Windows ensures that Java applications can consistently locate the Java Development Kit (JDK) necessary for compiling and running Java programs. By setting JAVA_HOME to point to the installation directory of the JDK, developers enable system-level applications and other tools to automatically reference the correct Java components, which is crucial for compilation, execution, and development in Java. This setup minimizes path errors and enhances compatibility across different development tools and scripts that rely on Java functionalities .

Integrated Development Environments (IDEs) significantly enhance Java programming productivity by providing tools that streamline the coding process. An IDE typically includes a code editor, compiler or interpreter, debugger, and build tools, all within a single software application. Features like code auto-completion, error highlighting, and integrated testing environments help developers write code more efficiently and with fewer errors, speeding up development and allowing for faster iteration and testing .

You might also like