Computer
Computer
The Greek word quality which means many and morph which means
change of forms. It is the ability of an object to take on many forms.
Polymorphism is a feature of being able to allot a different meaning to
a variable, a method or an object so they can have more than one
form. Thus it is the ability to use in operator method in different ways.
Token is an atomic part of a Java program that has a meaning for the
compiler and is used to execute the program efficiently. There are
various types of token. Pachas, keywords, identifiers, literals,
operators, and punctuators.
Keywords are reserved words that are predefined in the Java
compiler for a specific purpose.
Identifiers are the names given to different components of a Java
programme, like class variables and methods. It can be a
combination of letters and numbers, or a secret sequence of
letters. Keywords cannot be used as identifiers.
literals are the values that can be stored in the variables.
Operators are Special symbols that signifies the compiler to
perform some specific mathematical or non mathematical
operations or one or more operator.
Separator The special characters used to separate the variable or
characters in a Java program.
Punctuators are special characters in Java. Uses punctuation sign.
Implicit type conversion takes place when two types are compatible or
the larger type is larger than the source type. It is ascending order.
The implicit data type is automatically done by the Java compiler in
implicit data conversion. The resulting data types are not specified and
are chosen by the compiler. It is a process of widening. This is also
known as Coercion.
Types of operators
Arithmetic operators, (+, -, /, *, ++, --, %) (unary plus and unary
minus)
relation operators, (<, >, <=, >=, ==, !=)
logical operators ( &&, ||, !)
assignment operators (-=, +=, *=, /=, =, %=)
Ternary operators (condition) ? (print if true) : (print if false)
Miscellaneous operators (dot operator and new operator)
Input in Java
Package collection of Java classes and other packages having similar
functionality
Errors in Java
Syntax error: The errors that occurred due to violation of syntax,
role of the Java programming language are called syntax error.
Syntax errors are known as compile time errors.
Logical error, : Sometimes there may be errors in the logic of the
program due to which the program will not give the appropriate
output. This type of error is a logical error. Logical errors are also
called semantic error.
Runtime error: Runtime errors are occurred due to the execution
of a successfully compiled program.
Comments in Java
Comments are non-executive statements used to explain the code
such as why the variable has been used. What is the purpose of the
function et cetera? Can also be used to hide the code from the
compiler without deleting it. Commented statements are ignored by
the compiler comments are the programmer, debug any error easily.
Three types of comments.
Single line comments : these comments are used to write one
line. It starts with //
Multiline comments: these comments have to write more than
one line so that the logic of the court can be explained in details.
It begins with a ‘/*’ and end with ‘*/’
Documentation comments: these comments are used to write the
documentation part of the program, which is the question about
the program, the name of the programmer, et cetera. At the
beginning of the program, they did not depict the program logic.
It starts with ass for work /** and ends with */.
Ja statements in Java
Statement is used to exit from the loop. As soon as the break
statement in a loop execute the execution will be transferred to the
next statement immediately outside the loop. This means a statement
after the break statement in the loop body will not be executed. The
break statement can be applied to all the different types of loop
Continue statement is used to control the loop by sending the control
of to the next iteration when it is executed, the current flow stops and
skipping the remaining go to the next iteration
class object
Classes in Java are non primitive data types that act is a blueprint for
creating objects of the same type in other words they are a set of
instructions to build the specific type of object and object of a class is
also called an instance and the process of feating in object is called
instantiation
Access specifiers
The private access specifier restricts accessibility of data members and
member methods within a class only this means that the data
members and member methods are preceded by access specifier
private can be accessed only within the class which they are declared
in the same package
public access specifier allows the data members and member methods
to be accessed within the class and also outside the class in the same
package.
Instance variables are also known as non static data members these
variables are declared within the class but outside the member
methods they are created whenever an object is generated the
instance variables associated with different objects contain different
values/
class variable a class variable is also under the state static data
member it is a variable that is declared within the class using a static
keyword only one copy is created for all the objects of the class thus
having single value of the variable for all the objects.
member methods
a method that is declared within the class is known as a member
method it can be declared private or public.
constructors are special methods with the name which is same as that
of the class name they're also called automatically when the object is
created they used to initialize the instance of a class.
Header of method.
When a method is declared, the first line is known as method header or
method prototype or function prototype. This line contains the access
specifier, return type, method name, and list of parameters.
Method signature.
Method signature is the part of a method header containing only the
name of the method along with the parameter list.
Return type: If the function is returning a value, then the data type of
the value is written before the function name. The different data types
used to return type are byte, short int, long, float, double, car or
boolean. We can also use string if you want to return a word or
sentence. Other than these, all non primitive data types such as. Adi
class Xtra can be used to return type. If a function is not returning any
value then the keyword void is used.
Method name.
Every method should be provided with a names that it can be called
from the same class or different classes. Method name should be a
valid identifier. The method name should be meaningful and related to
the task done by it.
Constructors.
Special type of member method with the same name of the class.
It doesn't have a return type, not even void.
Used to initialise the instance variables of the class and the
object of the class.
Constructor of a class is called every time an object of a class is
created.
Constructors are always public as they can be called from outside
the class while creating the object of the class.
There are 3 types of constructor. Default constructor, parameterised
constructor, non parameterised constructor.
Constructor. Method.
Used to initialise the instance Used to execute the Java code
variables of a class. which performs a specific job.
Can be evoked only once, at the It can be evoked anytime as and
time of creating the object. when required.
It has the same name as that of It has a different name from the
the class. class name.
It does not have a return type, It has a return diet.
not even void.
It is always public. It may or may not be public.
Library classes.
Java.lang - Used for string manipulations.
Java.io - Used for input output operations.
Java.util - Use for input through Scanner class.
Java.math - News for mathematical operations.
* allows you to import all the characters from the Java packages when
used.
Primitive and composite data types.
Wrapper classes are the inbuilt classes that contain primitive data
types. These classes are used to convert primitive data types into
objects and vice versa with the help of their methods.
Every wrapper class has various methods too, providing a way to use
the primitive data types as objects.
All the wrapper classes are part of the Java Lang package in the Java
library.
Need for Wrapper class.
To allow primitive data types to convert from one data type to
another.
To store primitive data types objects.
Function Purpose
Integer.parseInt(String) It converts a string into integer
Integer.valueOf(String) form and stores it in integer
variable.
Long.parseInt(String) It converts a string into long type
Long.valueOf(String) data and stores it in a long
variable.
Float.parseInt(String) It converts string into float data
Float.valueOf(String) type and stores it in a Float
variable.
Double.parseInt(String) It converts string in 2 double data
Double.valueOf(String) type and stores it in a double
variable.
Function Description
Character.IsLetter It checks whether a character is a
letter or not. In returns true for
the given character.
Character.isDigit It checks whether a character is a
digit or not. In returns true for the
given character.
Character.isLetterOrDigit It takes whether a character is a
digit or letter. It returns true for
the given characters if it is a
character or a digit.
Character.isWhiteSpace Checks if a character is a white
space or not. It returns true if it
stores a white space. If turns
false if it return, it does not store
a white space.
Character.isUpperCase Check if character given is
uppercase or not.
Character.isLowerCase Check if a character given is
lower case or not.
Character.toUpperCase Converts the given character to
uppercase.
Character.toLowerCase Converts the given character to
lower case.
String handling
1. length()
2. charAt()
3. indexOf()
4. lastIndexOf()
5. toLowerCase()
6. toUpperCase()
7. concat()
8. substring()
9. replace()
10. equals()
11. equalsIgnoreCase()
12. compareTo()
13. compareToIgnoreCase()
14. startsWith()
15. endsWith()
16. trim()
17. valueOf()
Array handling