0% found this document useful (0 votes)
153 views6 pages

Java Specialist Technical Assessment

The document contains the answers to 10 technical assessment questions for a candidate named Ahmad Shaukie Bin Mohd Yatim. The questions cover topics like Java programming, regular expressions, SQL queries, and Unix commands. For each question, the candidate provided a detailed code sample or explanation to demonstrate his technical skills and knowledge.

Uploaded by

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

Java Specialist Technical Assessment

The document contains the answers to 10 technical assessment questions for a candidate named Ahmad Shaukie Bin Mohd Yatim. The questions cover topics like Java programming, regular expressions, SQL queries, and Unix commands. For each question, the candidate provided a detailed code sample or explanation to demonstrate his technical skills and knowledge.

Uploaded by

caukiee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Growthops Technical Assessment

Name: Ahmad Shaukie Bin Mohd Yatim


Date: 2/2/2023

1. Write a Java Program to reverse a string without using String inbuilt function

Answer:

import java.util.Scanner;

public class InputExample {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Write something here : ");
String words = input.nextLine();
char[] original = words.toCharArray();
int start = 0;
int end = original.length - 1;
char tempWord;
while(end > start){
tempWord = original[start];
original[start] = original[end];
original[end] = tempWord;
end--;
start++;
}
words = new String(original);
System.out.println("This is reversed words: " + words);
input.close();
}
}
2. Write a regular expression to validate Malaysia NRIC format
NRIC format
● 12 digits number
● 1st 6 digits are the date of birth in YYMMDD format
Sample NRIC: 880512123456

Answer: ^[0-9]{6}[0-9A-Za-z]{6}$

3. Write a java program to extract date of birth from Malaysia NRIC

Answer:

public class nricDobExtractor {


public static void main(String[] args) {
String nric = "970411106211";
String dob = nric.substring(0, 6);
System.out.println("Date of Birth (YYMMDD): " + dob);
}
}
4. Explain what is SQL Injection & how to avoid them in Java coding practice

-SQL Injection is a security vulnerability that can be prevented in Java by using


parameterized queries, which separate user-supplied data from the SQL code to
prevent malicious code from being executed.

5. Explain what are the use case of below unix commands


● ls - list the contents of a directory
● pwd – print the current working directory
● grep – search for a pattern in a file that contains the pattern
● cat – concatenates and displays the contents of the files
● head – displays the first ten lines of a file
● chown – change owner
● chmod – change permission
● cp – file copy
● vi – text editor to create or edit files
● rm – delete file
● ps – show current process
● df – show information about disk usage
● nohup – runs a command in the background
● telnet - connects to a remote machine using the Telnet protocol
● sudo – run commands with superuser privilege

6. Write a query to extract a list of students who have the n-th score rank.
Condition:
a. Output: student’s full name, advisor’s full name & score
b. Business Logic:
■ Same score consider having same rank (e.q.: In below sample 2
students have the same score of 85, they both consider as 1st rank)
■ If nobody have n-th rank the query return null

table_name: student
student_id first_name last_name advisor_id
1 Tanisha Blake 2
2 Jess Goldsmith NULL
3 Tracy Wu 3
4 Alvin Grand 1
5 Felix Zimmermann 2

table_name: grade table_name: advisor


student_id score advisor_id first_name last_name
1 40 1 James Francis
2 60 2 Amy Cheng
3 85 3 Lamar Alexander
35
4 4 Anita Woods
5 85

Answer:

SELECT s.full_name AS "Student Name", a.full_name AS "Advisor Name", s.score


FROM student s
JOIN advisor a ON s.advisor_id = a.id
WHERE (SELECT COUNT(DISTINCT score) FROM student WHERE score >=
s.score) = n
ORDER BY score DESC;

7. What’s the output of the below java program?


class Primary{
public void Print() {
System.out.println("Primary");
}
}

class Secondary extends Primary{


public void Print() {
System.out.println("Secondary");
}
}

class Main{
public static void DoPrint( Primary o ) {
o.Print();
}
public static void main(String[] args) {
Primary x = new Primary();
Primary y = new Secondary();
Secondary z = new Secondary();
DoPrint(x);
DoPrint(y);
DoPrint(z);
}
}

Answer:
PrimarySecondarySecondary

8. What’s the output of the below java program?


public class Main {
public static void main(String[] args) {
Grandkid c = new Grandkid ();
c.Print();
}
}

class Parent {
public void Print() {
System.out.println("Parent's Print()");
}
}

class Son extends Parent {


public void Print() {
System.out.println("Son Print()");
}
}

class Grandkid extends Son {


public void Print() {
super.Print();
System.out.println("Grandkid's Print()");
}
}

Answer:
Son Print()
Grandkid's Print()
9. What’s the output of the below java program?

class Main {
public static void main(String[] args) {
Secondary b = new Secondary();
b.show();
}
}

class Primary{
final public void show() {
System.out.println("Primary::show() called");
}
}

class Secondary extends Primary {


public void show() {
System.out.println("Secondary::show() called");
}
}

Answer: error

10. What’s the output of the below java program?


class Main {
public static void main(String args[]) {
try {
throw 10;
}
catch(int e) {
System.out.println("Got the Exception " + e);
}
}
}

Answer: error

You might also like