SCE/CE9001/CM101/Tutorial 1
Tutorial 1
Chapter 1, Introduction to Computers, Programs, and
Java
1. What is a keyword? List some Java keywords.
!s"
#eserved words or keywords are words that have a s$e%i&i% mea!i!' to the %om$iler a!d
%a!!ot (e used &or other $ur$oses i! the $ro'ram.
a(stra%t %o!ti!ue &or !ew
assert
)))
de&ault 'oto
)
$a%ka'e
(oolea! do i& $rivate
(reak dou(le im$leme!ts $rote%ted
(yte else im$ort $u(li%
%ase e!um
))))
i!sta!%eo& retur!
%at%h e*te!ds i!t short
%har &i!al i!ter&a%e stati%
%lass &i!ally lo!' stri%t&$
))
%o!st
)
&loat !ative su$er
+. ,s Java %ase se!sitive? What is the %ase &or Java keywords?
!s" Java is %ase se!sitive.
Java keywords are lower-%ase.
.. What is the stateme!t to dis$lay a stri!' o! the %o!sole?
Ans:[Link]();
/. What is the out$ut o& the &ollowi!' %ode"
public class Test {
public static void main(String[] args) {
[Link](!."#$%&'&." is );
[Link](!."#$%&'&.");
(
(
!s"
1
SCE/CE9001/CM101/Tutorial 1
0. Ca! Java ru! o! a!y ma%hi!e? What is !eeded to ru! Java o! a %om$uter?
!s" 1o.
J2M.
3. What is a %omme!t? ,s the %omme!t i'!ored (y the %om$iler? 4ow do you de!ote a
%omme!t li!e a!d a %omme!t $ara'ra$h?
Ans: A commnet documents what the program is and how it is constructed.
Comments help programmers to communicate and understand the program.
They are not programming statemnets and thus are ignored by the compiler.
(1) Line comment
// single line comment
(2) Block/paragraph comment
/* multiple line comment
This is the irst comment
This is the second comment
*/
/* also can be single line */
5. ,& a 1oClass6e&7ou!dError o%%urs whe! you ru! a $ro'ram8 what is the %ause o& the
error?
Ans: !hen a wrong class name is typed.
9. ,& a 1oSu%hMethodError o%%urs whe! you ru! a $ro'ram8 what is the %ause o& the
error?
Ans: !hen a wrong method name is typed.
9. ,& your $ro'ram !eeds to read i!te'ers8 (ut the user e!tered stri!'s8 a! error would
o%%ur whe! ru!!i!' this $ro'ram. What ki!d o& error is this?
!s" #u! time error.
+
SCE/CE9001/CM101/Tutorial 1
10. ,de!ti&y a!d &i* the errors i! the &ollowi!' %ode"
public class )elcome {
public static void main(String[] args) {
[Link](*)elcome to +ava,);
(
(
Ans: public class )elcome {
public static void main(String[] args) {
[Link](-)elcome to +ava,.);
(
(
11. The &ollowi!' $ro'ram is wro!'. #eorder the li!es so that the $ro'ram dis$lay
mor!i!' &ollowed (y a&ter!oo!."
public static void main(String[] args) {
(
public class )elcome {
[Link](a/ternoon);
[Link](morning);
(
Ans:
.