Skip to main content

Example for Outer class reference

 * This is a real time example for out class reference
package tcase;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;

 * @author visruth cv
public class Outer extends JFrame {

    private String outerClassField = "some value1";

    public Outer() {
        super("title of the frame");
        setSize(600, 600);
        setLayout(new FlowLayout());
        JButton b = new JButton("Ok");
        b.addActionListener(new ActionListener() {
            private String outerClassField = "some value2";
            public void actionPerformed(ActionEvent e) {
                System.out.println(Outer.this.outerClassField); //line 29
                System.out.println(outerClassField); //line 30

    public static void main(String[] args) {
        new Outer();
The line no.29 gives the current reference of outer class Outer.
Line no. 29 prints as 'some value1' and line no. 29 prints as 'some value2'


Popular posts from this blog

How to trim all strings in a bean (pojo/value object) in Java

One of my favourite frameworks is webfirmframework

Forms are used everywhere in a web/desktop/other applications. In these forms, the user may enter values starting and/or ending with spaces. But we may not need theses spaces at the starting and ending, so we may want to trim it. As we know, we may simply use a trim() method to trim a string. But, what if we want to trim all strings in a bean/pojo/value object. Suppose, consider a form having some fields, first name, last name, address etc... The user may enter the values as

First Name :

Last Name :

Address :  House name, Place, Distring

The values have spaces in the beginning and ending. So, to write code to trim every string separately is a kind of messing sometimes.

Here is a method which can trim all strings in a bean/pojo/value object (Only the strings will be trimmed, so it doesn't matter if it contains data types other than strings). Before that let us make a value object (POJO/bean) for these fields.
Consider …

Why Should You Use Pure JavaScript for UI instead of third party js libraries

There are lot of JavaScript libraries which make the development easier. But when we use a pure JavaScript we understand the core functionality & logic of a JavaScript engine. When we use a new js library we have to learn its own functions, features and their usages and they might also lead to a misconception of JavaScript execution, eg: AngularJS. However, some functionalities like charts/diagrams may not be able to do in a shorter time with pure JavaScript, in such cases we have to rely on third party libs.

When we use third party js libraries which provide ready made ui features we might face some unsolvable issues when customization required for its ui features so if we have a plan for nth level of ui customization then it's always better to use pure JavaScript. Modifying the js library itself is not always safe.

Which is the best framework for generating html from java code

Are you looking for answers of any of the following questions

Building HTML in Java code onlyBetter Html Builder in javaBuilding HTML in Java code onlyHTML code in Java classIs it a good practice to write Java methods to return HTML strings that will be returned to the display/presentation layerWhich is the best opensource java library/jar for html reportingServer controlled UI framework in JavaIs there any Java framework which is faster than SSD Then please have a look at webfirmframework. When you can well maintain the code it's always fine to return html by even a method.

Buy me a chocolate if I'm the first one brought it in your attention!