Question

1-what do static, private and public modifiers do to methods and fields in java ? 2-difference...

1-what do static, private and public modifiers do to methods and fields in java ?

2-difference between data streams and filtering streams?

3-when should an exception be thrown or catched?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

If a method or field is marked as private, then only code inside the same class can access the variable, or call the method. The Java access modifier public means that all code can access the class, field, constructor or method, regardless of where the accessing code is located.

Static access modifier links a method or field to the class rather than object of the class, which means that the static methods or fields belongs to the class and are common for all the objects.

2) Data streaming is a feature used to stream through a Collector along which you can do complex operations like filtering, etc.

3) If method can't handle the exception properly, it should be thrown. We generally throw an exception when we want to notify the caller of the method of some failures.

Add a comment
Know the answer?
Add Answer to:
1-what do static, private and public modifiers do to methods and fields in java ? 2-difference...
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
  • JAVA - Please describe these access modifiers in less than 2 sentences    public    private...

    JAVA - Please describe these access modifiers in less than 2 sentences    public    private    protected    default

  • a]using appropriate programming examples differentiate between cohesion and coupling[10marks] b]Write a java program that requests a...

    a]using appropriate programming examples differentiate between cohesion and coupling[10marks] b]Write a java program that requests a user to input 2 numbers then find the sum,difference and product of the inputed numbers [15marks] c]Public,Private,Protected ,static and final are access modifiers ,outline their individual effects when prepended to methods[15marks] d]Discuss the importance of the Exception class including examples of specific execeptions[10marks]

  • 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

  • (TCO 1) The JVM executes a Java application by (Points : 6)        executing the public static...

    (TCO 1) The JVM executes a Java application by (Points : 6)        executing the public static main method of the class.        creating an object of the class and executing that object’s main method.        executing the class constructor.        compiling the Java code into byte code. (TCO 1) Which method call converts the value in variable stringVariable to a double? (Points : 6)        Double.parseDouble( stringVariable );        Convert.toDouble( stringVariable );        Convert.parseDouble( stringVariable );        Float.parseFloat( stringVariable ); (TCO 1) Which of the following can...

  • For Java please.Artwork. javaimport java.util.Scanner;public class ArtworkLabel {public static void main(String[] args)...

     Given main(). define the Artist class (in file Artist java) with constructors to initialize an artist's information, get methods, and a printlnfo() method. The default constructor should initialize the artist's name to "None' and the years of birth and death to 0. printinfo() should display Artist Name, born XXXX if the year of death is -1 or Artist Name (XXXX-YYYY) otherwise. Define the Artwork class (in file Artwork.java) with constructors to initialize an artwork's information, get methods, and a printinfo() method. The constructor should...

  • Static methods can be called directly from the name of the class that contains the method. Static methods are usually created to do utility operations. For example: public class Test{ public static i...

    Static methods can be called directly from the name of the class that contains the method. Static methods are usually created to do utility operations. For example: public class Test{ public static int timesTwo(int value){ return value * value; } } public class TestDriver{ public static void main(String[] args){ int var = Test.timesTwo(5);   System.out.println(var); } } For your final exercise, create a class called ManyLinkedLists. It will contain a static method called createLinkedList(). That method takes an argument that is...

  • Java - Object Oriented Programming Declare a class named Customer that has two private fields? Write...

    Java - Object Oriented Programming Declare a class named Customer that has two private fields? Write a set method to make sure that if age > 125 years or less than 0 then it is set to 0 (default value) What does it indicate when declaring a class's instance variables with private access modifier? What is the role of a constructor? The data part of by an object's instance variables is known as? Do all methods have to always return...

  • Please help me do the java project For this project you will be reading in a...

    Please help me do the java project For this project you will be reading in a text file and evaluating it in order to create a new file that represents the Class that will represent the properties of the text file. For example, consider the following text file: students.txt ID              Name                              Age                    IsMale           GPA 1                Tom Ryan                       22                       True              3.1 2                Jack Peterson                31                       True              2.7 3                Cindy LuWho                12                       False             3.9 When you read in the header line, you...

  • Define subclasses of InvalidTimeException InvalidHourException and InvalidMinuteException Public static methods: checkHour(String hh), checkMinute(String mm) Test ≥...

    Define subclasses of InvalidTimeException InvalidHourException and InvalidMinuteException Public static methods: checkHour(String hh), checkMinute(String mm) Test ≥ 2 strings; if invalid, throw an appropriate exception java

  • JAVA // TO DO: add your implementation and JavaDoc public class SmartArray<T>{    private static final...

    JAVA // TO DO: add your implementation and JavaDoc public class SmartArray<T>{    private static final int DEFAULT_CAPACITY = 2;   //default initial capacity / minimum capacity    private T[] data;   //underlying array    // ADD MORE PRIVATE MEMBERS HERE IF NEEDED!       @SuppressWarnings("unchecked")    public SmartArray(){        //constructor        //initial capacity of the array should be DEFAULT_CAPACITY    }    @SuppressWarnings("unchecked")    public SmartArray(int initialCapacity){        // constructor        // set the initial capacity of...

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
ADVERTISEMENT