Question

3 public class stringbufferEx lic static void main (String arga[1 stringbufferex stringbutterEestringbutfertx atringaufterix.proceed ) private void proceed ingBuffer stringBuffer new stringBuffer Initial value) System.out.printinistring, format (.8-35s ?s- .with inital value: ,, stringBuffer) r.setLength(o) //Setting the lenght to zero (0), which wil1 also rintin (String.format (-358tAfter setting the lenght to zero clear the contents of the stringBuffer System out stringBuffer.append (New value) system.out.printin(string.format (-35s , stringBuffer)) with new value: stringbutfer))
media%2F4eb%2F4eba163c-f0cf-4402-822c-3a
media%2F199%2F199d6cef-2296-4960-bf04-b1Please explain what each one does and why we use it in operating systems
0 0
Add a comment Improve this question Transcribed image text
Answer #1


In the First Program StringBufferEx we are using String.Format method to format the String. String.format uses the syntax similar to c and C++ like %-35s and %s. So in this program first we are initialising the string buffer with content inital value. So String buffer holds "initial value". then with the line


System.out.println(String.format("%-35s %s", "with intial value: ", stringBuffer));


with above line we are priniting the content of String Buffer but by formatting it by using String.format


"%-35s"    says that left shift the string and total length must be 35 and then %s prints the content of string buffer


So it prints like


first string "with initial value: " then some spaces and total length with string and space must be 35


so it prints "with intial value:                 "                 its lenght must be 35

then from %s content of the string buffer gets prints so finally it prints


"with intial value:                  initial value"

stringBuffer.setLength(0)   sets the length of stringBuffer to Zero

So System.out.println(String.format("%-35s %s", "After setting the length to Zero: ", stringBuffer)); prints
After setting the length to Zero:  

stringBuffer.append("New Value")           appneds the string to the String buffer

System.out.println(String.format("%-35s %s", "with new value: ", stringBuffer));    prints
"with new value:                     New Value"


Program2:

Map map = new HashMap(collection.size());

From above line you are creating a hashMap of initial size equal to collection and with default load factor 0.75.

for(Object obj : collection){
map.put(obj.key, obj.value);
}

you are putting the collection obj in the map with key as obj.key and value as obj.value
as you have created the map with the size equal to collection but as soon as map is full till its deafaul load factor i.e. 75 percent of its size
it doubles the size of the hashmap.

Map map = new HashMap(1 + (int) (collection.size()/0.75))
creating the map with intial size as 1 + (int) (collection.size()/0.75)


Program3:

In the Third Program there is Student class which implements Serializable that means we can serialize its object
In Student Class there are two private members rollNum, studentName
Among these studentName is transient variable

There is class DoNotSerialize we are serializing Student object using Serialize() method
We are creating Student object with rollNum =1 and studentName="Hoffen"
we are writing this object to student.ser file as studentName is transient variable so it can not be serialized
so after serialize() method there will student class seralized object but in that object only rollnum will be serialized not the studentName

Add a comment
Know the answer?
Add Answer to:
Please explain what each one does and why we use it in operating systems 3 public...
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. What is the output of this code? Ace.java public class Ace { private double a;...

    Java. What is the output of this code? Ace.java public class Ace { private double a; public Ace ( double x) {       a = x; } public void multiply (double f) {       a *= x;         } public String toString () {       return String.format ("%.3f", x); AceDem.java public class AceDemo { public static void main(String args[]) {    Ace card = new Ace (2.133); card.multiply (.5); System.out.println (card); } }

  • What is wrong the following code? Explain. public class Test { public static void main(String[] args)...

    What is wrong the following code? Explain. public class Test { public static void main(String[] args) { A a = new A(5.0); } class A { int value = 2; } }

  • What is the final value of the count field? public class Person { private String name;...

    What is the final value of the count field? public class Person { private String name; private int age; private static int count=0; public Person(String name, int age) { this.name = name; this.age age; count++; } public static void main(String[] args) { Person a - new Person("John Doe". 35): Person b new Person("Jane Doe", 38): for(int i=0;i<5;i++) Person tempa

  • Create a TicTacToe class that initializes a 3x3 board of "-" values. We will use this...

    Create a TicTacToe class that initializes a 3x3 board of "-" values. We will use this class in future exercises to fully build out a Tic Tac Toe game! The TicTacToe class should have a 2D array as an instance variable and a constructor that initializes the 2D array with the "-" value. Add a getter method that returns the private 2D instance variable. public class TicTacToeTester { //You don't need to alter any of the code in this class!...

  • can someone explain to me what does the dot mean ? and what would be the...

    can someone explain to me what does the dot mean ? and what would be the output and explain it? import java.io.*; public class Green { private int a; private int b; public Green(int aa,int bb) { a=aa; b=bb; } public void equals(Green c) { this.a=c.a;this.b=c.b;} public void fn(Green c) { this.a=3*c.b-c.a; this.b=2*c.a-this.b;} public void gg() { this.b=this.b-1; this.a=this.b-2; } public static void main(String args[]) { Green x=new Green(2,2); Green y=new Green(2,1); Green z=new Green(1,4); int xx=1,yy=2,zz=3; x.fn(y); z.gg(); System.out.println("...

  • Please Explain, Thanks :) QUESTION 2 Ghen is a java class าน¡strate, what are the contents...

    Please Explain, Thanks :) QUESTION 2 Ghen is a java class าน¡strate, what are the contents of the object right after line 13 in the main method ? public class Illustrate public ธtatic void main (String[] args) int xj private statie int y o public statie int count 0; public 1llustrate() 1. Illustrate I1 2. Illustrate 12 new Illustrate(3); new Illustrate(5): 4. Illustrate.incrementY) public Illustrate(int a) 9. Illustrate.count 10 public Illustrate(Illustrate 1) this.x I.x public vold setx(inta) 12. 13. Illustrate...

  • In Java. Please use the provided code Homework 5 Code: public class Hw05Source { public static...

    In Java. Please use the provided code Homework 5 Code: public class Hw05Source { public static void main(String[] args) { String[] equations ={"Divide 100.0 50.0", "Add 25.0 92.0", "Subtract 225.0 17.0", "Multiply 11.0 3.0"}; CalculateHelper helper= new CalculateHelper(); for (int i = 0;i { helper.process(equations[i]); helper.calculate(); System.out.println(helper); } } } //========================================== public class MathEquation { double leftValue; double rightValue; double result; char opCode='a'; private MathEquation(){ } public MathEquation(char opCode) { this(); this.opCode = opCode; } public MathEquation(char opCode,double leftVal,double rightValue){...

  • Can you please help me to run this Java program? I have no idea why it...

    Can you please help me to run this Java program? I have no idea why it is not running. import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.DecimalFormat; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @SuppressWarnings({"unchecked", "rawtypes"}) public class SmartPhonePackages extends JFrame { private static final long serialVersionID= 6548829860028144965L; private static final int windowWidth = 400; private static final int windowHeight = 200; private static final double SalesTax = 1.06; private static JPanel panel;...

  • IN JAVA: Write a class, ZeroException, which is an Exception, and is used to signal that somethi...

    IN JAVA: Write a class, ZeroException, which is an Exception, and is used to signal that something is zero when it shouldn't be. Write the class ArrayManipulator which creates an array and provides several methods to manipulate values taken from an array. ZeroException Task: Exceptions are used to signal many types of problems in a program. We can write our own as well to describe specific exceptional conditions which may arise. The advantage of doing so is that when exceptions...

  • PLEASE HURRY Software Testing Don't make any changes to the provided code. Please write a test...

    PLEASE HURRY Software Testing Don't make any changes to the provided code. Please write a test case for the below prompt using the provided java programs Use the setString() function in MyCustomStringInterface to set the value to “Peter Piper picked a peck of pickled peppers.”. Then test to see if reverseNCharacters() function returns the reversed string when the characters are reversed in groups of 4 and padding is disabled (in this case, “etePiP r repkcipa decep fo kcip delkpep srep.”)....

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