December 5, 2011

Java Serialization

We can read a file with FileReader function available in Java as FileReader fr = new FileReader(fileName); BufferedReader br = new BufferedReader(fr); Once data loaded into memory from file, now read it line by line String line = br.readLine(); while(line!=null) { pieces = line.split(separator); //for meta keywords we use mostly comma //now the string is […]

Ideal Weight Calculator

Ideal Weight Calculator Code Highlights: import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; JTextField txtWeight; static JSlider heightScale; ButtonGroup btnGroup; JRadioButtonMenuItem btnMale; JRadioButtonMenuItem btnFemale; public void calculate_weight() { String genderValue; if(btnMale.isSelected()==true) { genderValue = btnMale.getActionCommand(); } else { genderValue = btnFemale.getActionCommand(); } Integer userHeight = heightScale.getValue(); Integer heightSqr = (userHeight*userHeight); String idealWeight = […]

October 30, 2011

Float Array Sum Function In Java

Float Array Sum Function In Java: public float sumArr(float[] args) { int sum = 0; for (int j=0; j sum += args[j]; } return sum; }