0% found this document useful (0 votes)
48 views7 pages

Java Code Examples and Outputs

Uploaded by

Medha Adepu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views7 pages

Java Code Examples and Outputs

Uploaded by

Medha Adepu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Vehicle PDF

q1

package testing1;

import [Link];
import [Link];
import [Link];

/******************************************************************************

Online Java Compiler.


Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/

class Trainee{
int traineeId;
String traineeName;
Trainee(int cId, String name) {
[Link] = cId;
[Link] = name;
}
public int getTraineeId() {
return traineeId;
}
public void setTraineeId(int traineeId) {
[Link] = traineeId;
}
public String getTraineeName() {
return traineeName;
}
public void setTraineeName(String traineeName) {
[Link] = traineeName;
}
}

public class Tester


{
public static void main(String[] args) {
List<Trainee> list = new ArrayList<Trainee>();
Trainee c1 = new Trainee(110, "Patrick");
Trainee c2 = new Trainee(112, "Chandler");
Trainee c3 = new Trainee(113, "Darbie");
Trainee c4 = new Trainee(115, "Kelly");
[Link](c1);
[Link](c2);
[Link](c3);
[Link](c4);
if([Link](c3)){
[Link](1, [Link](3));
}
Stream<Trainee> stream = [Link]().filter(trainee ->
[Link]().length() > 5);
[Link]((trainee) -> [Link]([Link]() + "
"));
}
}

---------------------
output
110 113
---------------------

q2

package testing2;

import [Link];

public class Tester {


public static void main(String[] args) {
LocalTime newTimeObj = [Link](9, 45, 59);

int hour = [Link]();


int second = [Link]();
int minute = [Link]();
[Link](hour+":"+second+":"+minute);
}
}

---------------------
output
[Link]
---------------------

q3

package demo_test;

public class Validator {


public static boolean isValidCustomerName(String customerName) {
String regex = "([A-Z][a-z]+)(\\s[A-Z][a-z]+)*";
if([Link](regex))
return true;
return false;
}
}

package demo_test;

import static [Link].*;

import [Link];
import [Link];

public class TestDemoClass {

// @Test
// public void validateCustomerNameValidTest1() {
// [Link]([Link]("Aabel james"));
// }
// @Test
// public void validateCustomerNameValidTest2() {
// [Link]([Link]("Aabel james"),
true);
// }
// @Test
// public void validateCustomerNameValidTest3() {
// [Link]([Link]("Aabel james"));
// }
// @Test
// public void validateCustomerNameValidTest4() {
// [Link]([Link]("Aabel james"),
false);
// }
}

---------------------
output
3 and 4 pass testcases
---------------------

q4

package testing4;

import [Link];
import [Link];

public class CollectionsTest {


public static void main(String[] args) {
List<String> numList = new ArrayList<>();
int listSize = [Link]();
listSize += 10;
[Link]("Java");
for(int i = 1; i < listSize; i++) {
[Link]([Link](i - 1) + "-Java");
[Link](++i, "Java");
}
[Link](2);
[Link]("Element at 3rd position: " + [Link](2));
[Link]("Size: " + [Link]());
}
}

---------------------
output
Element at 3rd position: Java-Java
Size: 10
---------------------

q5

package testing5;

import [Link];
import [Link];

public class Tester {


public static void main(String[] args) {
Map map = new TreeMap();
[Link]("Spirng", 10);
[Link]("Java", 20);
[Link]("spring", 20);
[Link]("Java", 50);

[Link](map);

}
}

---------------------
output
{Java=50, Spirng=10, spring=20}
---------------------

q6
user DTO and API
---------------------
output
~
---------------------

=====================================================

Associate PDF

q1

package demo1;

import [Link];
import [Link];

public class CollectionsTest {


public static void main(String[] args) {
List<String> numList = new ArrayList<>();
int listSize = [Link]();
listSize += 10;
[Link]("Java");
for(int i = 1; i < listSize; i++) {
[Link]([Link](i - 1) + "-Java");
[Link](++i, "Java");
}
[Link](2);
[Link]("Element at 3rd position: " + [Link](2));
[Link]("Size: " + [Link]());
}
}

---------------------
output
Element at 3rd position: Java-Java
Size: 10
---------------------

q2

package demo2;
import [Link];

public class Tester {


public static void main(String[] args) {
LocalTime newTimeObj = [Link](9, 45, 59);

int hour = [Link]();


int second = [Link]();
int minute = [Link]();
[Link](hour+":"+second+":"+minute);
}
}

---------------------
output
[Link]
---------------------

q3

package demo3;

import [Link];
import [Link];

public class MapTester {


public static void main(String[] args) {
Map<Integer, String> songMap = new TreeMap<Integer, String>();
[Link](101, "Blowing in the Wind");
[Link](102, "Stand By Me");
[Link](null, "Annie's Song");
[Link](104, "Here I Am");
for([Link]<Integer, String> ele: [Link]()) {
[Link]([Link]()+"- "+[Link]());
}
}
}

---------------------
output
[Link]
---------------------

q4

package demo4;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

class Transaction{
public Integer TransactionId;
public Transaction(Integer transactionId, Double transactionAmount,
LocalDateTime time) {
super();
TransactionId = transactionId;
[Link] = transactionAmount;
}
public Integer getTransactionId() {
return TransactionId;
}
public void setTransactionId(Integer transactionId) {
TransactionId = transactionId;
}
public Double getTransactionAmount() {
return transactionAmount;
}
public void setTransactionAmount(Double transactionAmount) {
[Link] = transactionAmount;
}
private Double transactionAmount;
}

public class TransactionApp {


public static void main(String[] args) {
List<Transaction> transactions = new ArrayList<>();
Transaction transaction1 = new Transaction(1001, 2500.00,
[Link](2019, 7, 20, 13, 55));
Transaction transaction2 = new Transaction(1002, 1700.00,
[Link](2019, 12, 10, 10, 22));
Transaction transaction3 = new Transaction(1003, 28000.00,
[Link](2020, 7, 28, 19, 28));
Transaction transaction4 = new Transaction(1004, 1925.00,
[Link](2019, 1, 5, 11, 16));
Transaction transaction5 = new Transaction(1005, 1206.00,
[Link](2020, 5, 15, 19, 36));
[Link](transaction1);
[Link](transaction2);
[Link](transaction3);
[Link](transaction4);
[Link](transaction5);
Stream<Double> stream1 = [Link]().map(t ->
[Link]()*2);
Stream<Double> stream2 = [Link](t -> t > 4000);
Stream<Double> stream3 = [Link]();
List<Double> amountList = [Link]([Link]());
[Link](amountList);

}
}

---------------------
output
[Link]
---------------------

q5
validatePassword()

---------------------
output
~
---------------------

You might also like