GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Eclipse code format for fluent API’s
  • Memory management in java
  • Advantages of Struts 2.0 compare to Struts 1.2
  • January 2020
  • April 2012
  • March 2012
  • February 2012
  • Core Java
  • Struts 2
  • Uncategorized
  • MohanaRao SV
  • Permalink

This view

  • Original page
  • New address

GeezerVison is showing javaforlife.wordpress.com — Core Java – Java for Life

Java for Life

CoreJava, Struts2.0,Srping,Hibernate,JavaScript, HTML,Jquery,JPA,WebServices,Design Patterns
  • About me

    I am MohanaRao SV & I love to code.

    All posts / comments expressed here are my (or the contributors') own personal thoughts & views. And it never represents the views of the company / people I work with.

  • Recent Posts

    • Eclipse code format for fluent API’s
    • Memory management in java
    • Method to count number of repeated special characters in a given String.
    • Example for overriding Hashcode and Equals methods.
    • Advantages of Struts 2.0 compare to Struts 1.2
  • Archives

    • January 2020
    • April 2012
    • March 2012
    • February 2012
  • Categories

    • Core Java
    • Struts 2
    • Uncategorized

Updates from April, 2012 Toggle Comment Threads | Keyboard Shortcuts

  • Unknown's avatar

    MohanaRao SV 7:28 pm on April 27, 2012 Permalink | Reply
    Tags: java memorymanagement   

    Memory management in java 

    Heap: is a single area where JVM allocates memory for -Objects, including method code , static variables & instance variables.

    Stack: Stack is created for each individual thread, JVM allocates memory for – local variables & arguments(reference) (values passed to method variables)

    Note : interface – all values in interface are constants i.e final static, so it’s stored on Heap only.

    When we have a declaration like this

    class Sample{ 
    int e = 1; 
    public int math (int x, int y){ 
    A a = new A(); 
    return (A.e + x + y); 
    } 
    } 
    

    Then we have:
    Stack: x, y, a
    Heap: instance a (it is A object), a.e = 1
    (Note that a in stack points out to instance a in heap)
    If instance a is no longer used, it is garbage collected

     

    Reply Cancel reply

    Required fields are marked *

  • Unknown's avatar

    MohanaRao SV 3:22 pm on March 18, 2012 Permalink | Reply
    Tags: Java   

    Method to count number of repeated special characters in a given String. 

    public Map<Character, Integer> charIntMap(String str) {
    		Map<Character, Integer> map = new HashMap<Character, Integer>();
    		char[] charString = str.toCharArray();
    		int count = 1;
    		for (int i = 0; i < (charString.length - 1); i++) {
    			if (!Character.isLetter(charString[i])) {
    				if (!map.containsKey(charString[i])) {
    					map.put(charString[i], count);
    				} else {
    					map.put(charString[i], count++);
    				}
    			}
    		}
    		return map;
    	}
    
    
     
  • Unknown's avatar

    MohanaRao SV 1:02 am on March 12, 2012 Permalink | Reply
    Tags: core java.   

    Example for overriding Hashcode and Equals methods. 

    Whenever you are working with the collections HashMap, HashSet then you have to override pojo hashcode and equals method.

    package com.stackoverflow.java.core;
    
    import java.util.HashMap;
    import java.util.Map;
    
    public class Employee {
    	private String name;
    	private String sex;
    	private int salary;
    	private int age;
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    	public String getSex() {
    		return sex;
    	}
    
    	public void setSex(String sex) {
    		this.sex = sex;
    	}
    
    	public int getSalary() {
    		return salary;
    	}
    
    	public void setSalary(int salary) {
    		this.salary = salary;
    	}
    
    	public int getAge() {
    		return age;
    	}
    
    	public void setAge(int age) {
    		this.age = age;
    	}
    
    	@Override
    	public int hashCode() {
                      //Not taken care when genrating hashcode.
    		int hashcode = this.age * 2 + this.salary * 2;
    		return hashcode;
    	}
    
    	@Override
    	public boolean equals(Object obj) {
    		if (this == obj)
    			return true;
    		if (obj == null)
    			return false;
    		if (getClass() != this.getClass())
    			return false;
    		Employee employee = (Employee) (obj);
    		if ((this.name.equals(employee.name) && (this.sex.equals(employee.sex)
    				&& (this.age == employee.age) && (this.salary == employee.salary)))) {
    			return true;
    		} else {
    			return false;
    		}
    	}
    
     

c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Subscribe Subscribed
  • Java for Life
    View site in Reader
    Manage subscriptionsSign upLog in
    Report this content
    Collapse this bar
Create your own website, free on WordPress.com.Create your own website.
Start free
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.