Created
August 20, 2020 09:49
-
-
Save melwinlobo18/a43fec055bf878a266767eea350ec5a2 to your computer and use it in GitHub Desktop.
Java Training
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sap.training.abs; | |
public class ConcreteClass extends AbstractClass{ | |
@Override | |
public void printName() { | |
System.out.println("printName: Concrete class"); | |
} | |
} | |
abstract class AbstractClass { | |
private String name; | |
public abstract void printName(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sap.training; | |
public class Basic_1 { | |
public static void main(String[] args) { | |
System.out.println("Hello"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sap.training; // package | |
public class Basic_2 { | |
public static String appName = "my basic app"; // class variable | |
/** | |
* this is a multi-line comment | |
*/ | |
public static void main(String[] args) { | |
Integer a = 10; | |
// this is a line comment | |
int calc = calc(a); | |
System.out.println(calc); | |
stringManipulations(); | |
} | |
public static int calc(int a) { | |
return ++a; | |
} | |
public static void stringManipulations() { | |
String message = "hello world"; | |
System.out.println(message.length()); | |
System.out.println(message.substring(1, 3)); | |
String[] s = message.split(" "); | |
for (String temp : s) { | |
System.out.println(temp); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sap.training; | |
public class BasicArray { | |
public static void main(String[] args) { | |
int[] scores; | |
char[] letters, symbols; | |
String[] countries; | |
scores = new int[3]; | |
scores[0] = 11; | |
scores[1] = 21; | |
scores[2] = 31; | |
sumScores(scores); | |
} | |
static void sumScores(int[] n){ | |
int sum = 0; | |
for (int i:n){ | |
sum += i; | |
} | |
System.out.println(sum); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sap.training; | |
public class Car { | |
private long price; | |
private int years; | |
public Car(long price, int years) { | |
this.price = price; | |
this.years = years; | |
} | |
public long getPrice() { | |
return price; | |
} | |
public int getYears() { | |
return years; | |
} | |
public void setPrice(long price) { | |
this.price = price; | |
} | |
public void setYears(int years) { | |
this.years = years; | |
} | |
@Override | |
public String toString() { | |
return "Car{" + | |
"price=" + price + | |
", years=" + years + | |
'}'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sap.training; | |
public class CarApp { | |
public static void main(String[] args) { | |
Car car = new Car(12000, 1); | |
System.out.println("Car age: " + car.getYears() + "\nCar price: " + car.getPrice()); | |
final int value = 10; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sap.training.fnl; | |
public class Car extends ParentOfFinalClassDemo{ | |
private final Engine engine = new Engine(); | |
public static void main(String[] args) { | |
} | |
} | |
final class Engine { | |
int property = 10; | |
public int getProperty() { | |
return property; | |
} | |
public void setProperty(int property) { | |
this.property = property; | |
} | |
} | |
class ParentOfFinalClassDemo { | |
public void printSomething() { | |
System.out.println("Hello world"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sap.training.Inheritance; | |
public class Bike extends Vehicle{ | |
private Stand stand; | |
public Stand getStand() { | |
return stand; | |
} | |
public void setStand(Stand stand) { | |
this.stand = stand; | |
} | |
public static void main(String[] args) { | |
Stand stand = new Stand(); | |
new Bike().sound(); | |
} | |
@Override | |
public void sound() { | |
super.sound(); | |
System.out.println("Bike making sound"); | |
} | |
} | |
class Stand { | |
@Override | |
public String toString() { | |
return "This is a generic stand"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sap.training.Inheritance; | |
public class Bus { | |
int doors; | |
public int getDoors() { | |
return doors; | |
} | |
public void setDoors(int doors) { | |
this.doors = doors; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sap.training.Inheritance; | |
public class Vehicle { | |
private long speed; | |
private long mileage; | |
private long wheels; | |
public void setSpeed(long speed) { | |
this.speed = speed; | |
} | |
public void setMileage(long mileage) { | |
this.mileage = mileage; | |
} | |
public void setWheels(long wheels) { | |
this.wheels = wheels; | |
} | |
public long getSpeed() { | |
return speed; | |
} | |
public long getMileage() { | |
return mileage; | |
} | |
public long getWheels() { | |
return wheels; | |
} | |
public void sound() { | |
System.out.println("Vehicle making sound"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sap.training; | |
public class Practice_Enum { | |
enum level { | |
low, medium, high; | |
@Override | |
public String toString() { | |
return super.toString() + " Override"; | |
} | |
level() { | |
System.out.println("Called: " + toString()); | |
} | |
} | |
public static void main(String[] args) { | |
level val = level.high; | |
System.out.println(val); | |
level[] newArr = level.values(); | |
for (level temp:newArr) { | |
System.out.println(temp); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment