Sunday, June 10, 2012

Simple JPA Example

     In ySchool-mini week 4 assignment I did a simple JPA ( Java Persistence API) Project. In this project I used the same scenario (scenario-3) that was used in assignment-2 and  assignment-3.

What is JPA?

      The Java Persistence API  is a Java specification for accessing, persisting, and managing data between Java objects / classes and a relational database.

JPA

Scenario 3: 
a) Student marks can be entered entered in the following way
Student Name (StudentName loaded in ComboBox), Grade (1-13 ComboBox), Subject, Marks
b) User can enter these values and click "Add"
c) Here all those fields are mandatory and marks cannot be more than 100
d) System should validate those fields and show it in the response page

The source code is uploaded  in github.
https://github.com/Niroshan06/yschool_mini_nirosh_ass4

After create the database the netbeans was look like this.

Student database


  • Then I created a maven project ( yschool_mini_nirosh_ass4 ) in netbeans. Project structure was look like this.
Project structure
 
  • In index.jsp I added code for main page.
Main page

  • Then I created an entity class name "StudentsMarks".
              Right click on SourcePackages(jsf.yschool_mini_nirosh_ass4) ---> New --->
              Entity Class.. --->
 
Creating an Entity class.
                     
                Next ---> select "student" as Database Connection ---> finish.


Setup database connection.

  • In this Entity class (StudentsMarks.java) I added four variables String name, String grade, String subject and int marks. Then created getter and setter methods for this four variables.
 
  •  Then I created a Servlet, name "controller".
               Right click on SourcePackages(jsf.yschool_mini_nirosh_ass4) ---> New --->
               Servlet
 
Servlet

  • In controller.java I added a method "persist"
persist method
  • Then I wrote some codes in dopost method. You can get full codes from github.
           https://github.com/Niroshan06/yschool_mini_nirosh_ass4

  • When I run the project....



  • After click Add button a table "studentsmarks" was created automatically in the database "student".
              
studentsmarks table
 
  • To view the table values...
               Right click on the table (studentsmarks) ---> View Data...

Values in the table



Saturday, June 9, 2012

Simple JSF Project


In ySchool-mini week-3assignment I did a simple JSF (JAVA Server Faces) project.
In this project I use the same scenario that I used in Assignment-2.

Scenario 3: 
a)  Student marks can be entered entered in the following way
     Student Name (StudentName loaded in ComboBox), Grade (1-13 ComboBox), Subject, Marks
b)  User can enter these values and click "Add"
c)  Here all those fields are mandatory and marks cannot be more than 100
d)  System should validate those fields and show it in the response page

The full coding is uploaded  in github. https://github.com/Niroshan06/yschool_mini_nirosh_ass3

My project structure is look like this.

Project Structure
  • First I created a maven project using netbeans.
  • Then I added a JSF page name addMarks.
                   Right click on project----> New----> JSF page

JSF Page
  • In addMarks.xhtml following code is generate automatically.
                       <html xmlns="http://www.w3.org/1999/xhtml"
                                 xmlns:h="http://java.sun.com/jsf/html"
                                 xmlns:f="http://java.sun.com/jsf/core">

      The first is standard practice for XHTML pages. The second two directives allow the Facelets page to use the JSF Core and HTML tag libraries that are provided in the JSF specification, which in turn allows the Facelets page to use the underlying JSF UI components in the page.

  •  I added more codes in addMarks.xhtml to create the main page.
Main page
  • For the"Subject" text box I wrote the following code
                   <h:inputText label="Subject"
                           id="subject"
                           value="#{userBean.subject}"
                           required="true"/>
                  <h:message for="subject" />

      Here the required attribute is set to "true". So when we click Add button with empty Subject, it will give an error message for subject.
      In value attribute, it provides direct linkage to the subject property of the managed bean userBean. Basically, a managed bean is an officially registered Java class for a JSF application.

  • Then I created managed bean, name "userBean".
                  Right click on package---->New---->other---->JavaServer Faces---->JSF Managed Bean
Managed Bean
  • In userBean.java I added four variables String stuName, int grade, String subject and int marks. Then created getter and setter methods for this variables.
  • When I run the project......

Subject is empty.





Sunday, May 20, 2012

MVC architecture

      In yschool-mini week-1 assignment, I did my first simple maven project. From that assignment I have get a little experience in maven.
     This week (week 2) I have done assignment-2. This assignment is concern with MVC(Model,View,Controller)  architecture.

Model
   
It handles data processing and database works part. Model processes events sent by controller. After processing these events then it sends processed data to controller (thus, controller may reprocess it) or directly to view side.

View
   
View prepares an interface to show to the user. Controller or model tells view what to show to the user. Also view handles requests from user and informs controller.

Controller
   
Let’s say controller is like brain of the system. That is right. Because it processes every request, prepares other parts of the system like model and view. Then the system determines what to do by controller’s commands.

To understand the MVC  architecture the YIT team gave three different scenarios.

Scenario 1: 
a) Student registration page will have the following fields to be filled.
Student Name, Address, Grade (Year 1 to 13 loaded in ComboBox), Parent Name
b) User can enter these values and click "Register"
c) Here Student Name and Grade are mandatory fields
d) System will validate for those mandatory fields and will show a error message in the response page
e) If validation succeeds, show up the details of the registered student.

 
Scenario 2: 
a) Students can be searched by the following parameters
Student Name, Grade (Year 1 to 13 loaded in ComboBox)
b) User can enter these values and click "Search"
c) System should provide some mock data response based on the search parameter
(keep 5-6 students' details within the java class itself)
d) Search results need to be shown in the table in a new page

Scenario 3: 
a) Student marks can be entered entered in the following way
Student Name (StudentName loaded in ComboBox), Grade (1-13 ComboBox), Subject, Marks
b) User can enter these values and click "Add"
c) Here all those fields are mandatory and marks cannot be more than 100
d) System should validate those fields and show it in the response page


   I choose Scenario 3 to understand MVC architecture.

I use NetBeans IDE for this project.
The project structure is look like fig.1
fig-1

 Project Name is yschool-mini-niroshan
 This project has four JSP pages.


To get source code of this project click below.

 https://github.com/Niroshan06/yschool-Nirosh












When I run my project the browser was look like this.

fig-2


 When I click Add button with empty field, warning message was displayed.

fig-3


When the marks was less than zero or greater than hundred another warning message was displayed.

fig-4

When I fill the fields correctly, browser displayed Marks View.

fig-5
fig-6


Tuesday, April 24, 2012

My first simple maven project

Experience in first simple maven project

Last week (21st April 2012) Yarl IT Hub had conducted an online meeting about Java web programming techniques and fundamentals, followed by a session on Git source control, Maven build and initial project setup for crash course series. That day I heard about the Maven.


Set up the maven

I did the following set up to run the maven project.


If the maven installed correctly, the command prompt look like this.

 

 Create the first project.


  • In the commend prompt I typed "mvn archetype:generate -DarchetypeArtifactId=mavenarchetype-webapp -DgroupId=org.yarlithub.yschool -DartifactId=yschool"
  • It run  long time. finally It displayed the message "BUILD SUCCESS".
  • Then I changed my directory, where my project is created (yschool).
  • then I compiled my project by "mvn compile" command.
  • After I compiled, a folder 'target' was created into the yschool folder.
  • Then I add a jetty plugin to maven pom.xml
  • Run the command "mvn install jetty:run", It also run long time, finally it displayed the message "[INFO] Started Jetty Server"
  • Then I started my browser and type "http://localhost:8080/yschool/", the browser displayed "Hello World".
  • Then I go through yschool --->src ---> main ---> webapp --->index.jsp and edit text and reload the browser.

  

This is my first maven project.

Saturday, April 21, 2012

Mobile Operating System (Mobile OS)



Mobile Operating Systems (Mobile OS)
































Mobile Operating Systems (Mobile OS) 



         Like a computer operating system, a mobile operating system is the software platform on top of which other programs run. When you purchase a mobile device such as mobile phones, smartphones, PDAs and handheld computers, the manufacturer will have chosen the operating system for that specific device. The operating system is responsible for determining the functions and features available on your device, such as thumbwheel, keyboards, WAP, synchronization with applications, e-mail, text messaging and more. The mobile operating system will also determine which third-party applications can be used on your device. Some of the more common and well-known Mobile operating systems include the following:

Symbian OS
Symbian OS has become a standard operating system for smartphones, and is licensed by more than 85 percent of the world's handset manufacturers. The Symbian OS is designed for the specific requirements of 2.5G and 3G mobile phones.

Windows Mobile
The Windows Mobile platform is available on a variety of devices from a variety of wireless operators. You will find Windows Mobile software on Dell, HP, Motorola, Palm and    i-mate products. Windows Mobile powered devices are available on GSM or CDMA networks.

Palm OS
Since the introduction of the first Palm Pilot in 1996, the Palm OS platform has provided mobile devices with essential business tools, as well as capability to access the Internet or a central corporate database via a wireless connection.


Mobile Linux

The first company to launch phones with Linux as its OS was Motorola in 2003. Linux is seen as a suitable option for higher-end phones with powerful processors and larger amounts of memory.

MXI

MXI is a universal mobile operating system that allows existing full-fledged desktop and mobile applications written for Windows, Linux, Java, Palm be enabled immediately on mobile devices without any redevelopment. MXI allows for interoperability between various platforms, networks, software and hardware components.

Bada

Bada is an operating system for mobile devices such as smartphones and tablet computers. It is developed by Samsung Electronics. Its name means "ocean" or "sea" in Korean. It ranges from mid-range to high-end smartphones.


BlackBerry OS 

This OS is focused on easy operation and was originally designed for business. Recently it has seen a surge in third-party applications and has been improved to offer full multimedia support. Currently Blackberry's App World has over 50,000 downloadable applications.



iOS from Apple Inc

The Apple iPhone, iPod Touch, iPad, and second-generation Apple TV all use an operating system called iOS, which is derived from Mac OS X. Native third party applications were not officially supported until the release of iOS 2.0 on July 11th 2008. Before this, "jailbreaking" allowed third party applications to be installed, and this method is still available. Currently all iOS devices are developed by Apple and manufactured by Foxconn or another of Apple's partners.


Android

Android was developed by a small startup company that was purchased by Google Inc, and Google continues to update the software. Android is a Linux-derived OS backed by Google, along with major hardware and software developers that form the Open Handset Alliance.

Android has a large community of developers writing applications ("apps") that extend the functionality of the devices. Developers write primarily in a customized version of Java. Apps can be downloaded from third-party sites or through online stores such as Google Play (formerly Android Market), the app store run by Google. As of February 2012 there were more than 450,000 apps available for Android, and the estimated number of applications downloaded from the Android Market as of December 2011 exceeded 10 billion.

Market share
In 2006, Android, iOS, Windows Phone and Bada did not yet exist and just 64 million smartphones were sold. Today, nearly 10 times as many smartphones are sold and the top mobile operating systems marketed as "smartphones" by market share are Android, Symbian, Apple iOS, RIM BlackBerry, MeeGo, Windows Phone, and Bada.
Quarter
Android
iOS
Symbian
RIM
Microsoft
Bada
Other
2011     Q4
50.9%
23.9%
11.7%
8.8%
1.9%
2.1%
0.8%
2011     Q3
52.5%
15.0%
16.9%
11.0%
1.5%
2.2%
0.9%
2011     Q2
43.4%
18.2%
22.1%
11.7%
1.6%
1.9%
1.0%
2011     Q1
36.0%
16.8%
27.4%
12.9%
3.6%
1.7%
1.6%
2010     Q4
31.1%
16.1%
32.9%
13.1%
3.4%
1.3%
2.2%
2010     Q3
25.3%
16.6%
36.3%
15.4%
2.8%
1.1%
2.5%
2010     Q2
17.2%
14.2%
41.2%
18.2%
5.0%
0.9%
3.3%
2010     Q1
9.6%
15.3%
44.2%
19.7%
6.8%

4.4%
2009     Q4
7.6%
16.2%
44.7%
19.7%
7.9%

4.0%
2009     Q3
3.4%
17.0%
44.2%
20.5%
7.9%

7.0%
2009     Q2
1.8%
13.0%
51.0%
19.0%
9.3%

5.9%
2009     Q1
1.6%
10.5%
48.8%
20.6%
10.2%

8.2%
2008     Q4
1.1%
10.6%
46.5%
19.3%
12.2%

9.1%
2008     Q3
0.6%
13.1%
50.3%
16.1%
11.2%

9.8%
2008     Q2

2.8%
57.5%
17.5%
12.1%

10.8%
2008     Q1

4.6%
49.5%
11.6%
10.4%

11.6%
2007     Q4

5.2%
62.3%
10.9%
11.9%

9.6%
2007     Q3

3.4%
63.1%
9.7%
12.8%

11.5%
2007     Q2

1.0%
65.6%
8.9%
11.5%

13.0%
2007     Q1


61.2%
8.7%
13.4%

16.8%
            Table: World-Wide Smartphone Sales.