0% found this document useful (0 votes)
1 views

Introduction Tojava 3

Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995, known for its platform independence, simplicity, and security features. It supports key programming concepts such as object-oriented design, multithreading, and dynamic class loading, making it widely used in various applications. The document also covers Java's history, features, data types, variables, operators, and keywords, along with resources for further learning.

Uploaded by

Mahesh Sai
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Introduction Tojava 3

Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995, known for its platform independence, simplicity, and security features. It supports key programming concepts such as object-oriented design, multithreading, and dynamic class loading, making it widely used in various applications. The document also covers Java's history, features, data types, variables, operators, and keywords, along with resources for further learning.

Uploaded by

Mahesh Sai
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Java

Introduction to Java Programming


An Overview of Java Language
What is Java?
 Definition of Java:
 Java is a high-level, object-oriented programming language
developed by Sun Microsystems (now owned by Oracle
Corporation) in 1995.
 It was designed to be platform-independent, meaning that
Java programs can run on any device or operating system
that has a Java Virtual Machine (JVM) installed.
 Java is known for its simplicity, reliability, and security
features, making it one of the most widely used
programming languages in the world.

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.

Key features of Java:


 Object-Oriented: Java follows the object-oriented programming
paradigm, allowing developers to create modular, reusable
code using classes and objects.
 Platform-Independent: Java programs can run on any device or
operating system that has a compatible JVM, thanks to its
"write once, run anywhere" philosophy.
 Simple and Familiar: Java was designed to be easy to learn and
use, with syntax similar to C++ and other popular
programming languages.
 Secure: Java's built-in security features, such as bytecode
verification and runtime sandboxing, help protect against
malicious code and unauthorized access to system resources.
 Robust: Java's strong type system, automatic memory
management (garbage collection), and exception handling
mechanisms contribute to its robustness and reliability.
 Portable: Java's bytecode can be executed on any platform with a
compatible JVM, eliminating the need for platform-specific
compilation.
 Multithreaded: Java supports concurrent programming through its
built-in support for multithreading, allowing developers to create
applications that can perform multiple tasks simultaneously.
 Dynamic: Java's dynamic class loading and reflection capabilities
enable runtime manipulation of classes and objects, facilitating
dynamic application behavior.

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.

Running a Java Program:


 To run a Java program, you need to first compile the source
code into bytecode using the Java compiler (javac).
 Once compiled, you can execute the bytecode using the Java
Virtual Machine (JVM) by running the java command followed
by the name of the class containing the main method.
 After execution, the output "Hello, World!" will be displayed in
the terminal window.
WORA:

 Java is an object-oriented programming language that is class-


based and designed to have as few implementation dependencies
as possible. It is intended to let application developers "write
once, run anywhere" (WORA), meaning that compiled Java code
can run on all platforms without the need for recompilation.
JDK, JRE, and JVM:
JDK (Java Development Kit) :
 The JDK is a software development kit used for developing Java
applications.
 It includes tools such as the Java compiler (javac), which is used to
compile Java source code into bytecode, and the Java Archive Tool
(jar), which is used to package compiled bytecode into JAR files.
 The JDK also includes a complete Java Runtime Environment (JRE)
and other development tools and libraries necessary for Java
development.

JVM (Java Virtual Machine) :


 The JVM is a virtual machine that provides a runtime
environment for executing Java bytecode.
 It abstracts the underlying hardware platform, allowing Java
programs to be platform-independent.
 The JVM interprets bytecode instructions and dynamically
translates them into native machine code for execution by
the host system.

JVM (Java Virtual Machine) :

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.

Different Types of Variables :


Local Variables:

 Local variables are declared within a method, constructor, or


block of code and are only accessible within that specific scope.
 They are created when the method or block is entered and
destroyed when it exits.
 Local variables do not have default values and must be initialized
before use.
Instance Variables:
 Instance variables are declared within a class but outside of
any method, constructor, or block.
 They are associated with instances or objects of the class and
are unique to each instance.
 Instance variables are initialized when an object is created and
can have default values if not explicitly initialized.

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.

Data Type Conversions:


 Data type conversions in Java allow you to convert values from
one data type to another.
 Implicit conversions (widening conversions) are performed
automatically by the compiler when a value of a smaller data
type is assigned to a variable of a larger data type.
 Explicit conversions (narrowing conversions) require a cast
operator ((type)) and may result in loss of data if the value
cannot be represented in the target data type.
Primitive Data Types:
Data Size Description
Type
byte 1 byte Stores whole numbers from -128 to 127

short 2 bytes Stores whole numbers from -32,768 to 32,767

int 4 bytes Stores whole numbers from -2,147,483,648 to 2,147,483,647

long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808


to 9,223,372,036,854,775,807

float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal


digits

double 8 bytes Stores fractional numbers. Sufficient for storing 15 decimal


digits

boolean 1 bit Stores true or false values

char 2 bytes Stores a single character/letter or ASCII values


Operators :
Arithmetic Operators:
 Arithmetic operators are used to perform mathematical
operations on operands.
 They include addition (+), subtraction (-), multiplication (*),
division (/), and modulus (%), which returns the remainder of a
division operation.
 Example: int result = 10 + 5;

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

You might also like