Technology

Code Style with Android

Published by
admin

Introduction

Android is a big platform nowadays and cover almost all segments of society. We can see a variety of products based on the Android platform like Smartphones, Smart Watches and Smart TV, etc. Android is really growing up from cupcake to Android O we gone really intensive open source approach. So we brings Code Style with Android for our readers.

It makes Android very rich in a way of many developers from all over the world contribute their expertise and solve the bugs before the launch of the new version of Android. Many developers contribute in recently development process of Nought and now in Android O.

Exceptions

It can be really painful to ignore exceptions in your code. The code with better exception handling is more stable than without it. You must handle every exception in a principled way,specific cases may want extra code. Don’t catch the generic exception like IO exception, NullPointer exception and ArrayOutOfBound exception instead of these use generic Exception. You can later check what is the specific error by catching the error in that block.

Javadoc Standard Comments

Every file should have Javadoc Standard Comments it can have a copyright declaration, class or interface description. Every method should be well described about what this method can do, what is the its main function. Define fields in Standard places like at the top of the file or immediately before the method declaration.

Set the scope of variable in Code Style with Android

Keeping the scope of variable minimum makes code more readable, maintainable and less error prone. Local variables should declare where they first use.

Follow Variable Naming Conventions

1.Non public and non static fields  start with m.

2.Static fields names start with s.

3.Other field start with s.

4.Public static final fields and constant are ALL_CAPS_WITH_UNDERSCORES.

Use standard braces Style like this

class Sample {
    void method() {
        if (condition) {
            // ...
        }else {
            // ...
        }
    }
}

Each line of text in code should be at most 100 character long.

Use Standard Java Annotations

  • @Override: The @Override annotation must be used whenever a method overrides the declaration or implementation from a super-class. For example, in Android onCreate() method define the parent view of the activity so we override this method with annotation @override..
  • @SuppressWarnings: The @SuppressWarnings annotation should be used only under circumstances where it is impossible to eliminate a warning. If a warning passes this “impossible to eliminate” test, the @SuppressWarnings annotation must be used, so as to ensure that all warnings reflect actual problems in the code.

Code Style with Android Verdict

The Code should be robust and scale-able, it also consists uniform standard throughout the code structure. It will help the development team to easily understand what is the motive of a particular line of code. Stay tuned for more such articles only on The Smart Innovator.

admin

Recent Posts

CERT-IN raise concern over Apple Software!

The Indian Computer Emergency Response Team, or CERT-IN, has flagged multiple vulnerabilities in Apple software…

August 5, 2024

How Netflix recommends Movies & TV show?

Have you ever wondered how Netflix always seems to know exactly what you want to…

July 8, 2024

Mobile World Congress 2024 highlights

Mobile World Congress also known as MWC Barcelona this year is an annual trade show related to…

May 8, 2024

iPhone 15 – All about launch, feature, Price and Availability

Apple has once again captured the world's attention with the unveiling of its latest flagship…

March 23, 2024

How to Delete Instagram and be Productive!

Have you ever experienced that You wanted to do some of your favourite hobby, But…

February 11, 2024

Top 10 Quantum Computing Applications You Need to Know About

Quantum computing is one of the most exciting fields of technology today, promising to revolutionize…

December 9, 2023

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.

Read More