Oops I forgot I have a blog!

Howdy! I was thinking the other day that I needed to clean up my personal portfolio since I have learned so much over the last few years, but it is not reflecting on my site. As I was planning my redesign, I suddenly realized… I have a blog!!

So here I am again and I  am planning on booting this thing back up, so that I get back into sharing what I learned and to help myself solidify my understanding of the things I learned. So win-win for all!

Decompiling a Java Applet

Preinstall:

 

Walkthrough:

  1. Launch the Java applet that you want to extract.

step1

  1. Right click on the page and inspect element. If the Inspect Element page does not pop up, try right clicking again in the white space of the page.

step2

  1. Find a tag called Applet, and look for an attribute called archive. That value is the .jar file we need to download.step3

           Note: The attribute called codebase is the directory the jar file is stored.

  1. Go to the url that launched the Java applet and type in the codebase directory plus the jar file name.

step4

  1. If successful, you will have a copy downloaded to your computer.

step5

  1. Next, we need to find a decompiler for Java, and it is important to keep in mind that there are different decompiling softwares. In this example we will use a plug-in for Eclipse (http://jd.benow.ca/). Follow the instructions from this link

step6

  1. Restart Eclipse and create a new project called ExtractedApplet.

step7

  1. Right click the created project and choose Add External Archives under Build Path. Select the .jar file we want to add. This will add the downloaded jar file to your project.

step8

  1. You can now expand the Jar file and double click on the class you want to decompile.

step9

Now you can extract the code and do what you want with it!

Connecting an Android application with a web service developed in Node.js

What is a Web service?

W3C defines Web services as, “a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-processable format (specifically WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP-messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards.” In other words, Web service is a software system that bridges communication between multiple systems over a network. Web pages and applications use different types of Web standards to send and retrieve data.

How to setup a Web service?

One of the Web services used is Node JS. It is a JavaScript environment used for developing server-side web applications. The following steps and links will walk through Node and Express setup. The goal is to respond to a query by sending a JSON Object.

  1. First need to download NodeJS from there website https://nodejs.org/en/.
  2. Follow the steps shown on http://expressjs.com/starter/installing.html.
  3. Next edit the entry point file. In this case I choose index.js as the entry point file. Add the following information shown. This will return a JSON object.

Screenshot of Singleton Patter

Note: Depending on how you install Express, you might want to install ‘npm install body-parser’. Used for JSON parsing and parsing POST if need it.

How to connect an Android application to Node.js?

Android recommends an API called Volley that uses a RESTful system to connect to a Web service. Volley is a separate API that allows you to send and receive data from server.

  1. Create a MainActivity and added permission for INTERNET access in the Manifest.xml.
  2. Screenshot of Manifest

  3. Download Volley() and select Import Module under File. Follow the prompting to add Volley to application.
  4. Screenshot of importing module

  5. Android recommends implementing a Singleton pattern for Volley. Here is a link to writing the Singleton class.
  6. Link: http://developer.android.com/training/volley/requestqueue.html

  7. In MainActivity make sure to import the following:
  8. Screenshot of what to import in Main Activity

  9. Here is a screenshot for reading in a JSON Object:
  10. Screenshot of MainActivity

    Note: If you are running a node server using localhost and testing with a virtual device, make sure that the URL/IP address in the android application uses 10.0.2.2.

 

References:

https://en.wikipedia.org/wiki/Node.js
https://nodejs.org/en/
https://scotch.io/tutorials/learn-to-use-the-new-router-in-expressjs-4
http://developer.android.com/tools/devices/emulator.html#emulatornetworking
http://developer.android.com/training/volley/requestqueue.html

Determining which mobile platform to develop on.

So you came up with an awesome idea for an application and now you want to determine what platform to build it in. Do you build an application for Android, iOS devices or both? What are the pros and cons? Here are a few things to think about when researching and some things I have discovered on the interwebs.

Who is your audience

Deciding on your audience will change what platform you build on. Are you looking for coverage based on a specific region of the world or  a demographic? As of writing this blog, 66.9 of mobile devices in United States are using Android devices, where iOS device use reported at 28.4%, but the highest revenue comes from iOS purchases.  Your target audience is a big key to deciding a mobile platform.

Link showing smartphone market share around the world:http://www.kantarworldpanel.com/global/smartphone-os-market-share/

Another detail to think about is platform version.  Do you build for the newest software version or plan for an older version.  Apple’s developer website shows majority of their users using iOS9(newest), where Android shows their majority using Kitkat and Jellybean(a few generations back).

Versions being used as of Oct 5th, 2015:

Apple iOS Versions

 

Market Share

 

Platform Advantages and Disadvantages

Android

Advantages:
  • Widgets on Home and Lock screen
  • Better application management
  • Interface customization
  • Split-screen multitasking and better support
  • Expandable storage space
  • More diverse device options
  • More testing and backward combatiblility
  • Predominant in Asia
Disadvantages:
  • Different screen and resolutions due to multiple device
  • Quality of applications available in Play Store
  • Software fragmentation

 

iOS

Advantages:

  • Customers willing to pay more on iOS
  • Controlled environment
  • IOS consistent across all Apple devices, easy to update when new versions come out
  • IOS has an easy to use interface

Disadvantages:

  • Closed Platform
  • Approval process to publish

 

there are development costs

Consistent version update

Large US market

 

Things to Think about

 

Startup Fees and Developer Costs

 

Download #   revenue

Apple   100K           100M

Android 175K           60M

 

Q1 2015

 

Are there fees?

 

References

http://www.forbes.com/sites/dougolenick/2015/05/27/apple-ios-and-google-android-smartphone-market-share-flattening-idc/

http://www.greenbot.com/article/2686006/10-android-features-that-still-make-it-still-better-than-ios-8.html

http://thenextweb.com/dd/2015/04/06/apple-ios8-v-android-5-1-which-is-best/

http://mobilecon.info/advantages-and-disadvantages-android-mobile-phone.html#sthash.frMEAcJ1.dpbs

https://dzone.com/articles/major-drawbacks-android

http://www.techrepublic.com/blog/10-things/10-things-i-hate-about-developing-for-android-and-some-workarounds-that-help/

http://www.kinvey.com/blog/2360/what-are-the-pros-and-cons-to-building-an-app-for-ios

https://www.linkedin.com/pulse/20140724091107-158107023-advantages-of-ios-app-development-in-your-business

Simple iOS Application

Creating an iOS Project

  1. Open Xcode
  2. Choose “Create a New Xcode Project”
  3. Select “Single View Application” and click “Next”
  4. Create a product name for the application such as MyFirstApp
    1. Note: Language is set to Swift, and the device is set to Universal.

 

Basic Xcode Navigation

There are three basic panels we will use to create and application:

  • Navigator Area: Panel on the left-hand side that displays a directory of our project and additional navigation features.
  • Editor Area: Panel in the center that shows details of files selected from the Navigator Area.
  • Attribute area:  Panel on the right-hand side that corresponds to things selected in the Editor Area.

Additional details can be found here: https://developer.apple.com/library/ios/recipes/xcode_help-general/Chapters/Recipe.html#//apple_ref/doc/uid/TP40010548-CH9-SW1


 

Layout for First Application

  1. Click Main.storyboard from the Navigator area and the Editor area will show a blank box.
  2. Look at the bottom of the Attribute area. This is your object library, where you can drag and drop different design elements.
    1. Note: When you move an object to your layout a set of blue lines will appear depending on where you move it. This is to help align objects with the layout size.
  3. Drag and drop objects that you want to use for your project. Each object has its own attributes that can be changed. I recommend playing around with the settings.

Here Is An Example of My Layout:

My layout out design.
I used 4 labels, 1 button, 1 switch, and 1 slider.

 

Run Application and Layouts

  1. Launch application/Autolayout
  2. Click the “Run” button, and view your masterpiece!

Wait a minute?!  It doesn’t match! I lined it all up on the blue lines!

Welcome to the challenges of Xcode layout!  I will be the first one to admit that I am still learning the ins and outs of responsive layout, but I will show some things I have discovered through trial & error, and I’ll provide some links to other, more knowledgable designers.

To get started, I have provided an image of the Layout area which is at the bottom of the Editor panel when looking at a storyboard.

Example:
Image of the layout area under editor area of Xcode

 

The right-hand side of Layout area has four icons:

  • Stack: Aligns selected objects into a stacked view. Can change between vertical and horizontal display.
  • Align: Positions selected objects on view controller based on positions on the screen.  Examples include top, bottom, horizontal, vertical.
  • Pin: Adds constraints to selected objects based on fixed area.  Examples include: aspect ratio, and width/height away from another object.
  • Resolve Auto Layout Issues: Fixes any constraints missing or incorrect.  Examples include Add Missing Constraints, Clear Constraints, and Reset to Suggested Constraints (my personal favorite if you are ever lost.)

The center of the layout area controls what size layout to use based on the size of the device.  This defaults to width and height as “any”. This means the layout can be used as a baseline for any device.  If you change the layout size to fit an iPhone, then any constraints added will be explicitly for that layout.  This allows you to build different constraints based on the different devices you are designing.

The left-hand side expands a hierarchy of your layout. Here, you can tweak existing constraints, and see any sort of errors that might show up based on miss aligned constraints.  Any constraints that are highlighted in red mean your layout is not setup correctly. If this happens, I highly recommend going through a few different tutorials on auto layout to find the problem.

Links:

https://www.weheartswift.com/auto-layout-101/

http://www.raywenderlich.com/115440/auto-layout-tutorial-in-ios-9-part-1-getting-started-2

Note: If in doubt choose Add Missing Constraints to help “fudge” what isn’t quite working well.


 

Bringing Our Objects to Life

Our next step is getting our button, switch, and slider to respond based to an action.  The easiest way to setup this interaction is to drag and drop our objects as either an Outlet(variable) or Action(method).

  1. First, select the “Assistant Editor” in the top Toolbar. It looks like a vin-diagram on the top right-hand side of Xcode.
  2. Notice that we now see two editors, make sure that one shows our Main.storyboard and the other shows ViewController.swift.
  3. Example:

    Showing Main.storyboard and viewController.swift

  4. Move your mouse icon over the button we created and while holding the Control key drag the mouse into the ViewController class. When you let go of the mouse you will see a pop-up over the button.
  5. Leave everything the same, add a name for the button, and click Connect. This creates an interface builder with in our code allowing us to call the name of object to access it.
  6. Example:

    Interface builder menu

  7. The button now has a name, but it still needs to do something. We repeat the same drag and drop process, but change the Connection to Action,  create a name for the method, and you can either leave the type as any or change to UIButton.
  8. Example:

    Interface behavior action

  9. Repeat these step for however many additional objects you want to use.
  10. Run your application

Example:

My setup of actions and outlets

Note: In a bigger application I would create classes that contained what onClick, onSwitch, and onSlide would call, but for such small application I put everything into the ViewController.

//
//  ViewController.swift
//  MyFirstApp
//
//  Created by Casey Morris on 10/5/15.
//  Copyright © 2015 Casey Morris. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var myButton: UIButton!
    
    @IBOutlet weak var mySwitch: UISwitch!
    
    @IBOutlet weak var mySlider: UISlider!
    
    @IBOutlet weak var myScore: UILabel!
    
    var clickCounter:Int = 0
    var isDoubled:Bool = false
    
    @IBAction func onClick(sender: UIButton) {
        if(isDoubled == true){
            //Add score and update clickCounter
            // as a String via text method in the label myScore
            clickCounter = (clickCounter++)*2
            myScore.text = String(clickCounter)
            
        }else
        {
            clickCounter++
            myScore.text = String(clickCounter)
        }

    }
    @IBAction func onSwitch(sender: AnyObject) {
        if (mySwitch.on)
        {
            isDoubled = true
        }else
        {
            isDoubled = false
        }

    }
    @IBAction func onSlide(sender: UISlider) {
        //Convert Float value of slider to integer
        let choiceValue:Int = Int(sender.value)
        
        //Array of predefined colors
        let colorsArray = [
            UIColor(red: 90/255.0, green: 187/255.0, blue: 181/255.0, alpha: 1.0), //teal color
            UIColor(red: 222/255.0, green: 171/255.0, blue: 66/255.0, alpha: 1.0), //yellow color
            UIColor(red: 223/255.0, green: 86/255.0, blue: 94/255.0, alpha: 1.0), //red color
            UIColor(red: 239/255.0, green: 130/255.0, blue: 100/255.0, alpha: 1.0), //orange color
            UIColor(red: 77/255.0, green: 75/255.0, blue: 82/255.0, alpha: 1.0), //dark color
            UIColor(red: 105/255.0, green: 94/255.0, blue: 133/255.0, alpha: 1.0), //purple color
            UIColor(red: 85/255.0, green: 176/255.0, blue: 112/255.0, alpha: 1.0), //green color
        ]
        
        myButton.backgroundColor = colorsArray[choiceValue]
        

    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}


Feel free to copy and paste my code, just make sure to link your interface builder objects with my existing outlets and actions.


Additional Links

Basic Android Studio Installation

Things to Check before installing Android Studio

  • Check your current OS requirements (http://developer.android.com/sdk/index.html#Requirements)
  • Make sure you have the newest JDK installed (as of writing this, the newest version is Java SE 8u60)
  • If installing a newer JDK version make sure to uninstall older versions for security purposes

What if I have never installed a Java Development Kit (JDK) before?

  1. First go to Oracle’s download page: http://www.oracle.com/technetwork/java/javase/downloads/index.html
  2. Look for Java SE Development Kit and choose JDK
  3. Find the file that matches your OS, and install software.
javaAgree
Note: Don’t forget to click Accept License Agreement before downloading or you will go nowhere!

Installing Android Studio

  1. Download Android Studio from http://developer.android.com/sdk/index.html
  2. Accept all the license agreements and install
Note: If coming back to Android Studio, you can import previous settings.
Note: If coming back to Android Studio, you can import previous settings.

Installing and updating Android SDK 

Out of the box, Android SDK installs the bare minimum needed to write code. If you want to install or update additional APIs, then Android SDK Manager allows you to do so–and you will want more goodies!

  1. Launch Android Studio and you will see a Quick Start pop-up.
  2. Select SDK Manager and a new window will appear
  3. Click Configure and choose any package you want to install or update
  4. Google recommends putting a check mark next to the following:
      • Android SDK Tools
      • Android SDK Platfrom-tools
      • Android SDK Build-tools
      • SDK Platform
      • ARM EABI v7a System Image (You can choose whatever image you want per emulator testing. I usually install all.)

    Note: Make sure for both Android SDK Build-tools and SDK Platform that you select the newest version.

  5. If you want to code Android Wear, Android TV, or Google Cast, open the Extras directory and select:
    • Android Support Repository
    • Android Support Library
  6. Another recommended package to install is Google Play select:
      • Google APIs
      • Google Play services
      • Google Repository

    Note: Make sure to put a check on Google APIs in the newest Android API.

  7. This is a screen shot of my settings:

mySettings

Additional Links to get Started

Sites:

https://developer.android.com/training/index.html (free site)

http://www.codelearn.org/android-tutorial (free site)

http://developer.android.com/guide/index.html (free site)

https://www.udacity.com/course/developing-android-apps–ud853 (paid site)

http://android-developers.meetup.com/ (What better way to learn than with others in your area!)

What is a Stack?

Virtual memory is a large array of bytes that an operating system allocates to allow a machine-level program to seem like it has private use of main memory. The range of virtual space starts in memory at a low address and can be set to the highest size that the memory can hold. Usually, the space is a lot less, and each process is given a separate address space to use. This helps minimize the chance that memory can be intentionally or unintentionally written over by another process.

Anatomy of Virtual Memory:

Since memory is allocated from the lowest memory range to the highest range, most memory models are drawn from the bottom up. A basic memory model consists of a Text Segment, Initialized Data Segment (Data), Uninitialized Data Segment (BSS), Heap, and Stack. This modal can be more complex, but the following explanations will only focus on the most basic version.

Example of Memory Stack:

Image of a stack

Text Segment:

A text segment, or code segment, contains read-only executable instructions. When the code is executed, the object file is loaded into the text segment of the virtual memory.

Data Segment:

This section of memory contains two types of segments. The first segment is called the Initialized Data Segment. It stores the processes global and static variables that are initialized when code is executed. Data segments can be read-only or read-write. An example of both would be initializing an array[] equal to a string literal that is accessed globally. The string literal, which is a constant, is initialized in the read-only area. The global pointer is stored in the read-write area. The second segment is called the Uninitialized Data Segment or commonly referred to as the “bss”or “block started by symbol”. When a program is executed any variables the kernel has assigned to “null” or variables that were not initialized in the source code are assigned to the BSS segment.

Heap:

A heap starts at the end of the data segment and is used to allocate blocks of memory for a program. The heap is managed by what is called a “heap manager”. In C, you would call a function called malloc() to access the heap. The heap is extremely large compared to the stack, but it can be filled. The heap grows up towards the stack. Libraries and plugins are loaded into the heap.

Stack:

Stack memory is where local variables are stored. In some documentation, local variables are also called automatic variables. They are called automatic variables because the program creating it automatically controls the processes of allocating and de-allocating at the top of the memory region. When a local variable is added to a stack the memory grows down toward the heap. Stacks use a method called Last In First Out (LIFO) which is where the data that was stored last is the first to be removed. An example of LIFO would be pancakes stacked onto each other. They are stacked one on top of the other, from the bottom upwards and in order to reach the bottommost pancake, it is necessary to eat downwards from the top. When a new function is called, the automatic and temporary variables are added to the stack.

Stack and Heap use a pointer register to keep track of the address space available. Since the heap grows towards the stack and the stack grows down towards the heap, the free memory is maxed out once the pointers are the same.

Binary Notation

Binary is a format of ‘1s’ and ‘0s’ that when combined represent information that a computer can read. This information is interpreted by the computer’s processors as a high or low voltage. There are different types of binary notation.  The three most common binary encoding are unsigned, two’s-complement, and floating-point.  I will not go into too much info in this posting on the encodings, but when I have time I will later go into more on two’s-complement and unsigned because they are important things to think about when coding.  The importance of these things comes from the fact that carelessness can accidently cause stack overflowing or malicious intent can intentionally “smash” the stack.  For now, unsigned means a number greater than or equal to 0, two’s-complement or signed is used to represent negative and positive numbers, and floating-point is a scientific notation for real numbers.  These encoding are represented in base-2 where 0 is equal to ‘off’ and 1 is equal to ‘on’.

Example:

Let’s try to convert the number 42 to binary. I think the easiest way to work in binary is to find a power of two that is a little bigger than the number we need.  In this example 2^6 = 64 is bigger than 42. So I start by building a block of binary that are set to ‘0’ or ‘off’ to work with:

Bit(on/off): 0 0 0 0 0 0 0
Decimal Value: 64 32 16 8 4 2 1
Power of 2: 2^6 2^5 2^4 2^3 2^2 2^1 2^0

Once we have our block of binary, we start from left to right and put a ‘1’ for the values we need to equal up to 42.

Bit(on/off): 0 1 0 0 0 0 0
Decimal Value: 64 32 16 8 4 2 1
Power of 2: 2^6 2^5 2^4 2^3 2^2 2^1 2^0

Since we turned ‘on’ the value of 32, we can subtract 42 -32 which gives us our next value to look for which is ten. Ten is not a value in our block of binary, but eight is so we turn on the value again by putting a ‘1’.

Bit(on/off): 0 1 0 1 0 0 0
Decimal Value: 64 32 16 8 4 2 1
Power of 2: 2^6 2^5 2^4 2^3 2^2 2^1 2^0

Again we subtract ten from eight which gives us our next value of 1wo. Luckily two is a value in our block.

Bit(on/off): 0 1 0 1 0 1 0
Decimal Value: 64 32 16 8 4 2 1
Power of 2: 2^6 2^5 2^4 2^3 2^2 2^1 2^0

This makes our binary value of 42 as 0101010.  If you search online, there are many ways to convert to binary and back. In fact, there are sites and apps that will do it for you. I encourage anyone learning to convert to and from binary to practice by hand before getting comfortable using an application. You will get a better understanding of how it works.

Practice/Game: http://forums.cisco.com/CertCom/game/binary_game_page.htm

Welcome!

Welcome to my blog.  I am a software developer, who trying to get out of their comfort zone explaining and writing things. Hence the birth of this blog. So first off I apologize for any and all grammatical errors you find.  If you want, you could make it into a game and see how many I have per post.  I am constantly trying and learning new things, so feel free to leave comments and suggestions on things to learn or work on.  –Casey–