Thứ Ba, 30 tháng 12, 2008

Dot Net Interview Questions - Part 3

1.What is a stack? What is a heap?

Ans : Stack is a place in the memory where value types are stored. Heap is a place in the memory where the reference types are stored.

2.What is Boxing/Unboxing?

Ans : Boxing is used to convert value types to object.
E.g. int x = 1;
object obj = x ;
Unboxing is used to convert the object back to the value type.
E.g. int y = (int)obj;

3.What is globalization?

Ans : Globalization is the process of customizing applications that support multiple cultures and regions.

4.What is localization?

Ans : Localization is the process of customizing applications that support a given culture and regions.

5.What is Ilasm.exe used for?

Ans : Ilasm.exe is a tool that generates PE files from MSIL code. You can run the resulting executable to determine whether the MSIL code performs as expected.

6.What is Ildasm.exe used for?

Ans : Ildasm.exe is a tool that takes a PE file containing the MSIL code as a parameter and creates a text file that contains managed code.

7.What is the ResGen.exe tool used for?

Ans : ResGen.exe is a tool that is used to convert resource files in the form of .txt or .resx files to common language runtime binary .resources files that can be compiled into satellite assemblies.

8.What happens when you change the web.config file at run time?

Ans : ASP.NET invalidates the existing cache and assembles a new cache. Then ASP.NET automatically restarts the application to apply the changes.

9.Explain the AutoPostBack feature in ASP.NET?

Ans : AutoPostBack allows a control to automatically postback when an event is fired. For eg: If we have a Button control and want the event to be posted to the server for processing, we can set AutoPostBack = True on the button.

10.What are Master Pages?

Ans : Master pages is a template that is used to create web pages with a consistent layout throughout your application. Master Pages contains content placeholders to hold page specific content. When a page is requested, the contents of a Master page are merged with the content page, thereby giving a consistent layout.

11.What are the types of Caching?

Ans : 1.Application Cache 2.Page Output Cache 3.Variable Cache

12.Method Parameters in C#?

Ans : 1. REF,2. OUT,3.PARAMS

13.What’s the .NET datatype that allows the retrieval of data by a unique key?

Ans : HashTable.

14.How do you debug an ASP.NET Web application?

Ans : Attach the aspnet_wp.exe process to the DbgClr debugger.

15.What is the syntax to inherit from a class in C#?

Ans : Place a colon and then the name of the base class.

Example: class MyNewClass : MyBaseClass

16.What’s a bubbled event?

Ans : When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents.

17.What does WSDL stand for?

Ans : Web Services Description Language.

18.Can you override private virtual methods?

Ans : No, moreover, you cannot access private methods in inherited classes, have to be protected in the base class to allow any sort of access.

19.What is an out parameter?

Ans : An out parameter allows an instance of a parameter object to be made inside a method. Reference parameters must be initialised but out gives a reference to an uninstanciated object.

20.What is recursion?

Ans : Recursion is when a method calls itself.

21.Name 10 C# keywords.

Ans : abstract, event, new, struct, explicit, null, base, extern, object, this

22.What is a DLL?

Ans : A set of callable functions, which can be dynamically loaded.

23.What is unsafe code?

Ans : Unsafe code bypasses type safety and memory management.

24.How would you read and write using the console?

Ans : Console.Write, Console.WriteLine, Console.Readline

25.What’s the difference between // comments, /* */ comments and /// comments?

Ans : Single-line comments, multi-line comments, and XML documentation comments.

Dot Net Interview Questions - Part 2

1.What are server controls?

Ans : ASP.NET server controls are components that run on the server and encapsulate user-interface and other related functionality. They are used in ASP.NET pages and in ASP.NET code-behind classes.

2.What are Sealed Classes in C#?

Ans : The sealed modifier is used to prevent derivation from a class. A compile-time error occurs if a sealed class is specified as the base class of another class. (A sealed class cannot also be an abstract class) .

3.What is the difference between Array and Arraylist?

Ans : As elements are added to an ArrayList, the capacity is automatically increased as required through reallocation. The capacity can be decreased by calling TrimToSize or by setting the Capacity property explicitly.

4.What is Jagged Arrays?

Ans : A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different dimensions and sizes. A jagged array is sometimes called an “array-of-arrays.”

5.Which method is used to redirect the user to another page without performing a round trip to the client?

Ans : Server.Transfer method.

6.Is it possible to debug java-script in .NET IDE? If yes, how?

Ans : Yes, simply write “debugger” statement at the point where the breakpoint needs to be set within the javascript code and also enable javascript debugging in the browser property settings.

7.How many ways can we maintain the state of a page?

Ans : Client Side - Query string, hidden variables, viewstate, cookies

Server side - application , cache, context, session, database.

8.Will the finally block be executed if an exception has not occurred?

Ans : Yes it will execute.

9.What is the base class of all web forms?

Ans : System.Web.UI.Page .

10.Can we force the garbage collector to run?

Ans : Yes, using the System.GC.Collect(), the garbage collector is forced to run in case required to do so.

11.What does the virtual keyword in C# mean?

Ans : The virtual keyword signifies that the method and property may be overridden.

12.Whats the difference between web.config and app.config?

Ans : Web.config is used for web based applications whereas app.config is used for windows based applications.

13.What is the difference between a session object and an application object?

Ans : A session object can persist information between HTTP requests for a particular user, whereas an application object can be used globally for all the users.

14.Is it possible to perform forms authentication with cookies disabled on a browser?

Ans : No, it is not possible.

15.Which control has a faster performance, Repeater or Datalist?

Ans : Repeater.

16.What technique is used to figure out that the page request is a postback?

Ans : The IsPostBack property of the page object may be used to check whether the page request is a postback or not. IsPostBack property is of the type Boolean.

17.How can we force a thread to sleep for an infinite period?

Ans : Call the Thread.Interupt() method.

18.What’s the difference between Response.Write() andResponse.Output.Write()?

Ans : Response.Output.Write() allows you to write formatted output.

19.Describe the difference between inline and code behind.

Ans : Inline code written along side the html in a page. Code-behind is code written in a separate file and referenced by the .aspx page.

20.What is the lifespan for items stored in ViewState?

Ans : Item stored in ViewState exist for the life of the current page. This includes postbacks (to the same page).

21.What is PostBack & Callback?

Ans : One technique that current ASP.NET 1.0/1.1 developers use to overcome this postback problem is to use the Microsoft XMLHTTP ActiveX object to send requests to server-side methods from client-side JavaScript. In ASP.NET 2.0, this process has been simplified and encapsulated within the function known as the Callback Manager. The ASP.NET 2.0 Callback Manager uses XMLHTTP behind the scenes to encapsulate the complexities in sending data to and from the servers and clients. And so, in order for the Callback Manager to work, you need a web browser that supports XMLHTTP. Microsoft Internet Explorer is, obviously, one of them.

22.What is singlecall and singleton ?

Ans : Differneces between Single Call & Singleton. Single Call objects service one and only one request coming in. SingleCall objects are useful in scenarios where the objects are required to do afinite amount of work. Single Call objects areusually not required to store state information, and they cannot hold state information between method calls. However, SingleCall objects can be configured in aload-balanced fashion.

Singleton objects are those objects that service multiple clients and hence share data by storing state information between client invocations. They are useful in cases in which data needs tobe shared explicitly between clients and also in which the overhead of creating and maintaining objects is substantial.

23.What is Machine.config File ?

Ans : As web.config file is used to configure one asp .net web application, same way Machine.config file is usedto configure application according to a particular machine. That is, configuration done in machine.configfile is affected on any application that runs on a particular machine. Usually, this file is not alteredand only web.config is used which configuring applications.

24.What debugging tools come with the .NET SDK?

Ans : 1. CorDBG – command-line debugger. To use CorDbg, you must compile the original C# file using the /debug switch.

2. DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR.

25.What does assert() method do?

Ans : In debug compilation, assert takes in a Boolean condition as a parameter, and shows the errordialog if the condition is false. The program proceeds without any interruption if the conditionis true.

Dot Net Interview Questions part 1

1.What method do you use to explicitly kill a users session?

Ans : Syntax: Session.Abandon()

Note : The Abandon method destroys all the objects stored in a Session object and releases their resources.If you do not call the Abandon method explicitly, the server destroys these objects when the session times out.

2.What methods are fired during the page load?

Ans : Init() ,Load(),PreRender(),Unload().

3.What data type does the RangeValidator control support?

Ans : Integer,String and Date.

4.Which method do you invoke on the DataAdapter control to load your generated dataset with data?

Ans : Fill() method.

5.Which control would you use if you needed to make sure the values in two different controls matched?

Ans : CompareValidator Control

6.What base class do all Web Forms inherit from?

Ans : The Page class.

7.Explain the differences between Server-side and Client-side code?

Ans : Server-side code executes on the server. Client-side code executes in the context of the clients’ browser. you store the information about the user’s locale?

Ans : System.Web.UI.Page.Culture

9.Can you edit data in the Repeater control?

Ans : No, it just reads the information from its data source.

10.Which template must you provide, in order to display data in a Repeater control?

Ans : ItemTemplate.

11.How can you provide an alternating color scheme in a Repeater control?

Ans : AlternatingItemTemplate.

12.Name two properties common in every validation control?

Ans : ControlToValidate property and Text property.

13.Is String is Value Type or Reference Type in C#?

Ans : String is an object (Reference Type).

14.What is the difference between Server.Transfer and Response.Redirect? Why would I choose one over the other?

Ans : Server.Transfer transfers page processing from one page directly to the next page without making a round-trip back to the client’s browser. This provides a faster response with a little less overhead on the server. Server.Transfer does not update the clients url history list or current url. Response.Redirect is used to redirect the user’s browser to another page or site. This performas a trip back to the client where the client’s browser is redirected to the new page. The user’s browser history list is updated to reflect the new address.

15.What is the Global.asax used for?

Ans : The Global.asax (including the Global.asax.cs file) is used to implement application and session level events.

16.How many classes can a single .NET DLL contain?

Ans : It can contain many classes.

17.What is portable executable (PE)?

Ans : The file format defining the structure that all executable files (EXE) and Dynamic Link Libraries (DLL) must use to allow them to be loaded and executed by Windows. PE is derived from the Microsoft Common Object File Format (COFF). The EXE and DLL files created using the .NET Framework obey the PE/COFF formats and also add additional header and data sections to the files that are only used by the CLR.

18.What is strong name?

Ans : A name that consists of an assembly’s identity—its simple text name, version number, and culture information (if provided)—strengthened by a public key and a digital signature generated over the assembly.

19.What is Code Access Security (CAS)?

Ans : CAS is the part of the .NET security model that determines whether or not a piece of code is allowed to run, and what resources it can use when it is running. For example, it is CAS that will prevent a .NET web applet from formatting your hard disk.

20.What are the different types of assemblies?

Ans : Private, Public/Shared, Satellite

21.Which namespace is the base class for .net Class library?

Ans : system.object

22.How do you create threading in .NET? What is the namespace for that?

Ans : System.Threading.Thread .

23.What is the difference between ref & out parameters?

Ans : An argument passed to a ref parameter must first be initialized. Compare this to an out parameter, whose argument does not have to be explicitly initialized before being passed to an out parameter.

24.What are indexers?

Ans : Indexers are similar to properties, except that the get and set accessors of indexers take parameters, while property accessors do not.

25.What are the access-specifiers available in c#?

Ans : Private, Protected, Public, Internal, Protected Internal.

Chôm từ :

Thứ Hai, 29 tháng 12, 2008

Cakephp 1.2 final ra lò

Cakephp 1.2 final ra lò

Today, the history of the CakePHP grows stronger. December 25, 2008 will be remembered as one of the most important points in this history. After exactly 2 yrs from the first development release, we can happily say we have the most stable and powerful web framework available. Please enjoy our big present to you, CakePHP 1.2 stable [1]. For this release, we have removed the test files from the build, and created a tag in SVN.

Through the last two years, we have been blessed by a dedicated, talented, and opinionated community[2]. We have shared disagreements[3] and triumphs. We have won popularity contests[4] and been hated on. We have seen CakePHP grow into a truly international community[5]. All of these events have generated an immense amount of passion for CakePHP.

No one is more passionate about CakePHP than the developers[6] who close tickets and fix bugs. We started out two years ago with a small team that dedicated countless hours to implementing new features into 1.2 and maintaining 1.1 stable. This team ensured the integrity of code and vision of the project. When we needed to grow, we found members of the community who showed the same amount of dedication and passion for CakePHP. And with the launch of CakeBOOK, on, we have seen the dedication and passion further extend to all the contributors and translators[7] of the fantastic documentation that makes learning about the power of CakePHP a bit easier.

We have seen CakePHP adopted by large projects[8] and the growth of dedicated service companies[9]. We have held a workshop[10] to spread the knowledge and passion of CakePHP. And ultimately, we implemented a huge list of features...

  • - Tests!

    • - All classes are test-covered, with good code coverage

    • - Test suite now integrated into the framework

    • - test generation

    • - support for coverage analysis

  • - Command-line infrastructure

    • - with more shell scripts and ability to write custom ones easily

  • - Plugin architecture

    • - Plugins are now distributable as packaged collections of files

    • - Can be loaded from your main app with a dot syntax

  • - Internationalization and Localization support

    • - i18n and l10n classes

    • - Support for unicode strings

  • - Auth component

    • - automatically handles sessions for authenticated users

    • - ties into ACL for automatic denial of protected content or actions

  • - Email component

    • - for generation of text and html email

  • - Security component

    • - HTTP auth support, great for web services

    • - CSRF protection

  • - Cookie component

    • - for secure cookie handling

  • - Custom model finders

    • - simplified syntax

  • - powerful and extensible

  • - Join models

    • - for modeling and accessing HABTM join tables

  • - Behaviors, new way to extend models

    • - Supports "mixing in" new functionality

  • - Containable behavior

    • - simplified query optimization

  • - Validation system extended

    • - with new Validation class, lots of rules

  • - multiple rules and messages

  • - Database drivers

    • - support for many more databases including DB2 and Oracle

  • - Caching

    • - Adapter-driven caching, with support for APC/XCache/Memcache

  • - Set class,

    • - for magical array hacking

  • - Socket and HttpSocket classes

    • - for dealing with remote data and services

  • - Debugger class, for detailed introspection of errors

    • - Get stack traces anywhere in your code

    • - Introspected help on errors, with context information

  • - Pagination

    • - one of the first additions to the new version

    • - one of the simplest systems known

  • - Proper Routing

    • - mapResources() method for exposing controllers via REST

    • - Reverse routing support

    • - Named arguments

    • - Magic variables for common regexes

    • - Support for file extensions with custom content type mappings

  • - View stuff

    • - Separate templates for different content types

    • - automatic switching with RequestHandler

    • - New helper callbacks

    • - renderElement() replaced with element(), added built-in caching support

  • - FormHelper

    • - All form-related methods moved here

    • - New dot notation

    • - Support for associations and multiple records

    • - Huge automation and introspection support; form creation requires very little code

  • - Configure and App classes

    • - for configuration and loading

  • - Replaces defines and global functions

We hope that was a fun read. The changes since 1.1 have been dramatic, but to us this was the minimum set of features needed to a truly powerful framework and realize our vision for maintainability, flexibility, and extensibility.

Almost as dramatic as the feature set, was the growth of the community over this time, especially with its adoption of testing. We are proud of the fact that Cake is one of the most test covered frameworks. Test coverage allows us to fix more bugs and produce the most stable framework available. We believe that a feature is not truly a feature if there is even one known bug. With that in mind, each release comes with the expectation that no bugs are known at the time.

Many of you may remember the first release of 1.2. Back on Dec 25, 2006 we released at revision 4206. Many features had not been implemented or finalized, but we had a taste of what was to come. With this release at [7958], we have come a long way. But possibly the most exciting aspect of being where we are on Dec 25, 2008, is what we expect to see in the future.

CakePHP helps build amazingly powerful applications. We have a running list of examples[11]. Many of these applications were built with earlier versions of 1.2. With the release of CakePHP 1.2 stable, we expect these applications to enjoy a long history, just like the CakePHP project itself.

If you have made it this far, we would like to pass on a few extra goodies we have been working on. First is the all new Cake 1.2 cheatsheet. The old CakeSheet has proved to be a simple, quick reference to some of the power of CakePHP. This new version is the start of several more to come. Second, the gorgeous DebugKit plugin. This plugin helps you develop your application faster by providing quick, easy access to a lot of valuable debugging information. DebugKit also provides and excellent example of how you can build plugins to extend the functionality of you application. Finally, for all the TextMate users out there we have an updated CakePHP TextMate bundle. Joel Perras has put in a great amount of work and coding CakePHP in TextMate just got a lot easier thanks to him. For all these great resources and more, head on over to the downloads[12] page.

We hope you enjoy the big present and the few goodies. Have a great holiday season.
- Gwoo, Nate, PhpNut and the rest of the CakePHP team

download bản final ở đây

Thứ Năm, 25 tháng 12, 2008

Mẹo vặt với Apache 2

1. Để thêm một module vào apache (trên linux - win thì không biết )
a2enmod tên_mod
ví dụ
a2enmod rewrite
để thêm mod rewrite
2. Xem các module đã cài đặt
apache2ctl -l

Thứ Tư, 24 tháng 12, 2008

method chaining php

Trong một số thư viện của PHP người ta thường dùng method chaining để viết code ngắn gọn và đẹp hơn .

Doctrine là một ORM framework tận dụng triệt để cách viết này , một số khác có thể thấy trong các thư viện của Zend Framework .

Doctrine :

$users = Doctrine_Query::create()
->from('User u')
->leftJoin('u.Phonenumber p')

Zend Framework :

$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.')
->setFrom('', 'Some Sender')
->addTo('', 'Some Recipient')

Trong khi cách viết thông thường là :

$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('', 'Some Sender');
$mail->addTo('', 'Some Recipient');

Rõ ràng sử dụng method chaining đẹp và ngắn gọn hơn nhiều .

để làm được điều này , rất đơn giản . Ở các phương thức cho phép tiếp tục gọi tiếp sẽ return về đối tượng $this .

public function foo() {
... do something ...
return $this;

lúc này có thể gọi như sau $myobject->foo()->bar()->baz()->bat();

Thứ Năm, 18 tháng 12, 2008

Hướng dẫn cài đặt flex sdk trong Ubuntu

Để có thể làm việc được với Flex, về cơ bản chúng ta sẽ cần cài đặt 2 chương trình sau:
- Flex SDK: là một chương trình biên dịch và gỡ lỗi command line. Đây là một chương trình miễn phí của Adobe. Bạn có thể download miễn phí tại đây.

- Flash Flayer 10: là một chương trình để chạy các flex đã được biên dịch (hay đúng hơn là thực thi các mã script). Đây cũng là một chương trình miễn phí của Adobe. Bạn có thể download tại đây.

Cài đặt Flex SDK:

- Sau khi download về tôi được một file zip sau: Giải nén file zip ta có được folder flex_sdk_3, ta sẽ chuyển thư mục này vào một thư mục nào đó. Tôi sẽ chuyển thư mục này theo đường dẫn: "/home/tendangnhap/flex_sdk_3". Vậy là ta đã cài đặt xong.

- Để chạy flex sdk, chúng ta sẽ vào thư mục "flex_sdk-3/bin". Trong thư mục này sẽ chứa các file chạy, với windown thì file chạy sdk sẽ là mxmlc.exe. Còn trong linux thì file chạy chỉ là mxmlc. Bây giờ ta test bằng cách chạy một đoạn flex helloword nhé.

+ Đầu tiên ta sẽ tạo ra một file có tên là helloworld.mxml ngay trong thư mục flex_sdk_3/bin có nội dung như sau:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" layout="absolute">
<mx:Panel title="Hello World" width="200" height="100">
<mx:Label text="Wellcome to Flex" fontSize="20" color="blue"
mouseDownEffect="WipeRight" />

+Tiếp đến ta sẽ dúng sdk để dịch, ta vào chương trình Terminal, gọi đến đường dẫ chứa chương trình flex_sdk_3. Ở đây đường dẫ của tôi sẽ là: "/home/hoantocxoan/flex_sdk_3/bin/" ta sẽ gõ như sau:
sudo cd /home/hoantocxoan/flex_sdk_3/bin

sudo mxmlc helloworld.mxml

+ Sau 2 câu lệnh trên thì chương trình sẽ dịch ra file helloworld.swf. Như vậy là bạn đã cài đặt và biên dịch thành công flex_sdk.

- Công việc tiếp theo là ta sẽ thiết lập lại biến môi trường để ta có thể gọi chương được ở bất cứ nơi đâu thay vì cứ phải vào trong /home/hoantocxoan/flex_sdk_3/bin. Ta sẽ xét lại biến môi trường như sau:
sudo gedit ~/.bashrc

+ Ta sẽ mở được file bashrc bằng chương trình gedit trong ubuntu ra. Ta chỉ việc thêm vào 2 dòng sau:
export PATH=$PATH:/home/hoantocxoan/flex_sdk_3/bin

vào trước dòng "export HISTCONTROL=ignoreboth" là được.

Thứ Hai, 1 tháng 12, 2008

chơi với RIA

RIA là gì?

RIA - Rich Internet Application là một dạng ứng dụng web (web application) cố gắng thể hiện những chức năng truyền thống của phần mềm chạy trên desktop. Ở mức nào đó, RIA xóa nhòa lý thuyết phi trạng thái của giao thức HTTP.

RIA có đặc điểm gì?

  • ứng dụng RIA chạy hoàn toàn trên trình duyệt (web browser) hỗ trợ flash mà không cần cài đặt ứng dụng.

  • quan hệ khá gần với javascript

  • dung lượng tải về khá lớn nên phụ thuộc vào đường truyền mạng

  • không thân thiện với các máy tìm kiếm

  • nguy cơ bảo mật là có thật, dù flash & javascript bị rất hạn chế trong việc can thiệp vào hoạt động của máy tính.

Vậy lợi ích của RIA?

  • không cần cài đặt hay triển khai, đơn giản như là chạy ứng dụng flash.

  • cung cấp cho người dùng những chức năng vô cùng đa dạng, nâng cao lên rất nhiều khả năng tương tác so với mã HTML/DHTML/javascript truyền thống.

  • giao diện sử dụng rất ấn tượng với nhiều hiệu ứng hấp dẫn.

  • tương tác không đồng bộ (Asynchronous communication) với server, làm giảm tài nguyên mạng sử dụng cũng như tiết kiệm hoạt động của server. Bên cạnh đó lại dễ dàng dịch chuyển dữ liệu giữa client/server mà không cần người dùng phải thao tác nhiều và liên tục.

Xây dựng ứng dụng RIA?

bạn có thể sử dụng DHTML/css/javascript kết hợp với kỹ thuật ajax theo kiểu truyền thống hoặc sử dụng 2 dạng tiếp cận mới hơn là Flex & Silverlight.

cách đơn giản và dễ dàng nhất, bạn hãy tìm và download những cuốn sách về chủ đề & công cụ này để tìm hiểu thêm.

nếu bạn tự hỏi giữa flex & silverlight thì bạn nên học cái nào? thế này nhé, trong câu chuyện với một người bạn cách đây ít hôm, chúng tôi nói đến việc flash được cài trên hầu hết (>90%) trình duyệt web hiện nay, trong khi silverlight chỉ được cài trên ~ 6.3% số lượng. Điều đó có nghĩa là bạn học flex sẽ có tương lai hơn, bạn nghĩ vậy phải không? thế nhưng hôm đó bạn tôi đặt lại một vấn đề, nếu như Microsoft cài đặt mặc định silverlight vào tất cả các bản IE trong các phiên bản Windows sắp tới, thị phần trình duyệt cài silverlight sẽ tăng đến mức nào? có lẽ vào khoảng > 80% như thị phần của IE hiện nay.

ngoài ra, có một bài so sánh khá thú vị giữa flex vs silverlight của  ở đây

happy coding!

tham khảo:,