Friday, March 20, 2020

How Barometers Measure Air Pressure

How Barometers Measure Air Pressure A barometer is a widely used weather instrument that measures atmospheric pressure (also known as air pressure or barometric pressure) the weight of the air in the atmosphere. It is one of the basic sensors included in weather stations. While an array of barometer types exist, two main types are used in meteorology: the mercury barometer and the aneroid barometer. How the Classic Mercury Barometer Works The classic mercury barometer is designed as a glass tube about 3 feet high with one end open and the other end sealed. The tube is filled with mercury. This glass tube sits upside down in a container, called the reservoir, which also contains mercury. The mercury level in the glass tube falls, creating a vacuum at the top. (The first barometer of this type was devised by Italian physicist and mathematician Evangelista Torricelli in 1643.) The barometer works by balancing the weight of mercury in the glass tube against the atmospheric pressure, much like a set of scales. Atmospheric pressure is basically the weight of air in the atmosphere above the reservoir, so the level of mercury continues to change until the weight of mercury in the glass tube is exactly equal to the weight of air above the reservoir. Once the two have stopped moving and are balanced, the pressure is recorded by reading the value at the mercurys height in the vertical column. If the weight of mercury is less than the atmospheric pressure, the mercury level in the glass tube rises (high pressure). In areas of high pressure, air is sinking toward the surface of the earth more quickly than it can flow out to surrounding areas. Since the number of air molecules above the surface increases, there are more molecules to exert a force on that surface. With an increased weight of air above the reservoir, the mercury level rises to a higher level. If the weight of mercury is more than the atmospheric pressure, the mercury level falls (low pressure). In areas of low pressure, air is rising away from the surface of the earth more quickly than it can be replaced by air flowing in from surrounding areas. Since the number of air molecules above the area decreases, there are fewer molecules to exert a force on that surface. With a reduced weight of air above the reservoir, the mercury level drops to a lower level. Mercury vs. Aneroid Weve already explored how mercury barometers work. One con of using them, however, is that theyre not the safest things (after all, mercury is a highly poisonous liquid metal). Aneroid barometers are more widely used as an alternative to liquid barometers. Invented in 1884 by French scientist Lucien Vidi, the aneroid barometer resembles a compass or clock. Heres how it works: Inside of an aneroid barometer is a small flexible metal box. Since this box has had the air pumped out of it, small changes in external air pressure cause its metal to expand and contract. The expansion and contraction movements drive mechanical levers inside which move a needle. As these movements drive the needle up or down around the barometer face dial, the pressure change is easily displayed. Aneroid barometers are the kinds most commonly used in homes and small aircraft. Cell Phone Barometers Whether or not you have a barometer in your home, office, boat, or plane, chances are your iPhone, Android, or another smartphone has a built-in digital barometer! Digital barometers work like an aneroid, except the mechanical parts are replaced with a simple pressure-sensing transducer. So, why is this weather-related sensor in your phone? Many manufacturers include it to improve elevation measurements provided by your phones GPS services (since atmospheric pressure is directly related to elevation). If you happen to be a weather geek, you get the added benefit of being able to share and crowdsource air pressure data with a bunch of other smartphone users via your phones always-on internet connection and weather apps. Millibars, Inches of Mercury, and Pascals Barometric pressure can be reported in any one of the below units of measure: Inches of Mercury (inHg) - Used mainly in the United States.Millibars (mb) - Used by meteorologists.Pascals (Pa) - The SI unit of pressure, used worldwide.Atmospheres (Atm) - Air pressure at sea level at a temperature of 59 Â °F (15 Â °C) When converting between them, use this formula: 29.92 inHg 1.0 Atm 101325 Pa 1013.25 mb Edited by Tiffany Means

Tuesday, March 3, 2020

How Static Fields in Java Work

How Static Fields in Java Work There can be times when its useful to have values that are shared across all instances of a particular class. Static fields and static constants enable this type of sharing by belonging to the class and not to the actual objects. The Static Modifier Normally fields and methods defined in a class can be used only when an object of that class type has been created. For example, consider a simple Item class that keeps track of goods in a store: public class Item {   Ã‚  private String itemName;   Ã‚  public Item(String itemName)   Ã‚  {   Ã‚  Ã‚  Ã‚  this.itemName itemName;   Ã‚  }   Ã‚  public String getItemName()   Ã‚  {   Ã‚  Ã‚  Ã‚  return itemName;   Ã‚  } } To be able to use the getItemName() method, we must first create an Item object, in this case, catFood: public class StaticExample {   Ã‚  public static void main(String[] args) {   Ã‚  Ã‚  Ã‚  Item catFood new Item(Whiskas);   Ã‚  Ã‚  Ã‚  System.out.println(catFood.getItemName());   Ã‚  } } However, if the static modifier is included in a field or method declaration, no instance of the class is required in order to use the field or method - they are  associated with the class and not an individual object. If you look back at the above example, you will see that the static modifier is already being used in the main method declaration: public static void main(String[] args) { The main method is a static method that does not require an object to exist before it can be called. As main() is the starting point for any Java application, there are in fact no objects already in existence to call it. You could, if you felt like having a program that continually calls itself, do this: public class StaticExample {   Ã‚  public static void main(String[] args) {   Ã‚  Ã‚  Ã‚  String[] s {random,string};   Ã‚  Ã‚  Ã‚  StaticExample.main(s);   Ã‚  Ã‚  Ã‚  } } Not very useful, but notice how the main() method can be called without an instance of a StaticExample class. What Is a Static Field? Static fields are also known as class fields. They are simply fields that have the static modifier in their declarations. For example, lets go back to the Item class and add a static field: public class Item {   Ã‚  //static field uniqueId   Ã‚  private static int uniqueId 1;   Ã‚  private int itemId;   Ã‚  private String itemName;   Ã‚  public Item(String itemName)   Ã‚  {   Ã‚  Ã‚  Ã‚  this.itemName itemName;   Ã‚  Ã‚  Ã‚  itemId uniqueId;   Ã‚  Ã‚  Ã‚  uniqueId;   Ã‚  } } The fields itemId and itemName are normal non-static fields. When an instance of an Item class is created, these fields will have values that are held inside that object. If another Item object is created, it too will have itemId and itemName fields for storing values. The uniqueId static field, however, holds a value that will be the same across all Item objects. If there are 100 Item objects, there will be 100 instances of the itemId and itemName fields, but only one uniqueId static field. In the above example, uniqueId is used to give each Item object a unique number. This is easy to do if every Item object that is created takes the current value in the uniqueId static field and then increments it by one. The use of a static field means that each object does not need to know about the other objects to get a unique id. This could be useful if you wanted to know the order in which the Item objects were created. What Is a Static Constant? Static constants are exactly like static fields except that their values cannot be changed. In the field declaration, the final and static modifiers are both used. For example, perhaps the Item class should impose a restriction on the length of the itemName. We could create a static constant maxItemNameLength: public class Item {   Ã‚  private static int id 1;   Ã‚  public static final int maxItemNameLength 20;   Ã‚  private int itemId;   Ã‚  private String itemName;   Ã‚  public Item(String itemName)   Ã‚  {   Ã‚  Ã‚  Ã‚  if (itemName.length() maxItemNameLength)   Ã‚  Ã‚  Ã‚  {   Ã‚  Ã‚  Ã‚  Ã‚  Ã‚  this.itemName itemName.substring(0,20);   Ã‚  Ã‚  Ã‚  }   Ã‚  Ã‚  Ã‚  else   Ã‚  Ã‚  Ã‚  {   Ã‚  Ã‚  Ã‚  Ã‚  Ã‚  this.itemName itemName;   Ã‚  Ã‚  Ã‚  }   Ã‚  Ã‚  Ã‚  itemId id;   Ã‚  Ã‚  Ã‚  id;   Ã‚  } } As with static fields, static constants are associated with the class rather than an individual object: public class StaticExample {   Ã‚  public static void main(String[] args) {   Ã‚  Ã‚  Ã‚  Item catFood new Item(Whiskas);   Ã‚  Ã‚  Ã‚  System.out.println(catFood.getItemName());   Ã‚  Ã‚  Ã‚  System.out.println(Item.maxItemNameLength);   Ã‚  Ã‚  Ã‚  } } There are two important things to notice about the maxItemNameLength static constant: It is declared as a public field. Generally its a bad idea to make a field public in any class you design but in this case, it doesnt matter. The value of the constant cannot be changed.The static constant is used from the class name Item, not an Item object. Static constants can be seen throughout the Java API. For example, the integer wrapper class has two that store the maximum and minimum values an int data type can have: System.out.println(The max value for int is: Integer.MAX_VALUE); System.out.println(The min value for int is: Integer.MIN_VALUE); Output: The max value for int is: 2147483647 The min value for int is: -2147483648