Tuesday, March 29, 2011

First C# Program Line by Line

The following is a typical Hello World program for C#.  On the left side is the code and the right side its explanations. 

using System;

This reference is used by Console class. Otherwise, you need to type the class in full (to include its namespace System):

System.Console.WriteLine(“…”);

using System.Collections.Generic;

Not used. Something useful that Microsoft tries to promote.

using System.Linq;

Not used. Something useful that Microsoft tries to promote.

using System.Text;

Not used. This reference contains the StringBuilder class that is memory efficient when working with strings manipulations.

 

Blank line or tab or space has no effect on the final compiled code. Add them to improve the code readability.

namespace ConsoleApplication1

A way to group related code together. By default, Visual Studio will use your application name as the namespace.

{

1st curly bracket START

Curly brackets { and } comes in a pair. They group block of code.

Everything from here till the 1st curly bracket END, belongs to the namespace ConsoleApplication1

class Program

Everything in C# must in a class. In this case, the name of the class is

ConsoleApplication1.Program

(You need to include the namespace as part of the name of the class)

{

2nd curly bracket START

Everything from here till the 2nd curly bracket END, belongs to the class Program

static void Main(string[] args)

static: it is a keyword to specify that the method Main is “static” . It belongs to the class and not instances of the class.

void: it is a keyword to specify that the method Main returns nothing.

string[] args: a string array variable with the name args

curly bracket { } : for code block

curve bracket ( ) : for method

square bracket [ ] : for array type

{

3rd curly bracket START

Everything from here till the 3rd curly bracket END, belongs to the method Main

Console.WriteLine("Hello C Sharp!");

Code doing the actual work!

}

3rd curly bracket END

}

2nd curly bracket END

}

1st curly bracket END

I have started a blog for beginners

Wednesday, March 23, 2011

What is programming in a nutshell?

Apply problem solving skills, then use programming language to tell the computer what to do and finally the result is a completed program.

image

Tuesday, March 22, 2011

Win 7: disk management and defrag

Just received my new Fujitsu Lifebook S series notebook with Intel core i7 with Nvidia Geforce 310M, 4 Gig DDR3 1066Mhz RAM, running on win7 32 bit enterprise OS.

It comes in 2 partition: 300 Gig C: drive and 200 Gig D: drive.

I have the habit of starting the machine with a good long term maintenance strategy, this time I did the following:

Adjust disk partitions:

I removed D: drive, shrinked C: drive to about 150 Gig, then create a new 100 Gig D: drive followed by 250 Gig E: drive. C: drive for more permanent programs, D: drive for adhoc programs that I play around, E: drive for data.

Start > Computer > (Right click) Manage

Storage > Disk Management

Right click on any of the disk:

image

Turn on the defragmentation program:

Locate the defragmentation program by typing into the search box: defrag

image

Click on configure schedule

image

Set the weekly schedule for a suitable timing

image

That’s it.

How to become a good programmer eventually?

There are many programming books designed for “dummies” (real beginners) but really not doing so.  I am trying to consolidate basic stuff with these beginners in mind. 

Stuff like how long to become a good programmer (at least 10 years or 10000 hrs) and what skills to pick up other than learning a programming language (problem solving, learning how computer works and etc):

http://mpgddprog.blogspot.com/

Thursday, October 07, 2010

Netbeans for Mobile App

The following is just a brief introduction to Java ME and features in Netbeans 6.9.x.

Updated: I have created a new blog on how to develop Java ME games using Netbeans 6.9.x:

http://mpgddmgd.blogspot.com/

Content:

  • Lab 01: My First MIDlet for Java ME Application
  • Lab 02: Packaging and Deployment

Reference:

http://netbeans.org/features/javame/

http://netbeans.org/kb/docs/javame/quickstart.html

http://www.forum.nokia.com/Develop/Java/Getting_started/Step_5_Find.xhtml

http://www.openclassworld.org/javame

Netbeans for Mobile App

Netbeans IDE provides the following components that make it easy to create mobile applications or games:

Netbeans IDE

Create, test and debug applications for the Mobile Information Device Profile (MIDP) 1.0, 2.0, 2.1 (MSA), the Connected Limited Device Configuration (CLDC) 1.0 and 1.1, and the Connected Device Configuration (CDC).

The NetBeans IDE comes bundled with the latest Java ME SDK 3.0 which supports both CLDC and CDC development. You can register other mobile and embedded platforms from the Tools menu.

Visual Mobile Designer

Develop GUIs rapidly with the Visual Mobile Designer (VMD): Drag and drop components like wait screens, login screens, file browsers, an SMS composer, and splash screens are included. The Analyzer tool helps you decrease file size by identifying unused components for removal, and it also checks for MIDP 1.0 compliance. The VMD also makes GUI localization easier.

SVG Component Palette

Select basic shapes from the SVG image palette to get started and use the other SVG components in the palette such as SVGForm, Button, CheckBox, TextField, Slider, and more to create rich content interfaces for your mobile applications.

Data Binding

Data Binding to UI components is a simple and consistent way for applications to interact with and display data using the Data Binding property editor together with the DataSet component in the Visual Mobile Designer.

Mobile Game Builder

Develop mobile games with a visual editor designed for the MIDP 2.0 Game API. The API allows you to create game scenes with sprites on a game canvas using tiled layers and layer management.

Next, we shall only cover the basic Netbeans IDE interface. The other topics shall be covered later on.

Lab 01: My First MIDlet for Java ME Application

Step 1: Start Netbeans 6.9.x

Step 2: Create a new Java ME MIDP application:

File > New Project

image005

Project name: HelloWorld1

image008

Netbeans IDE navigations

[Projects] [Navigator] [File]

image016

Views: Source Screen Flow Analyzer

Other windows: Properties Palette

image017

Visual Mobile Designer Palatte Reference:

http://wiki.netbeans.org/VisualMobileDesignerPalatteReference

Step 3: Build and Run: Run > Run Main Project (F6)

image018

image019

Step 4: Select another emulator phone: Projects Window: right click on HelloWorld1 > Properties

Click on the Devices to select another emulator phone.

image023image024

Step 5: Build and Run: Run > Run Main Project (F6)

Lab 02: Packaging and Deployment

Step 1: Run > Clean and Build Project (shift F11)

Step 2: Browse using Windows File Explorer to the project folder

For example: …\ My Documents\NetBeansProjects\HelloWorld1\dist

image025

Step 3: Direct PC connection (depends on your mobile phone)

For Sony Ericson, copy the above two files into the "installs" folder

image026

Step 4: In your mobile phone, browse to the "installs" folder to install the MIDlet

What do we need to know?

(1) Automatic preverification

Because J2ME is designed for small devices with limited memory, much of the usual Java preverification has been removed from the virtual machine to allow for a smaller footprint. As a result, it is necessary to preverify your J2ME application before deployment. An additional check is made at run time to make sure that the class has not changed since preverification.

In Java ME IDEs (Netbeans/Eclipse), preverification of classes is done automatically during the compile process.

(2) Deployment: JAD and JAR files

JAR file is just a zip file containing two files: MANIFEST.MF and preverified class file (HelloMIDlet.class)

MANIFEST.MF is a text file containing the following information:

Manifest-Version: 1.0

Ant-Version: Apache Ant 1.8.1

Created-By: 1.6.0_16-b01 (Sun Microsystems Inc.)

MIDlet-1: HelloMIDlet, , hello.HelloMIDlet

MIDlet-Vendor: Vendor

MIDlet-Name: HelloWorld1

MIDlet-Version: 1.0

MicroEdition-Configuration: CLDC-1.1

MicroEdition-Profile: MIDP-2.1

JAD (Java Application Descriptor) is just a text file containing the following information:

MIDlet-1: HelloMIDlet, , hello.HelloMIDlet

MIDlet-Jar-Size: 2069

MIDlet-Jar-URL: HelloWorld1.jar

MIDlet-Name: HelloWorld1

MIDlet-Vendor: Vendor

MIDlet-Version: 1.0

MicroEdition-Configuration: CLDC-1.1

MicroEdition-Profile: MIDP-2.1

(3) Other Deployment methods

Over-The-Air (OTA)

image027

Email and MMS

A JAR file could be included as an attachment to an e-mail or within an MMS. When the e-mail/MMS is opened, the AMS will automatically be activated and provide an option to install the sent MIDlet.

Deploying from Netbeans

Projects [Right click] select Properties, select Deploying, select Deployment Method:

image028

Projects [Right click] select Deploy

That’s all for the introduction. Happy learning ....

Continue your learning via tutorial series to develop mobile games in Java ME using Netbeans: http://mpgddmgd.blogspot.com/