0% found this document useful (0 votes)
6 views14 pages

Java & DBMS

Java is a versatile, object-oriented programming language known for its platform independence and wide application in various fields such as web, mobile, and enterprise software. Developed by Sun Microsystems and now owned by Oracle, Java utilizes the Java Virtual Machine (JVM) for executing bytecode, ensuring security and memory management. Key features include its object-oriented nature, robust security, and a large community, making it a popular choice for developers.

Uploaded by

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

Java & DBMS

Java is a versatile, object-oriented programming language known for its platform independence and wide application in various fields such as web, mobile, and enterprise software. Developed by Sun Microsystems and now owned by Oracle, Java utilizes the Java Virtual Machine (JVM) for executing bytecode, ensuring security and memory management. Key features include its object-oriented nature, robust security, and a large community, making it a popular choice for developers.

Uploaded by

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

CH 3: ABOUT JAVA

About Java:- Java programming is a versatile, object-oriented programming language and computing
platform, widely used for building a variety of applications, from web and enterprise software to
mobile apps and more. It's known for its platform independence (write once, run anywhere) thanks to
the Java Virtual Machine (JVM).
History of Java:- Java was developed by James Gosling at Sun Microsystems, and released in May
1995. It was initially designed to be used in consumer electronic devices, but its "write once, run
anywhere" principle made it popular for various applications. Sun Microsystems, where Gosling
worked, was later acquired by Oracle, which now owns Java.
JVM:- JVM stands for Java Virtual Machine. It's a software program that:
Key Functions
1. Loads: Loads Java class files.
2. Verifies: Verifies the code for security and correctness.
3. Executes: Executes Java bytecode.

Benefits
1. Platform independence: JVM allows Java code to run on any device that has a JVM, regardless of
the underlying operating system or architecture.
2. Memory management: JVM manages memory allocation and deallocation.
3. Security: JVM provides a sandboxed environment for Java code.

How it works
1. Compilation: Java code is compiled into bytecode.
2. JVM loading: JVM loads the bytecode.
3. Execution: JVM executes the bytecode.

The JVM is a crucial component of the Java ecosystem, enabling developers to write once and run
anywhere (WORA).
Java is a high-level, object-oriented programming language developed by Sun Microsystems (now
owned by Oracle Corporation). It's known for its:
Java Compiler:- The Java compiler, also known as javac, is a program that:

Key Functions
1. Compiles Java source code: Translates Java source code (.java files) into Java bytecode (.class
files).
2. Checks syntax and semantics: Verifies the correctness of the Java code.

The Java compiler is an essential tool for Java development, allowing you to write, compile, and run
Java programs.
Java Interpreter:-
The Java interpreter, also known as the Java Virtual Machine (JVM), is a program that:

Key Functions
1. Loads and executes bytecode: The JVM loads the compiled Java bytecode (.class files) and
executes it.
2. Provides runtime environment: The JVM provides a runtime environment for Java programs,
managing memory, security, and other resources.

How it works
1. Bytecode loading: The JVM loads the compiled Java bytecode.
2. Verification: The JVM verifies the bytecode for security and correctness.
3. Execution: The JVM executes the bytecode, performing the desired actions.

Benefits
1. Platform independence: The JVM allows Java code to run on any device that has a JVM, regardless
of the underlying operating system or architecture.
2. Dynamic loading: The JVM can dynamically load classes and libraries as needed.

The Java interpreter (JVM) plays a crucial role in the Java ecosystem, enabling developers to write
once and run anywhere (WORA).

Key Features of Java:-


1. Platform independence: Java code can run on any device that has a Java Virtual Machine (JVM).
2. Object-oriented: Java supports encapsulation, inheritance, and polymorphism.
3. Robust security: Java has built-in security features to prevent common programming errors.
4. Large community: Java has a vast and active community of developers.
Common Uses
1. Android app development: Java is widely used for developing Android apps.
2. Web development: Java is used for developing web applications using frameworks like Spring and
Hibernate.
3. Enterprise software: Java is used for developing large-scale enterprise software applications.
4. Desktop applications: Java is used for developing desktop applications, such as IDEs and media
players.

Benefits
1. Easy to learn: Java has a relatively simple syntax and is easy to learn.
2. Versatile: Java can be used for developing a wide range of applications.
3. Large ecosystem: Java has a vast ecosystem of libraries, frameworks, and tools.

Overall, Java is a popular and versatile programming language that's widely used in various industries
and applications.
OOPS, or Object-Oriented Programming System, is a programming paradigm that structures software
around "objects" rather than functions and logic. In Java, OOPS is a fundamental concept that helps
organize code, making it more modular, reusable, and maintainable.
The core idea of OOPS in Java revolves around:
 Classes and Objects:
 Class: A blueprint or template for creating objects. It defines the properties (attributes
or data) and behaviors (methods or functions) that objects of that class will possess.
 Object: An instance of a class. It is a concrete entity that holds specific values for the
properties defined in its class and can perform the actions defined by its methods.
 Method:-In Java, a method is a block of code that performs a specific task and is
defined within a class. It serves as a fundamental building block for organizing and
structuring code, promoting reusability, and improving modularity.
 Four Pillars of OOPS:
 Encapsulation: The bundling of data (attributes) and methods that operate on the
data within a single unit (class). It restricts direct access to some of an object's
components, promoting data security and control through access modifiers.
 Inheritance: A mechanism where one class (child class or subclass) can inherit
properties and methods from another class (parent class or superclass). This promotes
code reusability and establishes an "is-a" relationship between classes.
 Polymorphism: The ability of an object to take on many forms. In Java, this is
achieved through method overloading (same method name with different parameters)
and method overriding (subclass providing a specific implementation for a method
defined in its superclass).
 Abstraction: The process of hiding implementation details and showing only
essential information to the user. This is achieved in Java using abstract classes and
interfaces, focusing on "what" an object does rather than "how" it does it
Java provides four types of access modifiers that control the visibility and accessibility of classes,
methods, and variables:
 public:
 The public modifier grants the broadest access.
 Members declared as public are accessible from any other class, regardless of the
package they belong to.
 private:
 The private modifier provides the most restrictive access.
 Members declared as private are only accessible within the class in which they are
declared. They cannot be accessed from outside the class, even by subclasses or
classes within the same package.
 protected:
 The protected modifier offers a level of access between private and public.
 Members declared as protected are accessible within the same package and by
subclasses, even if those subclasses are in different packages.
 Default (no modifier):
 When no explicit access modifier is specified, the default access level (also known as
package-private) is applied.
 Members with default access are accessible only within the same package. They
cannot be accessed from outside the package

In Java, a variable is a named memory location used to store data values during the
execution of a program. It acts as a container for information that can be accessed,
modified, and referenced throughout the code.

Key characteristics of variables in Java:

Data Storage:

Variables hold specific data values, such as numbers, characters, or text strings.
Data Type:

Every variable in Java must be declared with a specific data type


(e.g., int, String, double). This data type determines the kind of values the variable can store
and the amount of memory allocated for it.

1. Primitive Data Types:


These are the most basic data types in Java and are predefined by the
language. They directly store the value of a variable. There are eight primitive data
types:
 Numeric Types:
o Integers: Used for whole numbers.
 byte: 8-bit signed integer.
 short: 16-bit signed integer.
 int: 32-bit signed integer (most commonly used).
 long: 64-bit signed integer.
o Floating-Point Numbers: Used for numbers with decimal points.
 float: 32-bit single-precision floating-point number.
 double: 64-bit double-precision floating-point number (most commonly used for decimals).
 Character Type:

o char: 16-bit Unicode character.


 Boolean Type:
o boolean: Represents a logical value, either true or false.

2. Non-Primitive (Reference) Data Types:


These data types are not predefined by Java but are created by the programmer
(except for String). They store references (memory addresses) to objects rather
than the actual values.

Classes:

User-defined blueprints for creating objects.



Interfaces:

Blueprints of a class that define a set of methods that a class must implement.


Arrays:

Used to store a fixed-size sequential collection of elements of the same data type.



String:


A sequence of characters, widely used for text manipulation. Although String behaves
somewhat like a primitive type due to its common usage and literal representation, it is
technically a class in Java.

Modifiability:

The value stored within a variable can be changed during the program's execution.

Scope and Lifetime:

Variables have a defined scope (where they can be accessed in the code) and lifetime (how
long they exist in memory), which depend on their declaration location.

Types of Variables in Java:


Local Variables:

Declared within a method, constructor, or block. Their scope is limited to that specific
block, and they are created when the block is entered and destroyed when it's exited.

Instance Variables:


Declared within a class but outside any method or constructor. They belong to an instance
(object) of the class, and each object has its own copy of these variables.



Static (Class) Variables:


Declared within a class using the static keyword. They belong to the class itself, not to any
specific instance, and there is only one copy of a static variable shared among all instances
of the class.


The rules for naming variables in Java, also known as identifiers, are as follows:

Valid Characters:

Variable names can consist of letters (A-Z, a-z), digits (0-9), the underscore character ( _),
and the dollar sign ($).


Starting Character:

A variable name must begin with a letter, an underscore (_), or a dollar sign ($). It cannot
start with a digit.


No Spaces:

Variable names cannot contain spaces.


Case-Sensitive:


Java is case-sensitive, meaning myVariable and myvariable are considered two different
variables.


No Keywords:

Variable names cannot be Java keywords (reserved words like public, static, int, class, etc.).


No Literals:

While not strictly keywords, the literals true, false, and null also cannot be used as variable
names.



Length:


There is no official limit to the length of a variable name, though shorter, descriptive names
are generally preferred for readability.

Conventions (Best Practices):


While not strict rules, these conventions are widely followed for better code
readability and maintainability:

CamelCase:

For variable names consisting of multiple words, use camel case, where the first letter of
the first word is lowercase, and the first letter of subsequent words is capitalized
(e.g., firstName, totalAmount).


Meaningful Names:

Choose names that clearly indicate the purpose or content of the variable.


Avoid Dollar Sign:

While technically allowed, the dollar sign ($) is conventionally avoided in general variable
names and is often reserved for compiler-generated or special-purpose names.



Avoid Underscore for starting:


Conventionally, variable names begin with a letter, not an underscore, unless for specific
internal or system-level variables.

Operators in Java are special symbols that perform specific operations on one, two, or three operands
(variables or values) and then return a result. They are fundamental for manipulating data and
controlling program flow.
Java operators can be categorized into several types:
 Arithmetic Operators:
Used for mathematical calculations.
 + (Addition)
 - (Subtraction)
 * (Multiplication)
 / (Division)
 % (Modulus - remainder after division)
 ++ (Increment)
 -- (Decrement)
 Assignment Operators:
Used to assign values to variables.
 = (Simple assignment)
 +=, -=, *=, /=, %= (Compound assignment operators)
 Relational Operators:
Used to compare two operands and return a boolean result (true or false).
 == (Equal to)
 != (Not equal to)
 > (Greater than)
 < (Less than)
 >= (Greater than or equal to)
 <= (Less than or equal to)
 Logical Operators:
Used to combine or modify boolean expressions.
 && (Logical AND)
 || (Logical OR)
 ! (Logical NOT)
 Bitwise Operators:
Used to perform operations on individual bits of integer operands.
 & (Bitwise AND)
 | (Bitwise OR)
 ^ (Bitwise XOR)
 ~ (Bitwise NOT/One's Complement)
 << (Left Shift)
 >> (Signed Right Shift)
 >>> (Unsigned Right Shift)
 Unary Operators:
Operate on a single operand.
 + (Unary plus)
 - (Unary minus)
 ++ (Increment)
 -- (Decrement)
 ! (Logical NOT)
 ~ (Bitwise NOT)
 Ternary Operator (Conditional Operator):
A shorthand for an if-else statement, taking three operands.
 condition ? value_if_true : value_if_false
 Instance of Operator:
Used to check if an object is an instance of a particular class or interface.
Operators are crucial for controlling the flow of a Java program, performing calculations, making
decisions, and manipulating data. Understanding their types, precedence, and associativity is essential
for effective Java programming.

In Java, public static void main(String[] args) is the entry point of a Java program. Here's what each
part means:

Breakdown
1. public: The method can be accessed from anywhere.
2. static: The method belongs to the class, not an instance.
3. void: The method doesn't return any value.
4. main: The name of the method, which is the entry point.
5. String[] args: An array of strings representing command-line arguments.

Purpose
The main method is called when the Java program starts execution. It's where the program's logic
begins.

Key aspects
1. Entry point: The JVM looks for this method to start executing the program.
2. Command-line arguments: The args array contains any command-line arguments passed to the
program.

Example:

public class HelloWorld {


public static void main(String[] args) {
[Link]("Hello, World!");
}
}
In this example, the main method prints "Hello, World!" to the console when the program is run.

CH 1 :DBMS
DATA & INFORMATION :
 Data is a collection of raw facts which have not been processed to reveal useful information.
 Information is produced by processing data

Database Management Software (DBMS):


A Software used for collection of related data that has been recorded, organized and made available
for searching is called a Database

A database management system is a collection of programs that enables users to create, maintain and
use a database.

Three Problems of Database:


 Data Redundancy
 Data Inconsistency
 Data Integrity

Types of Users of DBMS:


 End Users

 Database Administrator (DBA)

 Application Programmers:

System Analyst: System analyst determines the requirements of the end users and
then develops specifications to meet these requirements.

Advantages of using DBMS:

 Reduction in Redundancy
 Improved Consistency
 Improved Security
 User Friendly

Relational model:

 Row is called a Tuple.


 Column is called an Attribute.
 Table is called as a Relation.
 The data type of values in each column is called the Domain

Relational DBMS (RDBMS):

It is a DBMS which is based on the relational model as


discussed above. This is one of the most commonly used databases. Examples of RDBMS are Oracle,
MySQL, IBM DB2
Type of Key Constraint::

 Candidate Key
 Primary key
 Foreign key

Structured Query Language (SQL)


 SQL is a language that is used to manage data stored in a RDBMS.
 It comprises of a Data Definition Language (DDL) and a Data Manipulation Language (DML)

SQL COMMANDS:
 Create
 Update
 Insert
 Delete
 Select

Aggregate Functions
 COUNT- It counts the numbers of tuples in the result of the query.
 SUM – It finds the sum of all the values for a selected attribute which has numeric data type.
 MAX –It finds the maximum value out of all the values for a selected attribute which has
numeric data type.
 MIN - It finds the minimum value out of all the values for a selected attribute which has numeric
data type.
 AVG – It finds the average value of all the values for a selected attribute which has numeric data

You might also like