Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts
Sunday, March 11, 2018
Saturday, March 10, 2018
Friday, March 9, 2018
Getting Started with Flutter SDK Introduction with installation and run your first project
In a week ago actually more than a week, Flutter released its first beta version at the MWC in Barcelona In this video I'm gonna quickly explain what is flutter, how you can download and
setting up all you need to build and run your app and getting started with it, build your first android app.
What is Flutter?
Flutter is Google’s mobile UI framework for crafting high-quality native interfaces on iOS and Android in little amount of time. If you are a beginner or developer you can learn it quickly. Flutter works with existing code, is used by developers and organizations around the world, and it is free and open source.
Designed for both new and experienced mobile developers, Flutter can help you build beautiful
and successful apps in record time with benefits such as:
High-velocity development
Expressive and flexible designs
High-quality experiences across devices and platforms
To learn more about visit flutter.io
Flutter uses the programming language called dart. have you ever heard about that language.
I have seen a video in youtube but I didnt intended to watch that. Now with this I am learning that language and it is easy to learn. In this series Im gonna teach you everything from beginner level to advace level in dart.
Anyway, Dart is a modern concise dynamic programming language and it has really cool feature. I'm not going to describee them in this video. Visit the www.dartlang.org website for more info.
And in the future I think this language will be a famous one because of google's new os fuchsia uses this language.
Before installing flutter, install these
git install . check if path set or not and install it as usually you do
android studio
android device connected to your machine or emulator installed and open in your machine.
You do not need to download emmulator if you have installed android Studio. Just run it.
Download and install Flutter
To download install both of these, you have to simple thing that is go to the website. copy the command from flutter.io it is easy to download and install not like installing android studio. make sure you have installed git otherwise this command will not work.
go to the directory, where you want to install flutter. Keep remember, if you have installed this inside windows/system32 you will get an error message when running some
commands(Flutter doctor)
gradlew assembleDebug - Failed to run the Flutter compiler. Exit code: 255
in case if you did this find the installation folder and move it to another location :D. You heard me right that is easy and this will be bad sometimes beacuse if you accidently delete this folder your flutter installation will be disapear. You do not need to do any unstallation.
Flutter SDK
The Flutter SDK includes Flutter’s engine, framework, widgets, tools, and a Dart SDK. So, You do not need to download or install dart.
set path variable - if you type flutter without setting the path variable you will get a message like
Go to installed flutter direcotory and bin directory inside it copy the path and set it to PATH environmental variable
open up the cmd type Flutter to ensure that installation path is correctly added.
basic commands are,
flutter doctor - is a really cool tool that check your system for dependencies see if their any remaining dependencies you need to install.
Now lets see flutter doctor command
lets open the IntelliJ IDEA and add those two plugin
Flutter create project_name - to create a project
flutter help - to see available tools
Flutter devices - this command help you to see what are the connected android devices and running emulators.
Flutter run - to run the project(this command should be run inside the project directory)
create and run your first flutter app
Flutter create demo
cd demo
Flutter devices
Flutter run
(if you have a device connected this command will work otherwise a error message will appear)
Lets run this application using a emulator. First we need to create avd(Android Vertual Devices)
you can do this using Android Studio or using command line.
To create AVD
First go to the android sdk installed directory - tools - bin
then using cmd type
avdmanager create avd -n name -t targetID
target id - API level. Notice: Flutter runs above API level 16 and Android version 4.something above
emulator -list-avds - to list created emulators
emulator -avd name - to run a emulator
You can use
Android Studio
IntelliJ IDE
Atom Editor
Visual Studio Code
and etc.
view source code in IntelliJ. In upcoming videos I will show, how you can use other IDE's
Learn more:
flutter.io
medium.com/flutter-io
codelabs.developers.google.com
hackernoon.com/whats-revolutionary-about-flutter-946915b09514
In the next video I will show you how you can develop your first hello World app from scratch.
Tuesday, March 6, 2018
How to add .csv file data to MySQL through Java
First what is CSV meaning?
What is it?
Why do we need to use a .csv file?
We can create and add data through Microsoft Excel, Google Sheets and many more. But this post not about that but about how to add .csv file data to MySQL through Java program,
Here are the steps:
1. Create a database, table inside it and add fields that we want.
As a example I am going to create a database called Songs and table called Rap. This table contains four fields. Those are id, song_name, artist, relesead_year. MySQL Query as follows:
For database,
CREATE DATABASE Songs
To create table,
CREATE TABLE Rap(
id INT,
song_name VARCHAR(150),
artist VARCHAR(60),
relesead_year DATE
)
I did not add primary key and other things for the sake of simplicity of this post.
2. Create Java project with main class(I am using Eclipse IDE for this but you can use any IDE or notepad. steps are same)
If you are using eclipse go to File -> New -> Java Project. In the pop up window you can find a place to give a name to project. I have named it as AudioLibrary.
Next, right click on the project and go to New -> Class. In this window add the class name as Songs(I know this is not a proper name for this class. You can add a proper name) and package name as com.slcoder.audiolibrary and also make sure to tick the main class checkbox. As shown in the below image,
3. Connect to MySQL database.
Now, we must connect our Java project with MySQL database, otherwise we can not do CRUD(Create, Update and Delete). To connect we need a connector, a MySQL connector JAR(Java Archive). To download go to dev.mysql.com.
Next, right click on the project and create a folder called libs and copy paste the jar file that you have downloaded. Then, expand the libs folder and right click on the jar file and go to Build Path -> Add to buid path.
To ensure that this jar file successfully added to build path, expand and have a look at the Referenced Libraries. JAR file should link to that folder.
If you did not add the jar file to build path, you will get a error message like,
Now we can add java code to the Songs class main method to connect Java with MySQL database. Firstly, we need to
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/Songs", "root", "1234");
By the way, what is the database driver?
JDBC drivers are software libraries(JAR files) that communicate between a Java application and a database. For each and every relational database there are a specific JDBC driver.
Connection is a class actualy it is a interface. con is the object name. getConnection() is a method in the DriverManager class. And getConnection() takes three arguments.
- JDBC connection URL
- username
Second arguement is the username of the user in your database. The default name is root if you have not changed it.
- Password
And the third argument is the password of that user. By default there is no password for root user. Of course you can change it or add another user.
What is JDBC(Java Database Connectivity)?
And the third argument is the password of that user. By default there is no password for root user. Of course you can change it or add another user.
What is JDBC(Java Database Connectivity)?
It is a API(Application Programmable Interface) for connecting to Relational Database.
DriverManager
The DriverManager provides a basic service for managing a set of JDBC drivers. Read more about this class in the doc.
getConnection()
When this method get called DriverManager will attempt to locate a suitable driver. And the responsible of this method is to establish the connection to given url.
4. Create a .csv file for our needs and add some data to it.(If you want to learn how to add data to .csv file through MySQL using java)
Right click on the project or inside the src directory of your project and create a file and give it a name as songsdata.csv. and add some line to that file. When you do that kee remember to separate fields by , and these fields should match with the table fields/columns. As well as number of columns and data type of column.
I am gonna add three lines according to our database table columns as follows,
1,Mocking Bird,Eminem,2004-00-00
2,Dear Mama,2Pac,1995-00-00
3,My Life,The Game,2008-00-00
If there is two many comma separated values, when running your application you will end up with the
Row 1 was truncated; it contained more data than there were input columns
If there is lesser values
Row 1 doesn't contain data for all columns
If data types does not match with the table values or if your
.csv
file is something like- 'a', 'b', '', 'd'
MySQL does not know what to do with the ''
value. So, you will get a error message something like this.Data truncation: Incorrect date value: 'someValue' for column 'aColumn' at row 1
In case if you have not value to add for a field, you can use
NULL
like 'a', 'b', 'NULL', 'd'.
5. Write mysql query to add .csv file data into mysql table.
String sql = "load data local infile 'songsdata.csv' \n" +
" replace \n" +
" into table Rap \n" +
" columns terminated by ',' ";
String sql is the variable name and the value, that variable holds is MySQL query.
"load data local infile is used to load data from a local file. that file is is the 'songsdata.csv' wrapped by single comma and \n use to add new line
+ sign is added because I have devided the String into four lines to take readability in my example. Of course you do like below.
String sql = "load data local infile 'songsdata.csv' \n replace \n into table Rap columns terminated by ',' ";
replace \n will remove all the new lines from .csv file. If you refer the file, you can see we have added as three lines. So from sql query we are remove that line separation.
into table Rap columns terminated by ',' storing into the our table Rap and we have to specify what is the delimiter we are using to seperate fields. In this example it is ',' and you can use pipe-delimiter '|' or tab '\t'.
1|Mocking Bird|Eminem|2004-00-00
or
1 Mocking Bird Eminem 2004-00-00
Above line should use tab key not space. But if you do not change the csv comma separator to what ever delimiter you are using, you will get a error message like
Data truncated for column 'id' at row 1
Now you need two more line. One is
Statement stmt = con.createStatement();
Statement is also a interface and it's responsibility to executing a static SQL statement from the object that provides(in this example con) and returning the results(sql statement that created) it produces to the stmt. Read the doc.
Second one is,
stmt.execute(sql);
Above line use to execute the query. Statement contains a method called execute that takes one argument. Argument is the MySQL query. We can direcly add as a String or as I shown in the example assign into a variable and pass it to execute(). And returns
"load data local infile is used to load data from a local file. that file is is the 'songsdata.csv' wrapped by single comma and \n use to add new line
+ sign is added because I have devided the String into four lines to take readability in my example. Of course you do like below.
String sql = "load data local infile 'songsdata.csv' \n replace \n into table Rap columns terminated by ',' ";
replace \n will remove all the new lines from .csv file. If you refer the file, you can see we have added as three lines. So from sql query we are remove that line separation.
into table Rap columns terminated by ',' storing into the our table Rap and we have to specify what is the delimiter we are using to seperate fields. In this example it is ',' and you can use pipe-delimiter '|' or tab '\t'.
1|Mocking Bird|Eminem|2004-00-00
or
1 Mocking Bird Eminem 2004-00-00
Above line should use tab key not space. But if you do not change the csv comma separator to what ever delimiter you are using, you will get a error message like
Data truncated for column 'id' at row 1
Now you need two more line. One is
Statement stmt = con.createStatement();
Statement is also a interface and it's responsibility to executing a static SQL statement from the object that provides(in this example con) and returning the results(sql statement that created) it produces to the stmt. Read the doc.
Second one is,
stmt.execute(sql);
Above line use to execute the query. Statement contains a method called execute that takes one argument. Argument is the MySQL query. We can direcly add as a String or as I shown in the example assign into a variable and pass it to execute(). And returns
true
if the first object that the query returns is a ResultSet
object.
6. Run the project and explore the database table.
What are the best practices?
What are the best practices?
- Of course we did not close the database connection.
- We can use quotes in our .csv file to avoid unexpected errors or data.
Java EE became Jakarta EE
Even if Oracle handed over the Java EE to the Eclipse foundation, They are refused to give their trademark because of that reason Eclipse Foundation decided to quest to chose brand name. Finally Eclipse Foundation chose two names through some stages. They were "Jakarta EE" and "Enterprise Profile". To choose a best name from these two they started a poll and it is opened until Friday 23rd February 2018.
According to Mike Milinkovich's(executive director of the Eclipse Foundation) blog post says 7,000 people voted in the community poll, Over 64% votes for “Jakarta EE” and for “Enterprise Profile” community votes ended up with 35.6%. This "Jakarta" name came from the Apache Software Foundation. They have used this to Maven, Struts, tomcat and for so many Java open source tools. And of course Apache Software Foundation agreed to give their name to Eclipse Foundation.
With this spin off, Oracle also given below project sources. Table from the Eclipse Foundation.
According to Mike Milinkovich's(executive director of the Eclipse Foundation) blog post says 7,000 people voted in the community poll, Over 64% votes for “Jakarta EE” and for “Enterprise Profile” community votes ended up with 35.6%. This "Jakarta" name came from the Apache Software Foundation. They have used this to Maven, Struts, tomcat and for so many Java open source tools. And of course Apache Software Foundation agreed to give their name to Eclipse Foundation.
With this spin off, Oracle also given below project sources. Table from the Eclipse Foundation.
Old Name | New Name |
Java EE | Jakarta EE |
Glassfish | Eclipse Glassfish |
Java Community Process (JCP) [*] | Eclipse EE.next Working Group (EE.next) |
Oracle development management | Eclipse Enterprise for Java (EE4J) Project Management Committee (PMC) |
Furthermore, This decision not taken by only from Oracle, It was among IBM and Red Hat with Oracle. Oracle decided to spin off Java EE open source foundation to take on the role because it needs to grow up in these days.
I think Oracle moved this not only because they are doing their best to take Java SE to next level but also Eclipse foundation provided so may Java EE tools and Eclipse Foundation is the home for Java EE(according to developers). David Delabassee, said in August 2017 "We believe that moving Java EE technologies including reference implementations and test compatibility kit to an open source foundation may be the right next step, in order to adopt more agile processes, implement more flexible licensing, and change the governance process."
Now developers looking forward to see Eclipse Foundation work for the growth of the Jakarta EE.
Subscribe to:
Posts (Atom)