sanjeev on May 31st, 2010

Last week I attended training session on Design Pattern in AS3 …Before this session I  didn’t had clear picture of Design Pattern but now i am very much confident about this term…here I am going to put what I have learnt during my training session..

Introduction:
When we talk about the definition of Design Pattern..than various definition comes in my mind..so i will put one simple definition …”In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn’t a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.”

In other words we can say Design patterns provide solutions to common software design problems. In the case of object-oriented programming, design patterns are generally aimed at solving the problems of object generation and interaction, rather than the larger scale problems of overall software architecture. They give generalised solutions in the form of templates that may be applied to real-world problems.

Gang of Four(GOF):
When we discuss Design Pattern this term(GOF) is very important. The Gang of Four(Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides.) are the authors of the book(the book that started it all), “Design Patterns: Elements of Reusable Object-Oriented Software“. This book have been highly influential to the field of software engineering and is regarded as an important source for object-oriented design theory and practice. It gives a high-level description of the twenty-three design patterns.

In this article I just focused about what is design pattern…In next post I would discuss some of the major pattern like:
Strategy Pattern
Observer Pattern
Decorator Pattern
Factory Pattern
Singleton Pattern

Tags: , ,

sanjeev on March 31st, 2010

It is very easy to perform print operation in Flex.  You just need to use mx.printing.FlexPrintJob class.  The FlexPrintJob class is a wrapper for the flash.printing.PrintJob class. It supports automatically slicing and paginating the output on multilple pages, and scaling the grid contents to fit the printer’s page size.

You can find the code below to print data  from text file.

<?xml version=”1.0″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” creationComplete=”loadFile();”>
<mx:Script>
<![CDATA[

import flash.net.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLLoaderDataFormat;
import mx.printing.FlexPrintJobScaleType;
import mx.printing.FlexPrintJob;

private function loadFile():void
{
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, onComplete);
urlLoader.load(new URLRequest("PrintData.txt"));
}

private function onComplete(event:Event):void
{
textArea.text = URLLoader(event.target).data;
}

private function print(event:MouseEvent):void
{
var flexPrintJob:FlexPrintJob = new FlexPrintJob();
// checking if printer dialog box  is ready
if(flexPrintJob.start())
{

// adding object to print
flexPrintJob.addObject(textArea,FlexPrintJobScaleType.SHOW_ALL);
// sending data to print
flexPrintJob.send();
}
}
]]>
</mx:Script>

<mx:TextArea id=”textArea” height=”100%” width=”100%”/>
<mx:Button label=”Print Data” click=”print(event);”/>
</mx:Application>

In this code , I am loading text file named “PrintData.txt” . When we click on “Print Data” Button print dialog box will be appeared , choose printer settings and follow further instruction.

Tags: , ,

sanjeev on February 22nd, 2010

Following are the top 15 reason to use flex4:

1. Integration with Adobe Catalyst
2. Spark Component Architecture
3. MXML 2009
4. Improvements to View States
5. FXG Support
6. Skinning Enhancements
7. Updated Layout Model
8. Flash Builder 4
9. Compiler Performance
10. New Text Capabilities
11. Flash CS4 support
12. Remote services
13. Event handler autogeneration
14. Declarative graphics
15. Unit testing, Network monitor

Soon i will put features in detail..

sanjeev on February 2nd, 2010

I was wondering why the gtalk client doesn’t allow me to set invisible mode while chatting. But thanks to Gtalk Lab edition. I can now set an invisible mode in gtalk also. Just download the Gtalk Lab edition. This edition of Gtalk provides various features as well as invisible mode option ( not available in regular gtalk).

sanjeev on December 30th, 2009

Yesterday I was working on AS3 ..and I faced a problem regarding text formatting, I had to adjust the alignment of textfield at runtime..for this I wrote following piece of code:

var textFormat:TextFormat = new TextFormat();
textFormat.align = “center”;
textField.setTextFormat(textFormat);

But this didn’t work..I don’t know why.. after doing lots of R&D I found the simplest and acceptable solution..
To adjust the alignment of  TextField in AS3..we can use autoSize property..

textField.autoSize=”center”

sanjeev on December 9th, 2009

Yesterday I was running  “Disk Cleanup” in order to clean unnecessary files from my disk. By mistake I  checked “Hibernate file cleaner“  option in Disk Cleanup wizard. Next time when I started my laptop than I saw “Hibernate” option is missing from my system. Well it is known issue in vista but I forget that..I started googling to sort out this problem..and the solution I found is very easy.. you just have to do..

1) Right click on command prompt option(Start->Programs->Accessories->Command Prompt) and choose “Run as administrator”.

2)In Command Prompt windows type any of the  following command

powercfg /hibernate on
powercfg -h on

3) Now type “Exit” in command prompt..and you will see “Hibernate” option is re-enabled in your system…

Tags: , ,

sanjeev on November 23rd, 2009

Hello friends…I am back with new article..this time with good news…and my experiences with SCJP..

This month I took SCJP 1.5 and cleared it .. I am happy and want to share my experience with you…If you have to crack SCJP with good score..first you have to brush up all your basis fundamentals in Core Java..

To crack SCJP I will say..follow 3 P’s:

1)Practice

2)Practice

3)Practice

I mean to say just practice practice and practice…because practice will  improve your solving power effectively during examination…

The Dos and Don’ts for SCJP…

Do:

1) Read SCJP book by Katherine Sierra carefully..and believe me this book is like bed time story book..You will enjoy a lot while reading .

2) Practice mock exam..you can find various mock exam on net.

3) Join some java forum to discuss any issue I prefer JavaRanch

4) Use any exam simulator in order to feel real time exam and try to manage your time with accuracy.

Don’t

1) Don’t read only dump..It’s true that some question may come in exam..but what I faced that questions are slightly changed..like

In dump :

public String get() { return this.name; }

But in exam it may be:

String get() { return this.name; }

Here both function look similar except modifier(public,default)..so be careful while doing dumps..

I hope this will help all  candidate who are ready or planing to take the test

I will also post some article specially for SCJP  soon..

First you have to brush up all your basis fundamentals in Core Java

Tags:

sanjeev on October 8th, 2009

An assertion is a boolean expression that a developer specifically proclaims to be true during program runtime execution. The simple idea of using assertions can have an unexpected influence on a software program’s design and implementation. In this article I cover the mechanics of using the new assertion facility introduced in J2SE.

Assertions let you test your assumptions during development, but the assertion code basically evaporates when the program is deployed, leaving behind no overhead or debugging code to track down and remove.

Suppose you assume that a number passed into a method (say, assertMethod()) will never be negative. While testing and debugging, you want to validate your assumption, but: you don’t want to have to strip out print statements, runtime exception handlers, or if/else tests when you’re done with development. But leaving any of those in is, at the least, a performance hit. Assertions to the rescue! Check out the following code:

private void assertMethod(int number) {
if (number>= 0) {
useNumber(number+ x);
} else {  // number must be < 0
// This code should never be reached!
System.out.println(“ooh.. numberis a negative number! ”
+ number);
}
}

Because you’re so certain of your assumption, you don’t want to take the time (or program performance hit) to write exception-handling code. And at runtime, you don’t want the if/else either because if you do reach the else condition, it means your earlier logic (whatever was running prior to this method being called) is flawed.

Assertions let you test your assumptions during development, but the assertion code basically evaporates when the program is deployed, leaving behind no overhead or debugging code to track down and remove. Let’s rewrite assertMethod() to validate that the argument was not negative:

private void assertMethod(int number) {
assert (number>=0);   // throws an AssertionError
// if this test isn’t true
useNumber(number+ x);
}

Not only do assertions let your code stay cleaner and tighter, but because assertions are inactive unless specifically “turned on” (enabled).

Assertions work quite simply. You always assert that something is true. If it is, no problem. Code keeps running. But if your assertion turns out to be wrong (false), then a stop-the-world AssertionError is thrown (that you should never, ever handle!) right then and there, so you can fix whatever logic flaw led to the problem.

Assertions come in two flavors:

1.  assert expression1;

private void assertA()
assert (y > x);
// more code assuming y is greater than x
}

2. assert expression1 : expression2;

private void assertA() {
assert (y > x): “y is ” + y + ” x is ” + x;
// more code assuming y is greater than x
}

The difference between the two is that the second flavor adds a second expression, separated from the first (boolean expression) by a colon, this expression’s string value is added to the stack trace. Both flavor throw an immediate AssertionError, but the second flavor gives you a little more debugging help while the first flavor simply tells you only that your assumption was false.

Enabling Assertions:

You can enable assertions at runtime with
java -ea com.geelcsanonymous.TestClass    or
java -enableassertions com.geeksanonymous.TestClass

Disabling Assertions :
You must also know the command-line switches for disabling assertions,
java -da com.geeksanonymous.TestClass   or
Java -disableassertions com.geeksanonymous.TestClass

Enabling Assertions in Eclipse:

Basically, you want to pass an argument (-ea) to the VM. How to do this might vary depending on your version of Eclipse, but here’s how it works in Eclipse Europa…
# Open the Run Dialog (this should be an option under the “Run” menu).
# Click on the tab, “(x)= Arguments.”
# In the field for “VM arguments,” enter -ea to enable assertions.
# Click on the “Apply” button.

Tags: ,

sanjeev on July 1st, 2009

In Gmail Labels are great and all, but there are times I just want to move a message out of my inbox into a folder. but I guess I”m not the only one everyone easy way to manage the messages. I mean to say  that if you want to label a mail, you can simply drag and drop it over the label in your left sidebar and you’re done.

The list of labels has been moved up, pushing the chat list down, Google has minimized the number of labels that appear in the default list as to not push the chat bar down too far. For those who have dozens of labels in use, clicking on the “more” button will bring up the additional labels without going to a different Web page, and the number of labels shown in the default view can be set by the user.

For the first time, however, Google kill its first Gmail Labs project: right-side labels, which allowed you to move your labels to the right sidebar to get them out of the way, is no more.

sanjeev on June 30th, 2009

Bing is a new search engine designed to do more than merely help you find information. Bing organizes search results and provides refinement tools that help you overcome information overload, get things done and quickly bring you to the point of using that information to make an informed decision.