Introduction Tojava 3
Introduction Tojava 3
History of Java:
Java was created by James Gosling and his team at Sun
Microsystems in the early 1990s.
The initial version of Java, known as Java 1.0, was released to
the public in 1995.
Java's popularity grew rapidly due to its versatility and cross-
platform compatibility, leading to its widespread adoption in
enterprise software development, mobile app development,
web development, and more.
Java Features
Java was created by James Gosling and his team at Sun
Microsystems in the early 1990s.
The initial version of Java, known as Java 1.0, was released to
the public in 1995.
Object-Oriented:
Java is an object-oriented programming language, which means
it revolves around the concept of objects. Objects are instances
of classes, which encapsulate data and behavior.
Object-oriented programming allows for modular, reusable
code, making it easier to manage and maintain large-scale
projects.
Platform-Independent:
Java programs can run on any platform with a compatible
Java Virtual Machine (JVM). This platform independence is
achieved through the compilation of Java source code into
bytecode, which can be executed on any device or
operating system with a JVM installed.
This "write once, run anywhere" capability makes Java
highly versatile and accessible.
Simple and Familiar:
Java was designed to be easy to learn and use, with a syntax that is
similar to C++ and other popular programming languages.
Its simplicity and familiarity make it an ideal choice for beginners
and experienced developers alike, enabling faster development and
reduced learning curves.
Secure:
Java prioritizes security by incorporating various features such
as bytecode verification, runtime sandboxing, and access
control mechanisms.
These built-in security measures help protect against
vulnerabilities such as buffer overflows, memory corruption, and
unauthorized access to system resources, making Java
applications more robust and resilient to cyber threats.
Robust:
Java's robustness stems from its strong type system,
automatic memory management (garbage collection), and
exception handling mechanisms.
These features ensure that Java programs are less prone to
errors, crashes, and memory leaks, resulting in more stable
and reliable software.
Portable:
Java's portability is achieved through its bytecode compilation
and interpretation model, which allows Java programs to be
executed on any platform with a compatible JVM.
This eliminates the need for platform-specific compilation,
making Java applications truly platform-independent and
easily deployable across different environments.
Dynamic :
Java's dynamic capabilities include features such as dynamic
class loading and reflection, which enable runtime
manipulation of classes and objects.
This flexibility allows developers to create dynamic and
adaptable applications that can respond to changing
requirements and environments.
Multithreaded :
Java supports multithreading, allowing concurrent execution
of multiple tasks within the same program.
Multithreading enables developers to create responsive and
interactive applications that can perform multiple operations
simultaneously, enhancing performance and scalability.
Java Features:
Sample Java Program:
public class HelloWorld {
public static void main(String[] args) {
// Prints "Hello, World!" to the
terminal window
System.out.println("Hello, World!");
}
}
Explanation of Program Structure :
This Java program demonstrates the classic "Hello, World!"
example, which is often the first program taught to beginners
in programming.
The program consists of a single class named HelloWorld.
Within the class, there is a main method, which serves as the
entry point for the program.
The main method is declared as public, indicating that it can be
accessed from outside the class.
It is also declared as static, meaning it belongs to the class itself
rather than to instances of the class.
The main method takes an array of strings (args) as a
parameter, although it is not used in this example.
Inside the main method, a single statement is executed, which
prints the string "Hello, World!" to the terminal window using
the System.out.println method.
Atpar
Java Variables:
In Java, a variable is a named storage location used to store
data that can be manipulated and referenced in a program.
Variables in Java have a specific data type, which determines
the type of data that can be stored in them.
They are used to store values such as numbers, text, and
objects, allowing programmers to work with data in their
programs.
Instance Variables:
Static variables, also known as class variables, are declared with
the static keyword within a class but outside of any method,
constructor, or block.
They are associated with the class itself rather than with
instances of the class and are shared among all instances.
Static variables are initialized when the class is loaded into
memory and can have default values if not explicitly initialized.
Variable Naming Conventions:
Variable names in Java should be meaningful and descriptive,
reflecting the purpose or content of the data they store.
They must begin with a letter, underscore (_), or dollar sign ($)
and can be followed by letters, digits, underscores, or dollar
signs.
Variable names are case-sensitive, meaning that myVariable and
MyVariable are considered different variables.
It is recommended to use camelCase notation for variable names,
starting with a lowercase letter and capitalizing the first letter of
each subsequent word.
Atpar
Variables;
Java Data Types:
Primitive Data Types:
Primitive data types in Java are basic data types that are
predefined by the language and are not objects.
They represent single values and include:int: Used to store
integer values.
double: Used to store floating-point numbers with decimal values.
char: Used to store single characters.
boolean: Used to store true or false values.
And others such as byte, short, long, and float.
Reference Data Types:
Reference data types in Java are non-primitive data types that
are not predefined by the language and are created by the
programmer.
They represent complex data structures and include:Objects:
Instances of classes created using the new keyword.
Arrays: Ordered collections of elements of the same type.
Strings: Immutable sequences of characters.
And other user-defined classes and interfaces.
Relational Operators:
Relational operators are used to compare values and determine
the relationship between them.
They include equality (==), inequality (!=), greater than (>),
less than (<), greater than or equal to (>=), and less than or
equal to (<=).
Example: boolean isGreater = 10 > 5;
Logical Operators:
Logical operators are used to perform logical operations on
boolean operands.
They include logical AND (&&), logical OR (||), and logical
NOT (!).
Example: boolean result = (x > 0) && (y < 10);
Assignment Operators:
Assignment operators are used to assign values to variables.
They include simple assignment (=), as well as compound assignment
operators like addition assignment (+=), subtraction assignment (-=),
multiplication assignment (*=), and division assignment (/=).
Example: int x = 5; x += 3; // Equivalent to x = x + 3;
Operators:
Atpar
Java Keywords
Explanation of Keywords in Java:
Keywords in Java are reserved words that have predefined
meanings and cannot be used as identifiers (e.g., variable names,
class names, etc.).
They play crucial roles in defining the syntax and structure of Java
programs.
Examples include public, class, void, if, else, for, while, return, etc.
Examples of Keywords:
public: Access modifier used to specify the visibility of classes,
methods, and variables.
class: Keyword used to declare a class in Java.
void: Keyword used to indicate that a method does not return
any value.
if, else: Keywords used for conditional branching in Java.
Importance of Keywords in Programming:
Keywords form the foundation of the Java language and
provide essential building blocks for writing Java code.
They define the structure, behavior, and flow of Java
programs, making them indispensable for developers.
Understanding and correctly using Java keywords is
essential for writing efficient, readable, and maintainable
code.
Sources To Learn More:
JavaTpoint: https://www.javatpoint.com/introduction-to-java
W3 schools:
https://www.w3schools.com/java/java_intro.asp
YouTube:
https://www.youtube.com/watch?v=bm0OyhwFDuY&list=P
LsyeobzWxl7pe_IiTfNyr55kwJPWbgxB5
https://www.youtube.com/watch?v=Hl-zzrqQoSE&list=PLF
E2CE09D83EE3E28