Unit II
Unit II
Unit II
Native Web App, Benefits of Native App, Scenarios to create Native App, Tools for creating
Native App, Cons of Native App, Popular Native App Development Frameworks, Java &
Kotlin for Android, Swift & Objective-C for iOS, Basics of React Native, Native
Components, JSX, State, Props.
Web Native apps are built utilizing modern web technologies and the web platform while
embracing the full native functionality available on modern mobile devices. Web Native apps
look and feel like other native apps because they fully support the UI patterns of each
platform they run on.
Web Native is a term coined by the Ionic team to characterize the development approach
used when building apps with Capacitor, an open source cross-platform native bridge built
and maintained by the Ionic team. Capacitor is used as the foundation for all apps built with
the Ionic SDK. Capacitor is also a popular choice for web developers building apps outside of
the Ionic ecosystem, using their web-based UI library of choice.
1
Additionally, PhoneGap/Cordova was created in a previous generation of web
technologies where there was not a proliferation of powerful app frameworks or UI libraries
focused on bringing native mobile experiences to the web.
In contrast, Web Native centers around using the full power of modern web
technologies and the ecosystem around them to build high-quality mobile apps utilizing the
full native functionality available on each platform.
Web Native apps do not attempt to abstract away the details of each platform. Rather,
they utilize tools like Capacitor that make it relatively trivial to extend a modern web app
with rich native functionality when necessary.
Web Native apps look and feel like any other native app because they utilize powerful
APIs and native functionality available to them, focus on rich and fluid animations, and fully
match the UI systems native to each platform.
Truly Native
Web Native apps are truly native, in the sense that they are downloaded from the app
stores and installed as an IPA or APK file on a mobile device. They have full access to the
native operating system and can access any native device API. Most Web Native runtimes,
like Capacitor, include a library of prewritten native APIs for accessing common device
functionality. You can also drop into the native platform and write your own custom APIs to
interface with any feature available on the device - the same way as traditional native
development. There is literally nothing that you can’t access so Web Native apps are indeed
truly native.
Truly Web
At the same time, Web Native apps are fully web-based. The UI layer of your Web
Native app executes in a web browser on the mobile device, known as a Web View control.
This means that anything you can do in a web application can be done in a Web Native app.
Want to use ag-grid for data visualization? You can do that in a Web Native app! Have other
web libraries you want to take advantage of? Anything that runs on the web can be
incorporated into a Web Native app. The same goes for web UI libraries like Material UI or
Bootstrap. And if you’d like to customize the look and feel to match your brand colors, fonts,
or other stylings, you can do that easily using the same CSS customizations that you’re
already familiar with. The short story is that if you’re a web developer looking to build
mobile apps, you’ll be right at home using a Web Native approach.
2
Why Web Native?
Native Mobile and Web in One Codebase
Web Native apps embrace the “build once, run everywhere” mantra. Since they are
built using web technologies - aka “web-first” development - this provides the best
opportunity to reach the most platforms.
3
window.Capacitor.Plugins containing every loaded plugin and every known method that
plugin has exported to the Web View.
Finally, the bridge manages message passing and tracking native invocations between
the Web View and the native runtime.
Native Runtime
Calls to native plugins and custom native code are routed from the Web View to the
native runtime. When the Web Native app first starts, the runtime loads any installed plugins
and custom native plugins. The runtime also initializes the Web View and injects the
JavaScript Symbols for all known plugins into the Web View.
When plugins are invoked, the runtime processes each invocation as a message,
constructs a method call to the corresponding plugin, and executes it.
All calls in Capacitor are asynchronous, so the runtime manages a set of “active” calls
that have yet to be completed. These calls might be as simple as calling a Native API, or as
complicated as opening an intent and processing the result of another app (such as the
Camera on Android).
Once those calls are complete, a message is constructed and sent back to the Web
View, which ultimately causes the original plugin call in your app to resolve.
Web UI Layer
The web UI layer runs the web application, consisting of HTML, CSS, and JavaScript. All
visual interactivity, animations/gestures, and UI components are found here. Open source UI
libraries like Ionic Framework are available to make sure the app looks and feels the way you
would expect from a native mobile app, including mobile-optimized navigation, gestures, and
animations.
Accessing Native Device Features
Unsurprisingly, native code needs to be written to access native features. However,
this is abstracted away from the web developer via plugins, packages of code that
communicate with the native platform. The web developer makes calls to JavaScript APIs
exposed by the plugin, and Capacitor executes the underlying native code. Besides the benefit
of not needing to learn the iOS and Android-specific programming languages, Capacitor
seamlessly calls web code when required and native code when available using the exact
same API. As an example, instead of three separate APIs to open a device’s camera
(getPhotoWeb, getPhotoiOS, getPhotoAndroid), it’s just one: getPhoto.
4
Capacitor apps are native apps. The project files used to build the native iOS and
Android binaries are a plain iOS app for Xcode and a plain Android app using Gradle. This
means teams can add arbitrary native code to the app and invoke it from the Web View
through the Capacitor Plugin API. Teams with web and native developers can work alongside
each other, shipping new features faster than ever.
Web View Component
A Web View is a native browser control that is used to display web content. It’s a lightweight
instance due to being chrome-less (standard browser UI shell elements including the address
bar, tabs, and navigation buttons aren’t included). Thus, visually, there’s not much to it - only
the browser engine is available, and the developer decides which content to display to the end
user.
You’ve likely interacted with a Web View and didn’t know it, as they are used in
native apps all the time. Beyond Web Native apps, one common use case is in-app browsing,
where a website is loaded (with limited navigation controls) within the app. This is useful for
content that changes regularly, such as customer support documentation. Teams can update
the documentation at their leisure, and native app users always get the latest information.
Another example is 3rd party authentication, such as logging users in with social media or
various email providers. The user is directed to the 3rd party, signs into that service, then is
redirected back to the native app with only the data needed to securely authenticate them.
Another Web View use case is advertising. Since ads change dynamically based on the user
viewing them, loading them from the web is the easiest way to manage and deploy them.
Deploying to App Stores
Because Web Native apps are normal native apps at the end of the day, the way they
are deployed to the App Stores is just like any other native app. Developers use the native
integrated development environments (IDEs) - Android Studio and Xcode - to build and
compile each native app version. The app files (APK and IPA) are signed with a private key
representing the developer/company, then are uploaded to the app stores. The last mile of app
store deployment is managed within the app store portals, including release management,
marketing and promotional materials, user reviews, and more.
Deploying as a Mobile Web App or PWA
Web Native apps are simply web apps, so normal deployment capabilities and rules
apply. When you’re ready to publish your Progressive Web App and share it with the world,
5
just upload the contents of your web directory (for example, the www/ or build/ folder) to
your hosting provider of choice.
II. SCENARIOS TO CREATE NATIVE APP
6
Android Native App Development:
1. Requirements Gathering:
Define the purpose, features, and target audience of the app.
2. Setup Development Environment:
Install Android Studio: Google's official IDE for Android development.
Familiarize yourself with Java or Kotlin, the primary programming languages for Android
development.
3. Design UI/UX:
Create wireframes and designs using tools like Adobe XD, Sketch, or Figma.
4. Development:
Start coding according to the defined requirements using Java or Kotlin.
Design UI using XML layout files or programmatically.
Utilize Android SDK and frameworks like Android Jetpack, Room, Retrofit, etc.
5. Testing:
Perform unit tests, integration tests, and UI tests using JUnit, Espresso, or Robolectric.
Test on various devices and screen sizes using emulators or physical devices.
6. Debugging and Optimization:
Use Android Studio's debugging tools to identify and fix issues.
Optimize app performance and battery usage.
7. Publication:
Create a developer account on Google Play Console.
Generate signing keys and build release APKs.
Upload the APK and necessary metadata to Google Play Console.
8. Release and Maintenance:
Monitor app performance, reviews, and analytics.
Release updates as needed, addressing user feedback and adding new features.
7
Ionic
jQuery Mobile
Sencha Ext JS
Framework 7
Onsen UI
Unity
Qt-Creator
JetBrains Rider
When you conduct a research to know the top tools for Mobile App Development, you
arrive at these names. Mobile apps need to house several key functionalities so that they
provide businesses with operational efficiencies, drive profitability, improve resource
productivity, and assure consistent performance. All this is achievable with a mobile app
when you build it using the finest mobile app development tools. Let’s take a closer look at
top 11 mobile app development tools using which you can build your dream mobile apps.
1. React Native
A popular JavaScript-based mobile app development framework, React Native is
distinguished by its ability to assist in the simultaneous development of apps for iOS and
Android. While Java and Swift or Obj-C are bare minimum requirements for Android and
iOS respectively. However, React Native uses one common codebase to overcome this
limitation and helps build multi-platform applications.
It was launched in 2015 by Facebook and has continued to grow stronger and stronger
since then. Today, ask any professional software development company, and you would find
it using React Native. It has been used by top names such as Facebook and Uber, which
proves its authenticity as one of the top mobile app development tools.
Why Choose React Native?
Constantly growing community that comprises app developers from esteemed
organizations such as Facebook.
State management, React hooks, and component logic can be reused
For both iOS and Android apps, the code can be effectively reused.
Excellent third-party integration, supporting integration with JavaScript modules and
Native modules, and libraries.
8
Supported by hot and live reloading functionality, developers can execute code
changes in real time.
Gives developers the ability to remain UI-focused during the development process.
2. Flutter
Based on the Dart programming language, Flutter is an open-source SDK (software
development kit) that was developed by Google. Because of its affordability, development
speed, and extensive feature set, Flutter SDK not only satisfies the needs of large
corporations but also seamlessly integrates into the startup environment.
Like React Native, Flutter, too, helps in simultaneously building apps for iOS and
Android, and so is one of the most-used app development frameworks by app developers.
Why Choose Flutter?
Unique feature called ‘Hot reload’ allows developers to render changes fast, making
changes instantly reflect on the UI.
Provides ability to root out bugs in the development cycle itself.
Complex widgets can be developed and adjusted as per the needs of the application.
You can leverage existing Swift, Java, and Objective-C codes to access native
functionalities such as location and camera.
Developers have backend support from Google Firebase that strengthens their
confidence to build scalable apps.
3. Xamarin
There is nothing better than Xamarin to build native apps. Since it is a Microsoft
product, you will always be safe against unexpected termination of service, critical security
threats, and technology updates.
More than 1.4 million developers use Xamarin, which means talent scarcity will not
be a challenge for you when it comes to building your own mobile app development team.
Why Choose Xamarin?
Mono framework that exposes 100% of the native APIs to allow full use of device
capabilities
Platform-specific IntelliSense makes coding easier
Application indexing and deep linking
Easy cycle of build, test, deploy, and repeat using C++ programming language
9
Possible to use enterprise or social authentication, push notifications, offline sync
features
Ability to create high-performance shared libraries.
It’s one of the tools favored by software development companies that build enterprise
apps and software.
4. Ionic
Since Ionic has a complete open-source SDK, it is widely used to build hybrid
applications using CSS, HTML5, and SASS-like technologies. By building a mobile
application on Ionic, app developers can directly send the release update to the users.
Automating app delivery is much easier with Ionic. Equipped with these capabilities,
developers can easily deploy features and fixes to increase the speed of mobile app
development.
10
Excellent support to both high-end as well as less capable devices – those that do not
support JS.
Apps are accessible over a wide range of devices and browsers.
The transition from the currently active page to the new page can be animated using
jQuery Mobile transition events easily
The framework also includes many kinds of simply styled and touch-friendly form
elements.
Ability to determine ownership over application styling, cross-platform widgets, and
Themeroller take UI and Theming to the next level.
6. Sencha Ext JS
Sencha is for rapid mobile app development. If you want to create a native app that is
compatible with the latest versions of iOS and Android, Sencha should be your ideal choice.
It is one of the most suitable app development tools for building enterprise applications..
11
Why Choose Framework 7?
It works in a simple HTML layout attached with CSS framework and JS files
iOS-specific UI elements visualization, animations, and touch interaction
A wide range of ready-to-use UI elements and widgets such as list views, media lists,
modals, popups, form elements, and more
Support iOS swipe-back action from the left border of the screen
Ability to introduce custom styles to your applications
Enhanced video ad experience by partnering with vi (Video Intelligence)
8. Onsen UI
When you want to build Progressive Web Apps (PWAs) and hybrid apps for your
mobile devices, Onsen UI is one tool that must be on the list of your tools. As the name
suggests, it houses a large range of UI components specially for mobile devices.
The best thing about Onsen UI is that developers have the independence to build apps
with or without JavaScript. This framework-agnostic character of Onsen UI makes it a
favorite of mobile app developers.
Why Choose Onsen UI?
Offers an easy learning track, so developers can pick it up fast.
Can be set up very easily, since it is based on HTML, CSS, and JS.
Ready-to-use and easy-to-implement UI components such as toolbar, side menus,
tabs, lists, forms, etc.
No strict rule to install Android SDK or iOS – just begin coding and start building
applications.
Excellent support for command-line tools like Monaca, which helps build hybrid
apps.
Supports integration with AngularJS, React, Vue, and jQuery.
9. Unity
Unity’s fame as a game development app tool is widely acknowledged. Millions of
developers use the Unity game engine to build gaming apps for all kinds of platforms,
including Android, Windows, iOS, etc. Supported by its streamlined workflow and
impeccable user interface (UI), as well as its extensive set of features, it is one of the most
widely used game engines on the Android platform.
12
Even while Unity is primarily designed for building gaming apps, it can be effectively
used to build non-gaming apps for businesses, utilities, etc.
Why Choose Unity?
Quick and easy development support that speeds the app development process
C#-based development that simplifies coding complexities
Excellent code support helps in quickly increasing the app size.
Ability to scale the app to different devices
Optimal performance with large apps
A very powerful community with developers from industry stalwarts such as Disney,
NASA, Ubisoft, Microsoft, Electronic Arts, and Warner Bros.
10. Qt-Creator
A cross-platform IDE (integrated development environment), Qt-Creator offers
various tools for different tasks. For instance, it has a source code editor, a testing tool, an
Integrated GUI layout, and a visual debugging tool for monitoring the app.
Qt is based on a combination of C++, JavaScript, and QML (Qt Modelling
Language), though C++ forms most of Qt. The beauty of Qt is that it is based on the idea of a
custom rendering engine approach that reuses not just the app’s logic but also the UI.
Why choose Qt-Creator?
Quick integration with external SDKs such as AWS and PayPal.
Declarative syntax offers flexibility to compose complex user interfaces
Simple-to-implement property binding approach that simplifies making changes.
Comes with a range of features such as touch-based inputs, shader effects, controls,
and animations.
Powered by C++, developers can interact with native APIs.
Equipped with necessary tools, Qt Quick test framework speeds up testing.
11. JetBrains Rider
Based on IntelliJ Platform and ReSharper, JetBrains Rider is a cross-platform.NET
IDE that is quick and packed with features. It has a thorough understanding of all.NET
languages and technologies, and so is used by millions of developers across the globe.
A fundamental goal of all JetBrains products is to increase developer productivity.
Further, Rider demonstrates its value as a wonderful tool for a software development
company and a business that wants to develop a next-gen mobile app.
13
Why choose JetBrains Rider?
Developers can build .Net, Xamarin, and Unity apps for different platforms.
Rich editing and code insight for various programming languages.
Uses many useful and powerful features of the IntelliJ platform.
Instantly detects errors in compilation and runtime operations.
Promotes optimal design and development methods that minimize redundancy and
enhance coding.
With numerous intelligent navigation and search options, developers may quickly get
to any section of their code.
Rich plugin repository that comes with a wide array of plugins.
Conclusion
Choosing mobile app development tools from a plethora of options available in the
market is tough, only when you are not fully aware of your requirements.
So, before you venture out to seek the best mobile application development tool for
your project, create a set of your requirements and compare it with the features of the
tools.Whether you are looking to build cross-platform app with Flutter or a .NET application
development company with expertise in Xamarin, or native apps using Java app development
or iOS, Besides, you can always consult a reliable mobile app development company to better
understand the tools.
14
Impact: For businesses or startups with limited budgets, native app development may pose
financial challenges. It may require more significant investment upfront, potentially affecting
the overall project budget and ROI.
3. Longer Development Time:
Cons: Building native apps for multiple platforms requires separate development efforts,
resulting in longer development cycles. Each platform has its own set of design guidelines,
APIs, and development processes, leading to increased complexity and time requirements.
Impact: Longer development times can delay the app's launch, impacting time-sensitive
projects or market opportunities. It may also increase the risk of competitors launching
similar apps ahead of schedule.
4. Limited Audience Reach:
Cons: Native apps are platform-specific, meaning they can only run on the operating systems
for which they were developed (iOS or Android). This limits the potential audience reach
compared to cross-platform or web apps, which can be accessed across multiple devices and
platforms.
Impact: Businesses targeting a diverse audience may need to develop separate native apps
for each platform to reach all users effectively. This increases development costs and
maintenance efforts, especially for smaller businesses or startups.
5. App Store Approval Process:
Cons: Submitting native apps to app stores (e.g., Apple App Store, Google Play Store)
requires adherence to strict guidelines and review processes. Apps must comply with
platform-specific policies regarding content, functionality, security, and user privacy.
Impact: The app store approval process can introduce delays in releasing updates or new
features. Apps that fail to meet the guidelines may be rejected or removed from the app store,
requiring developers to make revisions and resubmit, further extending the timeline.
6. Updates and Maintenance:
Cons: Maintaining multiple native apps requires ongoing updates, bug fixes, and
compatibility testing for each platform. This can be challenging and time-consuming,
especially as new OS versions, devices, or hardware features are introduced.
Impact: Continuous maintenance and support are essential to ensure optimal performance,
security, and user experience. Neglecting updates or failing to address compatibility issues
may result in user dissatisfaction, negative reviews, and loss of market share.
15
V. JAVA AND KOTLIN FOR ANDROID
Introduction:
Official Language: Java was the first official programming language for Android app
development, supported by Google's Android SDK (Software Development Kit).
Mature Ecosystem: Java has a mature ecosystem with extensive documentation, libraries, and
community support, making it well-suited for building complex and feature-rich Android
apps.
Performance: Java offers good performance on Android devices, and developers have fine-
grained control over memory management and system resources.
Interoperability: Java code can easily interact with Android's native APIs and libraries,
allowing developers to access device features like camera, sensors, and GPS.
Platform Independence: While Android runs Java bytecode on its Dalvik or ART virtual
machines, developers write code in Java, which can be compiled to bytecode and executed on
any platform with a compatible JVM.
Rich Standard Library: Java comes with a rich standard library that provides classes and
methods for common programming tasks such as input/output, networking, data structures,
and more.
Exception Handling: Java has robust exception handling mechanisms, allowing developers
to handle errors and exceptions gracefully, which is crucial for building stable and reliable
Android apps.
Garbage Collection: Java features automatic garbage collection, which manages memory
allocation and deallocation, simplifying memory management for developers.
Development Tools:
Android Studio: Android Studio is the official Integrated Development Environment (IDE)
for Android app development. It provides advanced features like code completion,
debugging, and project management tailored specifically for Android development.
16
SDK Tools: The Android SDK includes tools for compiling, debugging, and packaging
Android apps. Developers use tools like ADB (Android Debug Bridge), SDK Manager, and
AVD Manager for various development tasks.
Android App is mostly developed in JAVA language using Android SDK (Software
Development Kit). Other languages like C, C++, Scala etc. can also be used for developing
Android App, but JAVA is most preferred and mostly used programming language for
Android App Development. So if you are a beginner in Android then JAVA language and
complete knowleadge of OOPS concepts is the first thing you need to learn before beginning
Android Development.
Introduction To JAVA
JAVA application runs on JVM (JAVA Virtual Machine) but Android has it’s own
virtual machine called Dalvik Virtual Machine (DVM) optimized for mobile devices.
Eclipse:
Being a JAVA programmer you will need some tools or software to code and run it.
Lots of tools are available over the web but we recommend you to use Eclipse for learning
JAVA since it is the most common tool used for Android Development alongwith Android
Studio. So getting habitual with Eclipse and its shortcuts will be bonus in your Android
journey. Other then Eclipse you can also prefer IntelliJ or netbeans for learning JAVA.
Android Studio? Are you thinking of using Android Studio for learning JAVA? Then
Android Studio is solely meant for Android programming. IntelliJ, Eclipse and Netbeans are
for real Java codings.
VARIABLES:
While creating variables in JAVA we need to assign two things. First is the type of
information we want to store and second is the name of the variable. Below is an example of
variable where int is a type of information (integer in this case) and x is the name:
17
Object-Oriented Language: Java is an object-oriented programming language,
which means it revolves around the concept of classes and objects. Everything in Java is
either a class or an object.
Main Method: Every Java program starts with a main method, which serves as the
entry point for the program. In Android, the main method is not explicitly used; instead, the
entry point for the app is the onCreate() method of the main activity.
Classes and Objects: Classes are blueprints for objects. They define the properties
(fields) and behaviors (methods) of objects. You can create instances of a class, called
objects, and work with them.
Packages: Java classes are organized into packages. Packages help in organizing your
code and avoiding naming conflicts. In Android, packages are used to organize components
of an app.
Variables and Data Types: Java supports various data types, including int, float,
double, boolean, etc. Variables are used to store data of a specific type. Android developers
often work with data types such as Strings, integers, floats, etc., to manage application data.
Control Flow Statements: Java supports control flow statements like if-else, switch-
case, loops (for, while, do-while) to control the flow of execution in a program. These are
used extensively in Android programming to make decisions and iterate through data
structures.
Inheritance and Polymorphism: Java supports inheritance, where a class can inherit
properties and behaviors from another class. Polymorphism allows objects of different classes
to be treated as objects of a common superclass.
Exception Handling: Java provides mechanisms for handling errors and exceptions
gracefully. This is crucial in Android development to ensure the stability of the app, as
unexpected errors can occur during runtime.
Collections Framework: Java provides a rich set of data structures through its
Collections Framework, including lists, sets, maps, etc. These are extensively used in
Android development for managing and manipulating data efficiently.
18
Example:
// MainActivity.java
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;
@Override
super.onCreate(savedInstanceState);
textView.setText("Hello, World!");
We override the onCreate method, which is called when the activity is first created.
Inside onCreate, we call setContentView to set the layout for the activity. The layout
is defined in an XML file (activity_main.xml), which typically resides in the res/layout
directory of the Android project.
Finally, we set the text of the TextView to "Hello, World!" using the setText method.
19
To accompany this code, you would also need to define the layout in an XML file named
activity_main.xml. Here's an example of what that XML might look like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textStyle="bold"
android:layout_centerInParent="true"
</RelativeLayout>
This XML layout file defines a RelativeLayout containing a single TextView with the
id textView, which will be used to display the "Hello, World!" message.
Since Android took the world by storm, developers have had few alternatives to Java
for app development. Java was the programming language that the most advanced phones
were using to run their native apps on their proprietary operating systems. For example,
Nokia’s Symbian had Java ME apps. Although its usage is widespread, Java comes with a lot
of historical baggage.
Java 8 solved some language issues and even more were corrected with Java 9 and 10.
Unfortunately, you have to set the minimum SDK to Android 24 to use all of Java 8’s
features, which isn’t an option for many developers. The fragmentation of the Android
20
ecosystem makes it impossible to leave out users with older devices. For most developers,
Java 9 and 10 aren’t even on the radar.
Kotlin is the modern programming language solution for Android. There are a few
things that make Kotlin a great fit for Android:
Compatibility: It’s compatible with JDK 6, so older devices aren’t left behind.
Performance: It’s on par with Java.
Interoperability: It’s 100% interoperable with Java including annotations.
Footprint: The runtime library for Kotlin is tiny.
Compilation Time: There’s a little overhead on clean builds but it’s way faster with
incremental builds.
Learning Curve: It’s easy to learn, especially for people used to modern languages. The Java
to Kotlin converter in IntelliJ and Android Studio makes it even easier. You can also use a
mix of Kotlin and Java in a project, so take your time learning Kotlin and add it in when you
feel comfortable.
While Java 8 is now supported on recent Android releases, recent developer surveys say that
Kotlin is gaining ground. The Realm team notes that ”Kotlin is about to change the whole
Android ecosystem.” Kotlin is now one of the most loved programming languages out there.
It’s poised to dominate Android app development. Above all, it’s a new language! What
could be more exciting? iOS developers had their fun in 2014 with Swift. Now, it’s your turn.
:]
Getting Started
For this tutorial, you’ll explore Kotlin by working with an app that allows users to
search for books, see book covers and share books with friends.
Download the materials using the Download Materials button at the top or at the
bottom of this page. Extract and open the starter project in Android Studio 3.3 or later.
MainActivity.java: An Activity that displays the screen for searching and displaying a list
of books.
DetailActivity.java: An Activity that displays the book cover for the ID passed to it.
JSONAdapter.java: A custom BaseAdapter that transforms a JSON object into a list view
item.
fun main()
{
println("Hello Geeks");
}
/* Java Code */
class Book {
private String title;
private Author author;
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
public Author getAuthor()
22
{
return author;
}
public void setAuthor(Author author)
{
this.author = author;
}
}
But in Kotlin only one line used to define the above class –
/* Kotlin Code */
data class Book(var title:String, var author:Author)
3. Concise – It drastically reduces the extra code written in other object-oriented
programming languages.
4. Safe – It provides the safety from most annoying and irritating
NullPointerExceptions by supporting nullability as part of its system.
Every variable in Kotlin is non-null by default.
5. String s = "Hello Geeks" // Non-null
If we try to assign s null value then it gives compile time error.So,
s = null // compile time error
To assign null value to any string string it should be declared as nullable.
String nullableStr? = null // compiles successfully
length() function also disabled on the nullable strings.
6. Interoperable with Java – Kotlin runs on Java Virtual Machine(JVM) so it is
totally interoperable with java. We can easily access use java code from kotlin and kotlin
code from java.
7. Functional and Object Oriented Capabilities – Kotlin has rich set of many useful
methods which includes higher-order functions, lambda expressions, operator
overloading, lazy evaluation, operator overloading and much more.
Higher order function is a function which accepts function as a parameter or returns a
function or can do both.
Example of higher-order function –
fun myFun(company: String,product: String, fn: (String,String) -> String): Unit {
23
val result = fn(company,product)
println(result)
}
24
Kotlin is multi-platform – Kotlin is supported by all IDEs of java so you can write
your program and execute them on any machine which supports JVM.
It’s much safer than Java.
It allows using the Java frameworks and libraries in your new Kotlin projects by
using advanced frameworks without any need to change the whole project in Java.
Kotlin programming language, including the compiler, libraries and all the tooling is
completely free and open source and available on github. Here is the link for
Kotlin is a statically typed programming language that runs on the Java Virtual Machine
(JVM) and can be used for Android app development. It was developed by JetBrains and
officially supported by Google as a first-class language for Android development. Kotlin is
concise, expressive, and interoperable with Java, making it an excellent choice for building
Android apps.
Here are the basics of Kotlin:
Null Safety: Kotlin addresses the notorious NullPointerException (NPE) issue by
making all types non-nullable by default. If you want to allow null values, you must
explicitly declare a variable as nullable.
Extension Functions: Kotlin allows you to extend existing classes with new
functionality without inheriting from them. This is achieved using extension functions.
Smart Casts: Kotlin's type system includes smart casts, which eliminate the need for
explicit casting when checking types.
Data Classes: Kotlin provides a concise way to create classes that are only meant to
hold data. These data classes automatically generate equals(), hashCode(), toString(), and
copy() methods.
Coroutines: Kotlin introduced coroutines to handle asynchronous programming.
Coroutines simplify asynchronous code by providing a structured way to write asynchronous
code sequentially.
25
Immutable Collections: Kotlin provides immutable collections such as List, Set, and
Map by default. These collections cannot be modified after creation, which helps prevent
unexpected changes.
Interoperability with Java: Kotlin is fully interoperable with Java, meaning you can
use Kotlin code in existing Java projects and vice versa. This makes migration from Java to
Kotlin or mixing both languages in a project seamless.
Native Components
React Native provides a set of built-in components that map directly to native UI components
on iOS and Android. These components allow you to create a native look and feel for your
mobile applications. Some of the key native components in React Native include:
1. View: The View component is like a <div> in web development. It is a container that
supports layout with flexbox, style, touch handling, and accessibility controls.
2. Text: The Text component is used to display text in your app. It supports nesting,
styling, and text manipulation.
3. Image: The Image component is used to display images in your app. It supports
various image sources, resizing, and caching.
33
4. TextInput: The TextInput component is used to accept user input. It supports single-
line and multi-line inputs, as well as secure text entry for passwords.
5. ScrollView: The ScrollView component is used to create scrollable content. It
supports vertical and horizontal scrolling, as well as pull-to-refresh and paging.
6. FlatList and SectionList: These components are used to render lists of data. FlatList
is a simple list, while SectionList supports section headers.
7. TouchableOpacity: The TouchableOpacity component is used to provide touchable
feedback to users. It provides a visual effect when the user touches it.
8. ActivityIndicator: The ActivityIndicator component is used to show a loading
indicator while content is loading.
9. Modal: The Modal component is used to present content modally over the rest of the
application.
10. TouchableHighlight and TouchableWithoutFeedback: These components are used
to provide custom touch feedback to users.
In React Native, JSX, state, and props work similarly to how they work in React for web.
Here's a brief overview of each:
1. JSX (JavaScript XML): JSX is a syntax extension for JavaScript that allows you to
write HTML-like code within your JavaScript files. It provides a way to describe the UI
components of your application. JSX gets compiled into regular JavaScript function calls that
create React elements.
Example:
import React from 'react';
import { Text, View } from 'react-native';
34
export default App;
State: State is a built-in feature in React that allows components to manage their own data.
State is mutable and can be updated using the setState method. State should be used for data
that can change over time and affects the component's rendering.
Example:
import React, { useState } from 'react';
import { Text, Button, View } from 'react-native';
STATE example
State
Definition: State is a built-in feature in React that allows components to manage their
own data. It is mutable and can be updated using the setState method.
When to Use State: Use state for data that can change over time and affects the
component's rendering.
Here's a simple example of using state in a React Native component. This example creates a
counter component that allows the user to increment and decrement a counter value:
import React, { useState } from 'react';
import { View, Text, Button, StyleSheet } from 'react-native';
Here's a simple example of using props in React Native. This example creates a Greeting
component that takes a name prop and displays a greeting message:
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
const Greeting = ({ name }) => {
return (
<View style={styles.container}>
<Text style={styles.text}>Hello, {name}!</Text>
</View>
);
};
const App = () => {
return (
<View style={styles.container}>
<Greeting name="Alice" />
40
<Greeting name="Bob" />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#f0f0f0',
},
text: {
fontSize: 24,
fontWeight: 'bold',
color: 'blue',
},
});
export default App;
In this example, the Greeting component takes a name prop and uses it to display a
personalized greeting message. The App component renders two Greeting components with
different names ("Alice" and "Bob"), demonstrating how props can be used to pass data from
a parent component to a child co mponent.
41