[Go to site: main page, start]

0% found this document useful (0 votes)
5 views5 pages

Java Notes

The document outlines key concepts of Java programming, including encapsulation, abstraction, polymorphism, inheritance, and modularity. It explains the roles of compilers and interpreters, the significance of source code and byte code, and the types of Java applications. Additionally, it covers data types, identifiers, tokens, errors, and comments in Java programming.

Uploaded by

Tanvi Fulfagar
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)
5 views5 pages

Java Notes

The document outlines key concepts of Java programming, including encapsulation, abstraction, polymorphism, inheritance, and modularity. It explains the roles of compilers and interpreters, the significance of source code and byte code, and the types of Java applications. Additionally, it covers data types, identifiers, tokens, errors, and comments in Java programming.

Uploaded by

Tanvi Fulfagar
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

1.

Encapsulation – When data and functions are wrapped within a unit called class, it is known
as encapsulation.
2. Abstraction – When the complex coding is hidden from user’s visibility but works in the
background when the user works on it is called data abstraction
3. Polymorphism – When there are multiple functions within the same scope with the same
name, but differ by the structure is called polymorphism. Function overloading, Function
Overriding.
4. Inheritance – The virtue by which the properties of a class is derived into another class, it is
called inheritance.
The class from which the properties are derived is called the base class or the super class the
class to which the properties are derived is called the derived class or the sub class.
5. Modularity – When a bigger program is divided into smaller modules in order to complete
the program faster and error free is called modularity. At the end all the smaller modules are
integrated to get the final result and the software

Java is object-oriented programming language. It is platform independent language. It is case


sensitive language. It’s a highly secured language.

What is a compiler?

It is an in - built program that is used to check all types of syntactical errors in the program. It
compiles the entire program all at a time and displays the errors. On successful compiling, the
compiler converts the source code to byte code. It is a light weight programming language.

What is an interpreter?

An interpreter is a program that interprets or converts one language to another. In Java, it interprets
the byte code to machine code and checks for any kind of technical errors one statement at a time.

Compiler Interpreter

It checks for syntactical errors and converts the Interpreter converts the byte code to
program to byte code all at a time. machine code and checks for logical errors
considering one statement at a time.

It creates a .class file It creates a .obj file

What is a source code?

The code that is written by the programmer in general English following the programming syntax is
called the source code. The source is saved in a .java file

Byte code

It is an intermediate code which consists of 1s and 0s. This file is created after the source code is
successfully compiled by the compiler. This source code is saved in a .class file.
Machine code

This a low-level language which is created by the interpreter on successful execution of the program.
This code is generated from the byte code. This code is understandable to the computer.

Why is Java a platform independent language?

In java, the source code is converted to byte code by the compiler after all the syntactical errors are
removed. This intermediate byte code is generated by the compiler is universal for all platforms. This
byte code is further converted to machine code, by Java’s own interpreter which makes Java a
platform independent language.

Source
Sourcecode
Code Compiler Byte Code Interpreter Machine Code

There are 2 types of java programing


1) Stand alone or desktop application – These kinds of program execute on a particular machine in
which the program is installed. These programs can be used only if it is installed in your device

2) Web application applet programing – In this kind of programing the program is executed using a
web browser. In this kind of program need not to be installed in your computer.

What are data types?

These are the different types of values that are supported by java. There are 2 types of major
categories of data types.
1) Primitive data type – These are some in built data types which occupy a fixed size of memory and
can store only 1 type of value at a time.

Data Type Size Default Value Range of Value


boolean 1 bit false true or false
char 2 bytes ‘\u0000’ Any single character
byte 1 byte 0 -27 to 27 -1
short 2 bytes 0 -215 to 215 -1
int 4 bytes 0 -231 to 231-1
long 8 bytes 0L -263 to 263-1
float 4 bytes 0.0f 3.4E-38 to 3.4E+38
double 8 bytes 0.0D 1.7E-308 to 1.7E+308

2) Reference Data Type – These data types do not have a fixed size in the memory and are formed
using the primitive data types. These data types can store multiple types of values at the same time.
Example- Class, Array, Interface, etc.
The rules for naming an identifier

1) No keywords can be used


2) It cannot have any special characters other than $ and _
3) It cannot start with any digits

Write a program to accept the length and breadth of a rectangle and find its area and perimeter.

WAP to accept the principal, rate and time and find the SI

WAP to accept 3 sides of a triangle and find its perimeter. (Sum of all sides)

WAP to accept the 3 numbers and find their average (Sum by 3)

What do you mean by public static main void?

Public – It is an access specifier that allows the main function to be accessed from outside the
class. If the main function is declared private or protected, the main function will not execute.

Static – Since there should be only one main function in the program, therefore the main
function is declared static.

Void – Since the main function does not return any value therefore its written type is void.

Main – since it is the main function of the program, it is declared main. The program always
starts executing from the main function.

WAP to accept 2 numbers and find the value of the expression, a 2 + b2 /2ab

WAP to accept a distance in meters and convert it to kilometers and meters

WAP to accept two numbers and interchange their values.

What are tokens?

Tokens are smallest individual units that are used to develop a program. There are 5 types of
tokens
1) Keywords – These are the reserved words in Java which have a special meaning to the
compiler. These words cannot be used for naming an identifier. Example – Void, class, public,
static, etc.

2) Identifiers – These are the named memory locations used to store a value. Example – int a =
10. Here a is an identifier. Class abc – abc is an identifier, it is the name of the class.

3) Literals – these are the fixed values in the program which never get changed throughout the
course of the program. These values are declared using the final keyword. Example – Final,
double p = 3.14. Here the value of p will never get changed throughout the course of the
program.

4) Separators – the symbols that are used to demarcate several sections of a program are called
separators. Example – {}, ; , .
5) Operators – These are the symbols that are used for different types of calculations. There are
different types of operators. Like:

1) Arithmetic operators – these types of operators are used for mathematical calculations.
Examples - +, -, *, /, %.

2) Logical Operators – These operators are used when multiple conditions are used in a program
at a time in order to perform a task. Example - ||, && and !

3) Relational Operators – These operators are used for comparing values. >,>=,<,<=,==,!=

4) Bitwise Operators – These operators work on binary values. Example –

WAP to accept two numbers and find the value of the following expression – a3 + b3 + 3ab (a+b)

WAP to accept the value in Celsius and convert it into Fahrenheit.

WAP to accept the value in seconds and convert it to hour minutes and seconds.

WAP to accept the value of a radius of a circle and find its area and perimeter.

ERRORS

What are errors?


Errors are the mistakes that are done while writing a program. There are 3 types of errors:

1) Syntax errors – these types of error occur when there are mistakes in writing a program. It
maybe a wrong syntax or maybe misspelled keywords. These types of errors are checked at
the time of compilation. If the program has any type of syntactical errors, the program
doesn’t compile.
2) Logical errors – in these types of errors, the programs execute successfully and gives a wrong
output due to use of wrong logic in the program. Example – Wrong formulae used or wrong
conditions applied etc. The program in this case does not stop executing.
3) Run time error – in this kind of error the execution of the program terminates abruptly.
These errors occur at the time of execution of the program due to an occurrence of an
abnormal condition. Example – Division by 0, Index out of Bound.
COMMENTS

What are comments?


These are the non – executable statements in a program. These statements are used in a
program to explain what the statements are doing. There are 3 types of comments:

1) Single line comments (//) - these are the comments that are written in only one line.
2) Multi line Comments (/*…*/) – these are used when comments exchange over more than
one line.
3) Documentation (/**……*/) – these are used at the beginning of the program to describe
what the program will actually do.

WAP to accept the three sides of a scalene triangle and find its area using hero’s formula.
√𝑠(𝑠 − 𝑎)(𝑠 − 𝑏)(𝑠 − 𝑐) where s = a + b + c /2

WAP to accept the principal, rate and time and find the CI and Amount

WAP to accept the coordinates of 2 points and find the distance between them.
Let point 1 be (x1, y1) and point 2 be (x2, y2). Distance between them is
√(𝑥2 − 𝑥1)2 + (𝑦2 − 𝑦1)2 .

[Link] (a, b), this means ab


[Link] (n), this means √𝑛

WAP to accept a two-digit number and the sum of the digits.


WAP to accept the values of a quadratic equation and find its roots using the formula,
-b+-√𝑏2 − 4𝑎𝑐 / 2a

WAP to accept the length of a pendulum and find the time period using the formula,
2π√𝑙/𝑔

You might also like