Java Batch Class 1 Notes
Java Batch Class 1 Notes
What is a Program?
Sequence of instructions that tells a computer how to perform a task.
-> Computer operates using binary code but we can’t write our code in binary so we
developed concept of language like C++,java,Python etc.Every language has some
grammatical rules .These grammatical rules are known as “SYNTAX”.
What is a compiler?
The compiler converts code written in human reading programming language into
machine code representation which is understood by the processor.
What is a linker?
Once the compilation step is done ,another step is needed to create a working executable
that can be invoked and run, that is, associate the function calls (for example) that your
compiled code needs to invoke in order to work.To link some code in other libraries to
your written code is what a linker does.Basically a linker combines these object code
files into an executable.
What is an Algorithm ?
Self contained step by step set of operations to be performed in order to solve a
problem.
Operations on a variable
Create ,Put some information,Get
Six Basic computer instructions
->Reading/Receiving some information
->Outputting/Printing some information
->Performing arithmetic operations
->Assigning a value to variable
->Conditional Execution (If ,If Else,Else)
-> Repeat a set of actions (Loops)
import java.util.*;
java.util - Contains the collections framework, legacy collection classes, event model,
date and time facilities, internationalization, and miscellaneous utility classes (a string
tokenizer, a random-number generator, and a bit array).
a++ (Post increment) its value is preserved temporarily until the execution of this
statement and it gets updated before the execution of the next statement
}
}
}
}
int a=10;
int b=10;
if(a==b) { // To check if a is equal to b we use “==”
System.out.println(“ARE EQUAL”);
AND (&&) When two statements both are true only then it will give true (Similar To AND
GATE which we studied in class 12)
OR (||)
NOT (!)
If -
if(condition) {
//execute if condition is true
}
IF ELSE
If (condition) {
}
Else {
//If above condition not satisfied
}
IF ELSE IF
if(condition ){
}
else if(condition ){
}
And so on ……
LOOPS
FOR LOOP
WHILE LOOP
initialization expression;
while (test_expression)
{
// statements
update_expression;
}
DO WHILE
initialization expression;
do
{
// statements
update_expression;
} while (test_expression);
SAMPLE PROGRAMS
int p=scn.nextInt();
int r=scn.nextInt();
int t=scn.nextInt();
System.out.println(“SI = ” + ((p*r*t)/100) );
import java.util.scanner;
int a=scn.nextInt();
int d=scn.nextInt();
for(int i=0;i<10;i++){
System.out.println( a+(i*d) );
}
If we chose while loop then
import java.util.scanner;
int a=scn.nextInt();
int d=scn.nextInt();
int i=0;
while(i<10){
System.out.println( a+(i*d) );
i++;
import java.util.scanner;
int a=scn.nextInt();
int b=scn.nextInt();
int c=scn.nextInt();
System.out.println( a + “ is greatest” );
}
else if(b>a && b>c){
System.out.println( b + “ is greatest” );
System.out.println( c + “ is greatest” );
**
***
****
import java.util.scanner;
int n=scn.nextInt();
int nst=1;
for(int i=0;i<n;i++){
for(int cst=1;cst<=nst;cst++){
System.out.print(“*”);
}
System.out.println();
nst++;
5) Pattern 2(for n)
*****
****
***
**
import java.util.scanner;
int n=scn.nextInt();
int nst=n;
int nsp=0;
for(int i=0;i<n;i++){
for(int csp=1;csp<=nsp;csp++){
System.out.print(“ ”); }
for(int cst=1;cst<=nst;cst++){
System.out.print(“*”);
System.out.println();
nst--;
nsp++;
6) Pattern 3(for n)
***
*****
***
import java.util.scanner;
int n=scn.nextInt();
int nst=1;
int nsp=n/2;
for(int i=0;i<n;i++){
for(int csp=1;csp<=nsp;csp++){
System.out.print(“ ”);
for(int cst=1;cst<=nst;cst++){
System.out.print(“*”);
System.out.println();
If(i<n/2){
nst+=2;
nsp--;
else{
nst-=2;
nsp++;