File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Missing import statment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Missing import statment" Watch "Missing import statment" New topic
Author

Missing import statment

garima jain
Ranch Hand

Joined: Sep 22, 2008
Posts: 60
Source: Whizlabs


What is the result of compiling and running this code assuming that the file bb.txt does not exist.
I thought the answer to this question would be Compilation error as import statement is missing and there is no numbering given on the left hand side. However, Whizlabs does not say this.
Please suggest. Thanks.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9319
    
  17

The real exam codes will always have line numbers. And if the line numbers don't start with 1, then you don't have to worry about import statements...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
garima jain
Ranch Hand

Joined: Sep 22, 2008
Posts: 60
thanks Ankit
Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
if i wont find import statement or line-1

then can i put answer as compilation fails...?


SCJP5 and SCWCD1.5
Think Twice Act Wise...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9319
    
  17

If the line numbers are not beginning from 1, then you can assume that all the required import statements are there. But if the line numbers start from 1, then you cannot assume that there are required import statements. So if the line number start from 5, and there is use of File class, then you can assume that there is an import java.io.*; statement on the lines not shown. But if the line numbers start from 1, and there is no import java.io.* or java.io.File, and the code uses the File class, then it would be a compilation error...
Pandey Gautam
Greenhorn

Joined: Nov 05, 2008
Posts: 14
Hi Ankit,
I read somewhere that import.lang is implicit import for any java file.
Is it correct?


SCJP6
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9319
    
  17

yes. You can use classes in java.lang package without importing any package. Like the Object and System classes are in the java.lang package along with the wrapper classes, String class and a lot of other classes which you can use directly...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Missing import statment