




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Operating system ppts...including process management and scheduling
Typology: Lecture notes
1 / 8
This page cannot be seen from the preview
Don't miss anything!





public class f1 { public static void main(String args[]) { System. out .println("vijay"); } }
import java.util.Scanner; public class scanner_input { public static void main(String args[]) { Scanner sc= new Scanner(System. in ); System. out .println("Enter your rollno"); int rollno=sc.nextInt(); System. out .println("Enter your name"); String name=sc.next(); System. out .println("Enter your fee"); double fee=sc.nextDouble(); System. out .println("Rollno:"+rollno+" name:"+name+" fee:"+fee); sc.close(); } } StringBuffer Input public class stringbuffer_input { public static void main(String args[]) { StringBuffer sb= new StringBuffer("Hello "); sb.insert(1,"Java");//now original string is changed System. out .println(sb);//prints HJavaello } }
import java.io.*;
public class BufferedReaderExp{ public static void main(String args[]) throws Exception{ InputStreamReader r= new InputStreamReader(System.in); BufferedReader br= new BufferedReader(r); String name=""; while (!name.equals("stop")){ System.out.println("Enter data: "); name=br.readLine(); System.out.println("data is: "+name); } br.close(); r.close(); } }
//Java Variable Example: Add Two Numbers class variable { public static void main(String[] args) { int a=20; int b=20; int c=a+b; System. out .println(c); } } //Java Variable Example: Widening class variable { public static void main(String[] args){ int a=20; float f=a; System.out.println(a); System.out.println(f); } } //Java Variable Example: Narrowing (Typecasting) class variable { public static void main(String[] args){ float f=20.5f;
//Unary Operator Example: ~ and! class operator{ public static void main(String args[]){ int a=10; int b=-10; boolean c=true; boolean d=false; System.out.println(~a);//- 11 (minus of total positive value which starts from 0) System.out.println(~b);//9 (positive of total minus, positive starts from 0) System.out.println(!c);//false (opposite of boolean value) System.out.println(!d);//true }} //Arithmetic Operator Example class operator{ public static void main(String args[]){ int a=10; int b=5; System.out.println(a+b);// System.out.println(a-b);// System.out.println(ab);// System.out.println(a/b);// System.out.println(a%b);// }} // Arithmetic Operator Example: Expression class operator { public static void main(String args[]){ System.out.println(1010/5+3-14/2); }} // Left Shift Operator //The Java left shift operator << is used to shift all of the bits in a value to the left side of a specified number of times. class operator { public static void main(String args[]){ System.out.println(10<<2);//102^2=104= System.out.println(10<<3);//102^3=108= System.out.println(20<<2);//202^2=204= System.out.println(15<<4);//152^4=15*16= }} // Right Shift Operator //The Java right shift operator >> is used to move left operands value to right by the number of bits specified by the right operand. class operator { public static void main(String args[]){ System.out.println(10>>2);//10/2^2=10/4= System.out.println(20>>2);//20/2^2=20/4= System.out.println(20>>3);//20/2^3=20/8=
// Shift Operator Example: >> vs >>> class operator { public static void main(String args[]){ //For positive number, >> and >>> works same System.out.println(20>>2); System.out.println(20>>>2); //For negative number, >>> changes parity bit (MSB) to 0 System.out.println(-20>>2); System.out.println(-20>>>2); }} //AND Operator Example: Logical && vs Bitwise & class operator { public static void main(String args[]){ int a=10; int b=5; int c=20; System.out.println(a<b&&a++<c);//false && true = false System.out.println(a);//10 because second condition is not checked System.out.println(a<b&a++<c);//false && true = false System.out.println(a);//11 because second condition is checked }} //OR Operator Example: Logical || and Bitwise | class operator { public static void main(String args[]){ int a=10; int b=5; int c=20; System.out.println(a>b||a<c);//true || true = true System.out.println(a>b|a<c);//true | true = true //|| vs | System.out.println(a>b||a++<c);//true || true = true System.out.println(a);//10 because second condition is not checked System.out.println(a>b|a++<c);//true | true = true System.out.println(a);//11 because second condition is checked }} // Ternary Operator Example class operator { public static void main(String args[]){ int a=2; int b=5; int min=(a<b)?a:b; System.out.println(min); }} // Assignment Operator Example
Switch-case public class switchcase { public static void main(String[] args) { int number=20; //int number=30; //int number=40; switch (number){ case 10: System. out .println("100"); break ; case 20: System. out .println("200"); break ; case 30: System. out .println("300"); break ; default : System. out .println("Not in Found"); } } } Do-while loop public class dowhileloop { public static void main(String[] args) { do { System. out .println("infinitive do while loop"); } while ( true ); } } While loop public class whileloop { public static void main(String[] args) { int i=1; while (i<=10){ System. out .println(i); i++; } } } For loop
public class forloop { public static void main(String[] args) { int arr[]={10,23,35,56,98}; for ( int i:arr){ System. out .println(i); } } } Break keyword public class break_key { public static void main(String[] args) { for ( int i=1;i<=3;i++) { for ( int j=1;j<=3;j++) { if (i==2&&j==2) { break ; } System. out .println(i+" "+j); } } } } Continue keyword public class continue_key { public static void main(String[] args) { for ( int i=1;i<=10;i++) { if (i==5) { continue ; } System. out .println(i); } } }