0% found this document useful (0 votes)
19 views5 pages

Introduction to Java Programming Basics

The document provides an introduction to Java, covering its definition, features, and reasons to learn it, emphasizing its simplicity, security, and versatility in various applications. It explains Java's editions, key terminologies, program execution process, and differences from C/C++. Additionally, it discusses output methods, comments, variables, and data types, including both primitive and non-primitive types.

Uploaded by

m62269582
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)
19 views5 pages

Introduction to Java Programming Basics

The document provides an introduction to Java, covering its definition, features, and reasons to learn it, emphasizing its simplicity, security, and versatility in various applications. It explains Java's editions, key terminologies, program execution process, and differences from C/C++. Additionally, it discusses output methods, comments, variables, and data types, including both primitive and non-primitive types.

Uploaded by

m62269582
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

Day-01 Intro

02 May 2025 12:01

1. Introduction to Java
1.1 What is Java?
Java is a simple, object-oriented, distributed, interpreted, robust, secure, architectural
neutral, portable, high performance, multithreaded, and dynamic language.
--From Sun's Website

It was developed by James Gosling in 1995 at Sun Microsystems (later acquired by Oracle
Corporation).
Java is known for its slogan: "Write Once, Run Anywhere" (WORA)

1.2 Why Learn Java?


• It is easy to learn and simple to use
• It is open-source and free
• It is secure, fast and powerful
• Used in web, mobile, desktop, and enterprise applications
• Android development is based on Java
• Strong community and rich set of libraries
• Forms the foundation for learning other programming paradigms

1.3 Features of Java (With Explanation)


Feature Description
Simple Syntax similar to C/C++ but no pointers or operator overloading
Object-Oriented Everything revolves around classes and objects, no coding outside of
class
Platform- Write-Once-Run-Anywhere
Independent
Secure No direct memory access, It has a security manager.
Robust Strong error checking and exception handling
Multithreaded Supports multi-tasking using threads
Architecture-Neutral Same output on any system with a JVM
High Performance Uses JIT (Just-In-Time) compiler
Dynamic Loads classes at runtime, supports dynamic linking

1.4 Java Editions


Edition Description
Java SE (Standard Edition) Core functionality – for desktop applications
Java EE (Enterprise Edition) For large-scale, web-based enterprise apps
Java ME (Micro Edition) For small devices like mobile phones
JavaFX For building rich desktop user interfaces

1.5 Java Terminologies

A Page 1
1.5 Java Terminologies
Term Meaning
JDK (Java Development Kit) Tools for developing Java applications (includes JRE +
compiler)
JRE (Java Runtime Required to run Java applications (includes JVM + libraries)
Environment)
JVM (Java Virtual Machine) Runs the Java bytecode, making Java platform-independent
Bytecode Intermediate code generated after compilation (understood
by JVM)

1.6 Java Program Execution Process


Source Code (.java)
↓ (compiled by javac)
Bytecode (.class)
↓ (executed by java)
Output on Console

1.7 First Java Program

public class HelloWorld {


public static void main(String[] args) {
[Link]("Hello, World!");
}
}

Explanation:
▪ public class HelloWorld → Class definition
▪ public static void main(String[] args) → Starting point of execution
▪ [Link]("Hello, World!") → Prints text to console

Output:
Hello, World!

1.8 How Java is Different from C/C++


Feature Java C/C++
Memory Management Automatic (Garbage Collector) Manual (malloc/free)
Platform Platform-independent Platform-dependent
Pointers Not supported Fully supported
Multiple Inheritance Not directly supported Supported
Security More secure Less secure

2.1 Output
To print anything we can use print methods.

[Link]("Text you want to print");

A Page 2
[Link]("Text you want to print");
[Link]("Prints new line after text");
[Link](456);
[Link](7+21);

2.2 Comments
Comments in Java help explain code, improve readability, and can temporarily disable code
during testing.

a. Single-line Comments:
Single-line comments start with two forward slashes (//).
Any text between // and the end of the line is ignored by Java (will not be executed).

// This is a comment
[Link]("Learn Java");

b. Multi-line Comments
Multi-line comments start with /* and ends with */.
Any text between /* and */ will be ignored by Java.

/* The code below will print the words Hello World


to the screen, and it is amazing */
[Link]("Comments make code more readable");

2.3 Variables
Variables are like labelled boxes used to hold and keep track of data. You can store different
types of information in these boxes, such as numbers or text, and you can retrieve or change
the data later when needed.

There are different types of variables like :


int, float, String, char, Boolean, etc..

How to create a variable:


To create a variable, you need to define its type and give it a value.

type variableName = value;

int a= 10;

The basic rules for naming variables are as follows:


• Variable names can include letters, digits, underscores, and dollar signs.
• Names must start with a letter.
• It’s best to start names with a lowercase letter, and they cannot have spaces.
• Names can also begin with a dollar sign ($) or an underscore (_).
• Variable names are case-sensitive; for example, "myVar" and "myvar" are considered
different variables.
• You cannot use reserved words (such as Java keywords like int or boolean) as variable
names.

2.4 Data Types

A Page 3
Primitive Data Types:

Type Defau Size Range of Values


lt
Value
s
boole false 8 bits true, false
an
byte 0 8 bits -128 to 127
char \u000 16 bits Characters Representation of ASCII values: 0 to 255
0
short 0 16 bits -32,768 to 32,767
int 0 32 bits -2,147,483,648 to 2,147,483,647
long 0 64 bits -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float 0.0f 32 bits up to 7 decimal digits
doubl 0.0 64 bits up to 16 decimal digits
e

Non-Primitive Data Types:


In Java, non-primitive data types are also known as reference data types. It is used to store
complex objects rather than simple values.

• Class: Classes are used to create objects, which are specific instances of the class. A
class defines the characteristics and behaviours of these objects, including their
properties (variables or fields) and functions (methods).
• Interface: An interface sets the requirements for a class that chooses to implement it,
detailing what functionalities must be provided but not how to achieve them. In Java,
interfaces promote abstraction and enable multiple inheritance, which makes classes
more flexible and reusable.
• Arrays: Arrays in Java are a way to store multiple values of the same type in one
variable. They have a fixed size, set when created, and are accessed by index. They are
often used for lists or simple tables.
• String: In Java, a string is a sequence of characters, like an array. Unlike a char array, a
string stores characters in one variable.
• enum: Enums are used to define a set of named constants, providing a way to represent
a fixed set of values.

A Page 4
A Page 5

You might also like