jfs
jfs
On
JAVA FULL STACK
SubmiGed
in partial fulfilment for the award of the degree
Of
Bachelor of
Technology in
Computer Science and Engineering
By
NAME : K LIKITHA
CERTIFICATE
• Introduction to web
• Introduction to Java
• Java Language Fundamentals
• OOP implementation
• Packages
• Arrays
• Exception handling
• Working with String
Introduction to Java:
• Java is a popular programming language, created in 1995.
• It is owned by Oracle, and more than 3 billion devices run Java.
• Java works on different platforms (Windows, Mac, Linux, Raspberry
Pi, etc.).
• It is easy to learn and simple to use.
• It is used for:
Syntax:
public class Main{
public static void main(String[] args){
System.out.println(“Hello World”);
}
}
• The name of the java file must match the class name. When saving
the file, save it using the class name and add ".java" to the end of the
filename.
• Inside the main() method, we can use the println() method to print a
line of text to the screen.
IDENTIFIERS:
• To create a variable, you must specify the type and assign it a value.
Data Types:
• Data types are divided into two groups:
Example:
int myInt = 9;
double myDouble = myInt;
Example:
double myDouble = 9.78d; int
myInt = (int) myDouble;
Operators:
• Operators are used to perform operations on variables and values.
✓ Arithmetic operators
✓ Assignment operators
✓ Comparison operators
✓ Logical operators
✓ Bitwise operators
• Arithmetic Operators:
6
• Assignment Operators:
Operator Example Equivalent to
= a = b; a = b;
+= a += b; a = a + b;
-= a -= b; a = a - b;
*= a *= b; a = a * b;
/= a /= b; a = a / b;
%= a %= b; a = a % b;
• Relational Operators:
Operator Description Example
== Is Equal To 3 == 5 returns
false
• Logical Operators:
Operator Example Meaning
• Unary Operators:
Operator Meaning
Conditional Statements:
• Java has the following conditional statements:
Syntax:
if (condition) {
// block of code to be executed if the condition is true
}
Syntax:
if (condition) {
// block of code to be executed if the condition is true
} else {
// block of code to be executed if the condition is false
}
if (condition1) {
// block of code to be executed if condition1 is true
} else if (condition2) {
// block of code to be executed if the condition1 is false
and condition2 is true
} else {
// block of code to be executed if the condition1 is false and
condition2 is false
Syntax:
switch(expression) {
case x:
// code
block break;
case y:
// code
block break;
default:
// code block
}
✓ The switch expression is evaluated once.
Loops:
• Loops can execute a block of code as long as a specified condition
is reached.
• Loops are handy because they save time, reduce errors, and they
make code more readable.
While Loop:
The while loop loops through a block of code as long as a specified
condition is true.
Syntax:
while (condition) {
// code block to be executed
}
Do/While Loop:
// Outputs Volvo
Multidimensional Arrays:
• A multidimensional array is an array of arrays.
• Multidimensional arrays are useful when you want to store data as
a tabular form, like a table with rows and columns.
Methods:
• A method is a block of code which only runs when it is called.
• You can pass data, known as parameters, into a method.
• Methods are used to perform certain actions, and they are also
known as functions.
• Why use methods? To reuse code: define the code once, and use
it many times.
• A method must be declared within a class. It is defined with the name
of the method, followed by parentheses ( ).
Example:
public class Main {
static void myMethod() {
// code to be executed
}}
✓ myMethod() is the name of the method.
✓ static means that the method belongs to the Main class and not
an object of the Main class. You will learn more about objects and
how to access methods through objects.
✓ void means that this method does not have a return value.
When one object acquires all the properties and behaviors of a parent object, it is
known as inheritance. It provides code reusability. It is used to achieve
runtime polymorphism.
Polymorphism:
If one task is performed in different ways, it is known as polymorphism. For
example: to convince the customer differently, to draw something, for
example, shape, triangle, rectangle, etc.
In Java, we use method overloading and method overriding to achieve
polymorphism.
Another example can be to speak something; for example, a cat speaks meow, dog
barks woof, etc.
Abstraction in Java
Abstraction is a process of hiding the implementation details and showing
only functionality to the user.
Another way, it shows only essential things to the user and hides the internal
details, for example, sending SMS where you type the text and send the
message. You don't know the internal processing about the message delivery.
Abstraction lets you focus on what the object does instead of how it does it.
Ways to achieve Abstraction
There are two ways to achieve abstraction in java
1. Abstract class (0 to 100%)
2. Interface
(100%) Abstract class
in Java
A class which is declared as abstract is known as an abstract class. It can
have abstract and non-abstract methods. It needs to be extended and its
method implemented. It cannot be instantiated.
• An abstract class must be declared with an abstract keyword.
• It can have abstract and non-abstract methods.
• It cannot be instantiated.
• It can have constructors and static methods also.
•It can have final methods which will force the subclass not to change
the body of the method.
Example: abstract
class Bike{
abstract void run();
}
class Honda4 extends Bike{
void run(){System.out.println("running
safely..");} public static void main(String args[]){
Bike obj = new
Syntax:
interface <interface_name>{
The classes that directly inherit the Throwable class except RuntimeException
and Error are known as checked exceptions. For example, IOException,
SQLException, etc. Checked exceptions are checked at compile-time.
Java provides five keywords that are used to handle the exception.
• The "try" keyword is used to specify a block where we should place an
exception code. It means we can't use try block alone. The try block
must be followed by either catch or finally.
• The “catch” block is used to handle the exception. It must be
preceded by try block which means we can’t use catch block alone.
• The "finally" block is used to execute the necessary code of
the program. It is executed whether an exception is handled or
not.
• The “throw” keyword is used to throw an exception.
• The "throws" keyword is used to declare exceptions. It specifies that
there may occur an exception in the method. It doesn't throw an
exception. It is always used with method signature.
Example:
public class
}catch(ArithmeticException e){System.out.println(e);
}
System.out.println("rest of the code...");
}}
Multithreading in Java:
Multithreading in Java is a process of executing multiple threads
simultaneously.
A thread is a lightweight sub-process, the smallest unit of processing.
Multiprocessing and multithreading, both are used to achieve multitasking.
However, we use multithreading than multiprocessing because threads use a
shared memory area. They don't allocate separate memory area so saves
memory, and context-switching between the threads takes less time than
process.
Java Multithreading is mostly used in games, animation, etc.
Queries
Retrieve data from a database using the SELECT statement. The basic
query operations in a relational system are projection, restriction, and
join. The SELECT statement implements all of these operations.
A projection is a subset of the columns in a table. A restriction (also
called selection) is a subset of the rows in a table, based on some conditions.
For example, the following SELECT statement retrieves the names and prices
of all products that cost more than $15:
unit_price FROM
product
sales_order_items WHERE
sales_order_items.quantity > 12
The product table and the sales_order_items table are joined together
based on the foreign key relationships between them.