Question

Do I need "import java." to use built in method? "import java.io, import java.lang"

Do I need "import java." to use built in method? "import java.io, import java.lang"
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Let's see from scratch when we code in c we need to include or say import stdio that is standard input and output. When we talk of java the case is same but at times we can say we don't need to import java.io to write simple programs as we write in compiler which include them by itself but when we code in notepad we need to import every single packages we are using. Let's see an example

public class LangTest {
   public static void main(String args[]) {
      int num = 100;
      double result = Math.sqrt(num);
      System.out.println("Square root of the number: "+result);
   }
}

Output

Square root of the number: 10.0

If you observe the above example here we haven’t imported the lang package explicitly but, still, we are able to calculate the square root of a number using the sqrt() method of the java.lang.Math class.

When we code in notepad we need to import every single package but when we code in online compilers or specific editors of java we don't need to add built in packages like java.io or so!!!

Add a comment
Know the answer?
Add Answer to:
Do I need "import java." to use built in method? "import java.io, import java.lang"
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help writing the following java Java Method below. I just need a method to...

    I need help writing the following java Java Method below. I just need a method to take a user inputted First or Last Name and return the associated phone number, thank you! import java.util.*; import java.io.*; class PhoneList { public static void main(String[] args) throws Exception { boolean loop = true; File file = new File("PhoneList_Data.txt"); FileWriter fw = new FileWriter(file, true); fw.write("PhoneList Data"); fw.write("\n" + "Last, First: 6041337567, 2181731566");    // do { } (loop)    fw.close(); } //...

  • My client java a simple client program java .net import java.io*i public class MyClient (public static...

    My client java a simple client program java .net import java.io*i public class MyClient (public static void main(String args() thrown IO Exception (part I: initialize rocket and stream BufferedReader inFromUser - new BufferedReader(new inputStreamReader(System in)); Socket clientSocket - new Socket(___. ___); DataOutputStream oldToServer - new DataOutputStream(clientSocket.getOutputStrea, ())); part 2: interact with server

  • I need help running this code. import java.util.*; import java.io.*; public class wordcount2 {     public...

    I need help running this code. import java.util.*; import java.io.*; public class wordcount2 {     public static void main(String[] args) {         if (args.length !=1) {             System.out.println(                                "Usage: java wordcount2 fullfilename");             System.exit(1);         }                 String filename = args[0];               // Create a tree map to hold words as key and count as value         Map<String, Integer> treeMap = new TreeMap<String, Integer>();                 try {             @SuppressWarnings("resource")             Scanner input = new Scanner(new File(filename));...

  • Please write where its written write your code here!! please use java for the code! please...

    Please write where its written write your code here!! please use java for the code! please use the given code and I will rate thanks Magic index in an array a[1..n] is defined to be an index such that a[ i ] = i. Given an array of integers, write a recursive method to find the first magic index from left to right. If one exists in the given array, return the index number i, otherwise return -1. Here are...

  • /* * CPS150_Lab10.java */ import java.io.*; import java.util.*; /** * CPS 150, Fall 2018 semester *...

    /* * CPS150_Lab10.java */ import java.io.*; import java.util.*; /** * CPS 150, Fall 2018 semester * * Section N1 * * Lab Project 13: Comparing Java Strings * * @author *** Replace with your name *** */ public class CPS150_Lab13 { static final Scanner KBD = new Scanner(System.in); static final PrintStream OUT = System.out; // TO DO: Implement each of the following 4 methods, // using the String compareTo method: /* * lessThan(String, String) -> boolean * * method is...

  • package week_3; import java.util.Scanner; import java.util.*; //import java.lang.*; //import java.io.*; /** Write a program that can...

    package week_3; import java.util.Scanner; import java.util.*; //import java.lang.*; //import java.io.*; /** Write a program that can help decide if a particular programming project is best solved using a Waterfall or Agile methodology. Your program should ask the user: • How many programmers will be on the team [ More than 30 programmers -> Waterfall ] • If there needs to be firm deadlines and a fixed schedule [ Yes - > Waterfall ] • If the programmers have experience in...

  • Java Any help is appreciated 8.What is the output of the following program? import java.io.*; public...

    Java Any help is appreciated 8.What is the output of the following program? import java.io.*; public class Q8 { public static void main (String [] args)throws IOException { RandomAccessFile file = new RandomAccessFile (new File ("Q8.txt"), "rw"); double x = 100.00 ; file.writeDouble(x); file.writeDouble(x+10); file.writeDouble(x+20); file.seek(8); System.out.println(file.readDouble()); System.out.println(file.getFilePointer()); } } -------------------------------------------- Output 110.00 16 My Question: why is this the output?   

  • This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static...

    This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static void main(String args[]) throws IOException { Scanner inFile = new Scanner(new File(args[0])); Scanner keyboard = new Scanner(System.in);    TwoDArray array = new TwoDArray(inFile); inFile.close(); int numRows = array.getNumRows(); int numCols = array.getNumCols(); int choice;    do { System.out.println(); System.out.println("\t1. Find the number of rows in the 2D array"); System.out.println("\t2. Find the number of columns in the 2D array"); System.out.println("\t3. Find the sum of elements...

  • I need to use the verify method I have built in the Employee class and check...

    I need to use the verify method I have built in the Employee class and check if the salary falls in the range. If not I shouldn't store it in the array. I have tried various ways but it still gets stored in the array... here is my employee class: https://pastebin.com/iLzTuWe4 here is my test class: https://pastebin.com/Z33Q6h8E

  • Java. May only use import java.util.*; and import java.io*; packages. Write a program called WeatherReporter that...

    Java. May only use import java.util.*; and import java.io*; packages. Write a program called WeatherReporter that prompts the user for an input file name. reads the given file, which is in the format of CharlotteWeather2010.txt, line by line and uses the processLine() method as defined below:
 public static void processLine (String line){
 
 }
 to output to the console the data for each day formatted as shown below:
 01/01/2010 Low: 34.0 High: 48.0 Rain: no Snow: no 01/02/2010 Low: 24.1 High:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT