Sdet 1
Sdet 1
Sdet 1
1/2/2023 – Day 1
1)To print Hello World:
package com.basicSamples;
}
}
2) Calculator
package com.basicSamples;
public class Calculator {
int number; //Instance Variable
static int c; // Static Variable
public void add(int a, int b){
int sum; // Local Variable
sum=a+b;
System.out.println(sum);
}
public static void main(String[] args) {
Calculator cobj=new Calculator();
cobj.add(10,25);
cobj.number=10;
c=15;
}
}
3) Data Types:
package com.basicSamples;
//char
char letter='a';
System.out.println(letter);
//string
String str1="Java Programming";
System.out.println(str1);
String str2="programiz";
System.out.println(str2);
//binary
int binaryNumber=0b10010;
System.out.println(binaryNumber);
//octal
int octalNumber=027;
System.out.println(octalNumber);
//decimal
int decNumber=34;
System.out.println(decNumber);
//hexadecimal
int hexNumber=0x2F;
System.out.println(hexNumber);
//Byte range
byte range;
range=124;
System.out.println(range);
//short type
short temperature;
temperature=-200;
System.out.println(temperature);
int irange=-4250000;
System.out.println(irange);
//long
long lrange=-4324569780000L;
System.out.println(lrange);
}
}
4) Operators
package com.basicSamples;
//addition operator
System.out.println("a+b = "+(a+b));
//subtraction operator
System.out.println("a-b = "+(a-b));
//multiplication operator
System.out.println("a*b = "+(a*b));
//division operator
System.out.println("a/b = "+(a/b));
//modulo operator
System.out.println("a%b = "+(a%b));
//create variables
int ac=4;
int var;
}
}
2/2/2023 – Day 2
5) Relational Operator
package com.basicSamples;
int a = 7, b = 11;
// value of a and b
System.out.println("a is " + a + " and b is " + b);
// == operator
System.out.println(a == b);
// != operator
System.out.println(a != b);
// > operator
System.out.println(a > b);
// < operator
System.out.println(a < b);
// >= operator
System.out.println(a >= b);
// <= operator
System.out.println(a <= b);
// && operator
System.out.println((5 > 3) && (8 > 5));
System.out.println((5 > 3) && (8 < 5));
// || operator
System.out.println((5 < 3) || (8 > 5));
//System.out.println((5 > 3) || (8 < 5));
System.out.println((5 < 3) || (8 < 5));
// ! operator
System.out.println(!(5 == 3));
System.out.println(!(5 > 3));
}
}
6)Unary Operator
package com.basicSamples;
}
7)Ternary Operators
package com.basicSamples;
8)ConsoleInSample
package com.basicSamples;
import java.util.Scanner;
//float
System.out.println("Enter a foalt");
float f=sc.nextFloat();
System.out.println("Entered num " + f);
//double
System.out.println("Enter a double: ");
double d=sc.nextDouble();
System.out.println("Entered num: " + d);
//String
System.out.println("Enter a string: ");
String s =sc.next();
System.out.println("Entered string : "+s);
//long
System.out.println("Enter a long: ");
Long l =sc.nextLong();
System.out.println("Entered long : "+l);
sc.close();
}
}
9) Kid Class
package com.ClassesAndObjects;
import com.ClassesAndObjects.Kid;
}
EncapsulateKid
package com.ClassesAndObjects;
public class EncapsulatedKid {
private String getName() {
return name;
}
public void setName(String name) {
//this.name = name;
this.name = (name.length()==0)?"No name": name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age=(age>1 && age<13)? age: 2;
}
3/3/2023-Day 3
1) Method Overloading
package com.ClassesAndObjects;
2) Final Keyword
package com.basicSamples;
public class Calculator {
final double pi=3.14;
public void area(double radius) {
//pi=5.23;
double area=pi*radius*radius;
System.out.println("Area is "+ area);
}
3) String
package com.ClassesAndObjects;
public class StringSample {
//create a strings
String type="Java Programming";
String first="Java is a Object oriented Programming ";
String second=" Python";
String third=" Language";
//print strings
System.out.println(first);
System.out.println(second);
System.out.println(third);
String example="Hello";
example = example.concat("Welcome");
}
}