0% found this document useful (0 votes)
8 views6 pages

IT (Unit 1)

Bhv

Uploaded by

krishanusarma48
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)
8 views6 pages

IT (Unit 1)

Bhv

Uploaded by

krishanusarma48
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
You are on page 1/ 6

IT ( unit 1 )

14 September 2024 09:31

Arithmetic Operators
They are used to perform simple arithmetic operations on primitive and non-primitive
data types.

* : Multiplication
/ : Division
% : Modulo
+ : Addition
– : Subtraction

Unary Operators

Unary operators need only one operand. They are used to increment,
decrement, or negate a value.
• – : Unary minus, used for negating the values.
• + : Unary plus indicates the positive value (numbers are positive without this,
however). It performs an automatic conversion to int when the type of its
operand is the byte, char, or short. This is called unary numeric promotion.
• ++ : Increment operator, used for incrementing the value by 1. There are two
varieties of increment operators.
• Post-Increment: Value is first used for computing the result and then
incremented.
• Pre-Increment: Value is incremented first, and then the result is computed.
• – – : Decrement operator, used for decrementing the value by 1. There are two
varieties of decrement operators.
• Post-decrement: Value is first used for computing the result and then
decremented.
• Pre-Decrement: The value is decremented first, and then the result is
computed.
• ! : Logical not operator, used for inverting a boolean value.

Assignment Operator

‘=’ Assignment operator is used to assign a value to any variable. It has right-to-left associativity, i.e. value
given on the right-hand side of the operator is assigned to the variable on the left, and therefore right -hand
side value must be declared before using it or should be a constant.
The general format of the assignment operator is:
variable = value;
In many cases, the assignment operator can be combined with other operators to build a shorter version of
the statement called a Compound Statement. For example, instead of a = a+5, we can write a += 5.
• +=, for adding the left operand with the right operand and then assigning it to the variable on the left.
• -=, for subtracting the right operand from the left operand and then assigning it to the variable on the left.
• *=, for multiplying the left operand with the right operand and then assigning it to the variable on the left.
• /=, for dividing the left operand by the right operand and then assigning it to the variable on the left.
• %=, for assigning the modulo of the left operand by the right operand and then assigning it to the variable
on the left.

New Section 6 Page 1


Relational Operators

These operators are used to check for relations like equality, greater than, and less than. They return
boolean results after the comparison and are extensively used in looping statements as well as conditional
if-else statements. The general format is,
variable relation_operator value
Some of the relational operators are-
• ==, Equal to returns true if the left-hand side is equal to the right-hand side.
• !=, Not Equal to returns true if the left-hand side is not equal to the right-hand side.
• <, less than: returns true if the left-hand side is less than the right-hand side.
• <=, less than or equal to returns true if the left-hand side is less than or equal to the right-hand side.
• >, Greater than: returns true if the left-hand side is greater than the right-hand side.
• >=, Greater than or equal to returns true if the left-hand side is greater than or equal to the right-hand
side.

Logical Operators

These operators are used to perform “logical AND” and “logical OR” operations, i.e., a function similar to
AND gate and OR gate in digital electronics. One thing to keep in mind is the second condition is not
evaluated if the first one is false, i.e., it has a short-circuiting effect. Used extensively to test for several
conditions for making a decision. Java also has “Logical NOT”, which returns true when the condition is
false and vice-versa
Conditional operators are:
• &&, Logical AND: returns true when both conditions are true.
• ||, Logical OR: returns true if at least one condition is true.
• !, Logical NOT: returns true when a condition is false and vice-versa

Bitwise Operators

These operators are used to perform the manipulation of individual bits of a number. They can be used with
any of the integer types. They are used when performing update and query operations of the Binary
indexed trees.
• &, Bitwise AND operator: returns bit by bit AND of input values.
• |, Bitwise OR operator: returns bit by bit OR of input values.
• ^, Bitwise XOR operator: returns bit-by-bit XOR of input values.
• ~, Bitwise Complement Operator: This is a unary operator which returns the one’s complement
representation of the input value, i.e., with all bits inverted.

Java ArrayList is a part of the Java collections framework and it is a class of java.util package. It
provides us with dynamic arrays in Java. Though, it may be slower than standard arrays but can be
helpful in programs where lots of manipulation in the array is needed.

The main advantage of ArrayList in Java is, that if we declare an array then we need to
mention the size, but in ArrayList, it is not needed to mention the size of ArrayList.

Important features of ArrayList:

1. Arraylist inherits AbstractList class and implements the List interface


2. Arraylist is initialized by size. However the size changes depending on the collection size .
New Section 6 Page 2
2. Arraylist is initialized by size. However the size changes depending on the collection size .
3. Arraylist allows us to randomly access the list
4. Arraylist cant be used for primitive types ,like int , char etc

Methods in Arraylist

• add(int index, Object element) : insert a specific element at a specific position index in a
list.
• add(Object o) : append specific element to the end of a list.
• addAll(Collection C) : append all the elemnts from a specific collection to the end of the
mentioned list ,in such an order that values are returned by the specified collections
iterator
• addAll(int index, Collection C) : insert all of the elements starting at the specified position
from a specific collection into the mentioned list.

Clear() : remove al elemnts from a list.


Clone() : return a shallow copy of an arraylist in java

contains? (Object o) : returns true if this list contains


the specified element.
isEmpty?() : returns true if list contains no elements.
Size?() : returns the no. of elemnts in the list.

Q. How to Create an ArrayList in Java?

Ans : ArrayList<String> list = new ArrayList<>();

# arralist is different from array in java because arraylist can resize dynamically while a
traditional array has a fixed size. Arraylist also provides useful methods like add(), remove(),
size() etc…

ArrayList LinkedList
This class uses a dynamic array to store the elements in This class uses a doubly linked list to store the
it. . elements in it.
Inefficient memory utilization. Good memory utilization.
It can be one, two or multi-dimensional. It can either be single, double or circular LinkedList.
Insertion operation is slow. Insertion operation is fast.
Deletion operation is not very efficient. Deletion operation is very efficient.
This class works better when the application demands This class works better when the application
storing the data and accessing it. demands manipulation of the stored data.
Data access and storage is very efficient as it stores the Data access and storage is slow in LinkedList.
elements according to the indexes.
It is used to store only similar types of data. It is used to store any types of data.
This is known as static memory allocation. This is known as dynamic memory allocation.

New Section 6 Page 3


# To create an ArrayList, you can use its constructor. There are three primary constructors:

ArrayList(): Constructs an empty list.

ArrayList(Collection<? extends E> c): Constructs a list containing the elements of the
specified collection.

ArrayList(int initialCapacity): Constructs a list with the specified initial capacity.

# java server pages : JavaServer Pages (JSP) is a server-side programming technology


that enables the creation of dynamic, platform-independent
method for building Web-based applications. JSP has its roots
in the Java Servlet technology and was designed as a more
convenient way to create content that has both static and
dynamic components.

<% Java code here %> (its embedded with html)

# working of JSP :

1. Client Request: A client (usually a web browser) sends a request to


the web server for a specific JSP page.

2. Translation and Compilation: The web server translates the JSP file
into a Java servlet. This translation process converts the JSP syntax
and embedded Java code into a servlet class. The servlet class is then
compiled into bytecode that can be executed by the Java Virtual
Machine (JVM).

New Section 6 Page 4


Machine (JVM).

3. Execution: The compiled servlet is loaded into memory and initialized.


When the servlet is executed, it processes the client request by
running the embedded Java code. This code can interact with
databases, call JavaBeans, and perform other server-side operations.

4. Response Generation: The servlet generates an HTML response


based on the logic implemented in the JSP page. This response
includes the dynamic content created by the embedded Java code.

5. Client Response: The generated HTML response is sent back to the


client's browser, which displays the content.

Java API : ( application programming interface )


Its a set of predefined rules and specifications for accessing a web-based
software application or web tool.

MVC Architecture in Java

The Model-View-Controller (MVC) is a well-known design pattern in the


web development field. It is way to organize our code.

The model designs based on the MVC architecture follow MVC design
pattern. The application logic is separated from the user interface while
designing the software using model designs.

The MVC pattern architecture consists of three layers:

Model: It represents the business layer of application. It is an object to carry


the data that can also contain the logic to update controller if data is
changed.

View: It represents the presentation layer of application. It is used to


visualize the data that the model contains.

Controller: It works on both the model and view. It is used to manage the
flow of application, i.e. data flow in the model object and to update the
view whenever data is changed.

Adv and disadv in copy

Java Action tag :

New Section 6 Page 5


The JSP specification provides a standard tag called Action tag used within
JSP code and is used to remove or eliminate Scriptlet code from your JSP
code as JSP Scriptlets are obsolete and are not considered nowadays. There
are many JSP action tags or elements, and each of them has its own uses
and characteristics. Each JSP action tag is implemented to perform some
precise tasks.

jsp:forward: is used for forwarding the request and response to other


resources.

jsp:include: is used for including another resource.

jsp:body: is used for defining dynamically-defined body of XML element.

jsp:useBean: is used for creating or locating bean objects.

jsp:setProperty: is used for setting the value of property in the bean object.

jsp:getProperty: is used for printing the value of the property of the bean.

jsp:element: is used for defining XML elements dynamically.

jsp:plugin: is used for embedding other components (applets)

jsp:param: is used for setting the parameter for (forward or include) value.

jsp:text: is used for writing template text in JSP pages and documents.

jsp:fallback: is used for printing the message if plugins are working.

jsp:attribute: is used for defining attributes of dynamically-defined XML


element.

New Section 6 Page 6

You might also like