Simploified Basic Java Notes
Simploified Basic Java Notes
JAVA
A computer Program is a set of instructions that performs a specific task.
A programming language is a vocabulary and set of grammatical rules for instructing a computer to
perform specific tasks.
System software.
Application software.
These are the essential software These are the external software
for the system hardware to work. which provides additional
System software's are installed on functionality to user.
the computer when operating Application software's are installed
system is installed. according to user's requirements.
Some examples are operating Some examples are MS Office, web
system (OS), compiler, assembler, browser, media player, games,
interpreter, drivers, etc. facebook etc.
A computer programmer or coder, is a person who creates computer
software.
The term computer programmer can refer to a specialist in one area of
computers, who writes code for many kinds of software.
A web programmer or coder, is a person who creates web applications.
A range of occupations that involve programming are, for example:
software developer, web developer, mobile applications developer,
embedded firmware developer, software engineer, computer scientist,
game programmer, game developer and software analyst.
Computer understands only binary or low level or machine level language
i.e.(o's and 1's
High level languages are also known as Human readable language because
it contains words.
Programming languages are those which use compiler.
Scripting languages are those which use Interpreter.
1|Page
Java_notes_cp
Compiler Interpreter
Importat:
2|Page
Java_notes_cp
5. Games development
3|Page
Java_notes_cp
Functions/Methods
Class hello
Statements
❖ Shortcut:main+ctrl+space
Process Involved
4|Page
Java_notes_cp
F11:Run Program
Ctrl+shift++++:Zoom in
Ctrl+shift---:Zoom out
Variable:
Variables must be initiallised before using in Program. Used to store data . It can
be changed or reduced many times.
Syntax
Datatype Variablename=value;
Data Types in Java
A data type decides the type of data stored by variable.
It also decides how much memory should be allocated to a variable.
byte 1
short 2
int 4
float 4
char 1
double 8
5|Page
Java_notes_cp
Keywords in Java:
A keyword is a reserved word. You cannot use it as a variable name, function
name, constant name, array name etc.
6|Page
Java_notes_cp
Reading in java
After Input Statement you have to Insert a line”import java.util.Scanner;”
In main Function( S must be in capital):
”Scanner Scannername=new Scanner(system.in)”.
example
Int: variablename=scannername.nextInt();
Float: variablename= scannername.nextFloat();
Char: variablename= scannername.next().char At(0);
String: scannername.next();
The Final keyword is used to define constant in JavaProgram,But in C it is Const.
7|Page
Java_notes_cp
Comments in Java
Comments in Java language are the non-executable statements, used to provide information
about lines of code. It is widely used for documenting code.
Step 1: We need to import Scanner class from java.util package. (before class declaration)
import java.util.Scanner;
8|Page
Java_notes_cp
Operators
9|Page
Java_notes_cp
Pre-Increment&Decrement:
10 | P a g e
Java_notes_cp
Post-Increment&Decrement:
11 | P a g e
Java_notes_cp
12 | P a g e
Java_notes_cp
13 | P a g e
Java_notes_cp
14 | P a g e
Java_notes_cp
Control Statements
If Statements:
If else Statements:
To Find Vowel/consonants
15 | P a g e
Java_notes_cp
To Find odd/Even
To Find LeapYear
16 | P a g e
Java_notes_cp
Using Condition
To get Pass/Fail
17 | P a g e
Java_notes_cp
To Find Distinction
To get Pass/Fail
18 | P a g e
Java_notes_cp
19 | P a g e
Java_notes_cp
If else if Statements:
20 | P a g e
Java_notes_cp
21 | P a g e
Java_notes_cp
22 | P a g e
Java_notes_cp
23 | P a g e
Java_notes_cp
The break statement in switch case is not must. It is optional. If there is no break
statement found in the case, all the cases will be executed present after the
matched case.
If the value doesn't matches with any of the cases, then the statements
corresponding to default case will be executed
24 | P a g e
Java_notes_cp
25 | P a g e
Java_notes_cp
Looping Statements
A looping statement allows us to execute a statement or group of statements
multiple times.
while, do While and for loop repeatedly executes a statement or group of
statements as long as a given condition is true.
There are 2 types:
Pre tested Loop:(condition checks first).
{While loop, For loop} .
Post tested Loop:(condition checks later).
{Do while}.
Using Do While Printing Different Pattren of Numbers
26 | P a g e
Java_notes_cp
27 | P a g e
Java_notes_cp
28 | P a g e
Java_notes_cp
29 | P a g e
Java_notes_cp
Dowhile Loop
30 | P a g e
Java_notes_cp
ForLoop
31 | P a g e
Java_notes_cp
32 | P a g e
Java_notes_cp
C Jumping Statements
break:( used within switch and loops).
The break statement stops the execution of the loop or switch when
it is encountered.
continue: used only within loops.
The continue statement skips the current iteration of the loop and continues
with the next iteration. (or) It takes control to the beginning of the loop.
33 | P a g e
Java_notes_cp
34 | P a g e
Java_notes_cp
35 | P a g e
Java_notes_cp
36 | P a g e
Java_notes_cp
37 | P a g e
Java_notes_cp
38 | P a g e
Java_notes_cp
39 | P a g e
Java_notes_cp
40 | P a g e
Java_notes_cp
41 | P a g e
Java_notes_cp
42 | P a g e
Java_notes_cp
43 | P a g e
Java_notes_cp
44 | P a g e
Java_notes_cp
45 | P a g e
Java_notes_cp
46 | P a g e