Java and Perl Programming Concepts Quiz

Test your knowledge of Java programming concepts including interfaces, collections, and error handling, along with Perl programming language features including regular expressions, arrays, and object-oriented programming.

14 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What will be the value of $size after executing the following code?my @a = (0, 1, 2);$#a = 0;my $size = @a;

  1. undef
  2. 0
  3. 1
  4. 2
Question 2 Multiple Choice (Single Answer)

What elements will the @a array consist of? $_ = ' a b c '; my @a = split();

  1. ', 'a', ' ', 'b', ' ', 'c', ' '
  2. ', 'a', 'b', 'c', ''
  3. undef, 'a', 'b', 'c', undef
  4. 'a', 'b', 'c'
Question 3 Multiple Choice (Single Answer)

package A; sub NEW { bless {}, shift } sub AUTOLOAD { print ref(shift) } package main; my $obj = NEW A; $obj->foo();

  1. A
  2. AA
  3. Can't locate object method "foo" via package "A"
  4. none of the above
Question 4 Multiple Choice (Single Answer)

my $a = '123'; my $b = '0123'; if ($a == $b) { print "same"; } else { print "different"; }

  1. same
  2. different
  3. the code is ill-formed
  4. none of the above
Question 5 Multiple Choice (Single Answer)

In Perl, a/n ________ is a special character or a sequence that will define the number of times the previous character or sequence appears.

  1. character class
  2. metacharacter
  3. assertion
  4. quantifier
Question 6 Multiple Choice (Single Answer)

In Perl, 'stat' returns a thirteen element array with which of the following values?

  1. Last access
  2. Inode number
  3. Both of the above
  4. Perl Version ID
Question 7 Multiple Choice (Single Answer)

Which of the following is the correct way of sorting an array of integers in ascending order?

  1. sort @a
  2. sort {$1 <=> $2} @a
  3. sort {$a <=> $b} @a
  4. sort {$_[0] <=> $_[1]} @a
Question 8 Multiple Choice (Single Answer)

What gets printed? my @a = ([1, 2, 3, 4], [5, 6, 7, 8]); print join(' ', @{$a[1]}[1..3]);

  1. 1 2 3
  2. 2 3 4
  3. 5 6 7
  4. 6 7 8
Question 9 True/False

All three ways of calling new() are equivalent in the code below package A; sub new { my ($class, $param) = @_; return bless {param => $param}, $class; } package main; my $a1 = A->new('foo'); my $a2 = new A('foo'); my $a3 = A::new('A', 'foo');

  1. True
  2. False
Question 10 Multiple Choice (Single Answer)

Which regular expression deletes all tags specified as text enclosed by "<" and ">" from a document stored in a string, but deletes nothing else?

  1. $string =~ s/<*&>//g;
  2. $string =~ s/<\s*>//g;
  3. $string =~ s/<.*?>//g;
  4. $string =~ s/<.*>//g;
Question 11 Multiple Choice (Single Answer)

sorted map is

  1. interface
  2. class
  3. Object
  4. None of these
Question 12 Multiple Choice (Single Answer)

SortedSet can implement

  1. set
  2. ConcurrentSkipListSet
  3. Hashmap
  4. Queue
Question 13 Multiple Choice (Single Answer)

RandomAccess interface is found in

  1. java.io
  2. java.util
  3. javax.xml.stream
  4. java.io.*
Question 14 Multiple Choice (Single Answer)

Compile time error can

  1. Handle with try catch block
  2. Handle with Throwable class
  3. Both of above true
  4. None of above