Sunday, June 28, 2015

Fundamentals in Distributed Components Based Software Development.

Hi Guys,
This post regarding the lab session we have done in the DCBSD lab. Most of the student missed the steps, because of this reason lot of students faced troubles. Honestly, this lab session is not a big deal until you catch the each step clearly. Following steps described each important area we have done in DCBSD lab. I think this would be helpful to get some sense about DCBSD fundamentals.

1. Hello world ! – JAVA vs C# 
I think I don’t need to explain much detailed information about this step, but following screen shots will be getting some sense regarding basic configuration, what should be done first.

1.1.1 JAVA – Configurations in cmd
Set environment variable.
Just drag and drop folder inside to the command prompt
Change directory 
Just drag and drop folder inside to the command prompt

1.1.2 JAVA – ‘Hello World!’ application
In this level you don’t need to mention class access flag specially. Leave it as it is.

class helloWorld
{
    public static void main(String args[])
    {
        System.out.println("Hello World!");
    }
}
1.1.3 Compile
C:\Users\Denuwan Hettiarachch\Desktop\Lab 01>javac "Hello World !.java"

1.1.4 Run
C:\Users\Denuwan Hettiarachch\Desktop\Lab 01>java helloWorld

1.1.5 Disassemble Java class file 
When you have .class file of a project, it’s not readable. But we can read .class file thought the JAVA disassemble command in cmd.
C:\Users\Denuwan Hettiarachch\Desktop\Lab 01>javap -c helloWorld.class

1.2.1 C# - Configurations in cmd
You can use ‘Developer Command Prompt for VS2012’ , specially configured for C# as a developer tool. You don’t need to worry about set environment variable or anything about configuration. Just search it, open it & use it. It’s cool !
Search cmd and open Developer Command Prompt for VS2012

1.1.2 C# – Hello World ! application
In this level you don’t need to mention class access flag specially. Leave it as it is same as the JAVA.
using System;

class helloWorld
{
    public static void Main(String []args)
    {
        Console.WriteLine("Hello World !");
    }
}


1.1.3 Compile
C:\Program Files (x86)\Microsoft Visual Studio 11.0>cd "C:\Users\Denuwan Hettiarachch\Desktop\Lab 01" C:\Users\Denuwan Hettiarachch\Desktop\Lab 01>csc "Hello World !.cs"


1.1.4 Run
C:\Users\Denuwan Hettiarachch\Desktop\Lab 01>"Hello World !"

1.1.5 Disassemble C# class file
When you have .exe file of a project, it’s not readable. But we can read .exe file thought the C# disassemble command in cmd.

C:\Users\Denuwan Hettiarachch\Desktop\Lab 01>ILDASM "Hello World !.exe 
Disassembled code - C# GUI

2. Create a library & reusing JAVA
Here’s the deal, we create the class file without main method and compile it, you know if we doesn’t have main method we can’t run this class. It just a library file. We can reuse this library file in another application with the main method. But you should follow specified file structure you put all the libraries in the specified folder and import when you want to reuse it again.

2.1.1 Here’s the my file structure

2.1.2 Create a library file inside a ‘com’ folder
If you remember the first step which we created ‘Hello world!’ app, I mention you don’t need to worry about access flag, and we leave as it is by default. But when we create a library we can’t do it in that way. Because we decide to reuse it again, so we need to change the access flag as a ‘public’ because of the access flag change we should follow additional step, that is we must save the project file using class name. Otherwise we can’t reuse it again. 

package Code.com;

public class Item
{
    private int itemId;
    private String itemName;
    private double itemPrice;
  
    public Item(int itemId,String itemName,double itemPrice)
    {
        this.itemId = itemId;
        this.itemName = itemName;
        this.itemPrice = itemPrice;
    }

    public void printItemDetails()
    {
        System.out.println("Item ID : "+itemId);
        System.out.println("Item Name : "+itemName);
        System.out.println("Item Price : "+itemPrice);
    }
}
  
When I compile, I'm still in the root folder. no need to change directory. 
C:\Users\Denuwan Hettiarachch\Desktop\Lab 01>javac Code\com\*.java 


2.1.3 Create a project in root folder and reuse the library
We need to import library package top of the class.

import Code.com.*; //Import all libraries included in com folder

class itemApp
{
    public static void main(String args[])
    {
        Item firstItem = new Item(1,"Milk Powder",250.50);
        firstItem.printItemDetails();
    }

C:\Users\Denuwan Hettiarachch\Desktop\Lab 01>javac ItemApp.java

C:\Users\Denuwan Hettiarachch\Desktop\Lab 01>java itemApp

2.1.4 Create a library archive file and reuse it again.
We can also put all the libraries in the archive (.jar) file and reuse it when we want, Remember when we execute the command we must in the root folder in the cmd, and provide correct folder which libraries are included inside.  

2.1.4.1 Create an archive file
C:\Users\Denuwan Hettiarachch\Desktop\Lab 01>jar -cvf library.jar Code

2.1.4.2 Compile project using archive file 
C:\Users\Denuwan Hettiarachch\Desktop\Lab 01>javac -cp library.jar ItemApp.java

2.1.4.3 Execute the application which is using the archive file.
C:\Users\Denuwan Hettiarachch\Desktop\Lab 01>java -cp library.jar;. itemApp

3. Create a .dll library and reuse it in C# project
When we comparing the JAVA vs C# up to this level coding part is same except few things. But reusing libraries concept little bit change C# comparing with Java. C# doesn’t use folder structure we can simply name the namespace and recall it inside the runnable application without worrying the file structure.

using System;

namespace studentPackage
{
    public class student
    {
        private int studentId;
        private String studentName;
      
        public student(int Id, String Name)
        {
            studentId = Id;
            studentName = Name;
        }
       
        public void printStudentDetails()
        {
            Console.WriteLine("Id : "+studentId);
            Console.WriteLine("Name : "+studentName);
        }
    }
}

3.1 Create a .dll file
C:\Users\Denuwan Hettiarachch\Desktop\Lab 01>csc /target:library Student.cs

3.2 Compile project file, which is use .dll file


using System;
using studentPackage;

class StudentApp
{
    public static void Main(String []args)
    {
        student firstStudent = new student(1,"Kamal");
        firstStudent.printStudentDetails();
    }
}


C:\Users\Denuwan Hettiarachch\Desktop\Lab 01>csc /reference:Student.dll StudentApp.cs

3.3 Execute the runnable program which is use .dll file
C:\Users\Denuwan Hettiarachch\Desktop\Lab 01>StudentApp

[Download Lab Work]

Happy Coding.....

Regards,
Denuwan Himanga. 

2 comments: