Uploaded March 2013 | Updated November 2026, 3 hours ago
Demonstration on posting data to a application server using Android. Server is a sample Google AppEngine web server (demoprojectserver1234.appspot.com/). Full code below. Previous tutorial: youtube.com/watch?v=kJY4SJ3IgGk
package ca.demo.projectserverviewer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
/**
* Simple activity to demonstrate sending data to the app-server.
*/
public class SimplePostActivity extends Activity {
private static final String TAG = "PostActivity";
public static final String SERVER_URL = "demoprojectserver1234.appspot.com/";
public static final String POST_FILE = "post.cgi";
public static final String POST_URL = SERVER_URL + POST_FILE;
private static final String POST_OPTION_APPID = "appid";
private static final String POST_OPTION_ITEMID = "itemid";
private static final String POST_OPTION_DATA = "data";
private static final String MY_APPID = "3fa19507-c746-4dfa-8ded-ec60ef4d30d9";
private static final String MY_ITEMID = "112233";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_simple_post);
}
public void onClick_PostData(View v) {
TextView textView = (TextView) findViewById(R.id.txtDataEntry);
String data = textView.getText().toString();
postDataToServer(MY_APPID, MY_ITEMID, data);
// String uniqueItemId = UUID.randomUUID().toString();
// postDataToServer(MY_APPID, uniqueItemId, data);
}
// ------------- Post Changes to Server -----------------------
// Source: androidsnippets.com/executing-a-http-post-request-with-httpclient
private void postDataToServer(String appId, String itemId, String data) {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(POST_URL);
try {
// Setup data:
// TODO:- Change the [[ and ]] to the less-than and greater-than (YouTube limit)
List[[NameValuePair]] nameValuePairs = new ArrayList[[NameValuePair]]();
nameValuePairs.add(new BasicNameValuePair(POST_OPTION_APPID, appId));
nameValuePairs.add(new BasicNameValuePair(POST_OPTION_ITEMID, itemId));
nameValuePairs.add(new BasicNameValuePair(POST_OPTION_DATA, data));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post
HttpResponse response = client.execute(post);
int status = response.getStatusLine().getStatusCode();
Log.i(TAG, "Post request finished with a status of: " + status);
Toast.makeText(this, "Post completed w/ status: "+status, Toast.LENGTH_LONG).show();
} catch (ClientProtocolException e) {
Log.e(TAG, "Unable to post (protocol): ", e);
} catch (IOException e) {
Log.e(TAG, "Unable to post (IOException): ", e);
}
}
}
Demonstration on posting data to a application server using Android. Server is a sample Google AppEngine web server (demoprojectserver1234.appspot.com/). Full code below. Previous tutorial: youtube.com/watch?v=kJY4SJ3IgGk
package ca.demo.projectserverviewer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
/**
* Simple activity to demonstrate sending data to the app-server.
*/
public class SimplePostActivity extends Activity {
private static final String TAG = "PostActivity";
public static final String SERVER_URL = "demoprojectserver1234.appspot.com/";
public static final String POST_FILE = "post.cgi";
public static final String POST_URL = SERVER_URL + POST_FILE;
private static final String POST_OPTION_APPID = "appid";
private static final String POST_OPTION_ITEMID = "itemid";
private static final String POST_OPTION_DATA = "data";
private static final String MY_APPID = "3fa19507-c746-4dfa-8ded-ec60ef4d30d9";
private static final String MY_ITEMID = "112233";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_simple_post);
}
public void onClick_PostData(View v) {
TextView textView = (TextView) findViewById(R.id.txtDataEntry);
String data = textView.getText().toString();
postDataToServer(MY_APPID, MY_ITEMID, data);
// String uniqueItemId = UUID.randomUUID().toString();
// postDataToServer(MY_APPID, uniqueItemId, data);
}
// ------------- Post Changes to Server -----------------------
// Source: androidsnippets.com/executing-a-http-post-request-with-httpclient
private void postDataToServer(String appId, String itemId, String data) {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(POST_URL);
try {
// Setup data:
// TODO:- Change the [[ and ]] to the less-than and greater-than (YouTube limit)
List[[NameValuePair]] nameValuePairs = new ArrayList[[NameValuePair]]();
nameValuePairs.add(new BasicNameValuePair(POST_OPTION_APPID, appId));
nameValuePairs.add(new BasicNameValuePair(POST_OPTION_ITEMID, itemId));
nameValuePairs.add(new BasicNameValuePair(POST_OPTION_DATA, data));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post
HttpResponse response = client.execute(post);
int status = response.getStatusLine().getStatusCode();
Log.i(TAG, "Post request finished with a status of: " + status);
Toast.makeText(this, "Post completed w/ status: "+status, Toast.LENGTH_LONG).show();
} catch (ClientProtocolException e) {
Log.e(TAG, "Unable to post (protocol): ", e);
} catch (IOException e) {
Log.e(TAG, "Unable to post (IOException): ", e);
}
}
}





![Run Java from Jar: IntelliJ Terminal
How to run a Java program from IntelliJs built-in command line by using a Jar. Demos importing GSON library as an external Maven dependency to show power of a Jar file.
1. New project MyProjectName
Create package
Create MyMain class with main()
2. Setup GSON object
File Project Structure
Libraries (on left)
Click the green +
Select From Maven
Enter: com/google/code/gson:gson:2.8.2
3. Basic main()
public static void main(String[] args) {
// Use GSON:
Gson gson = new Gson();
for (String s : args) {
System.out.println(Args: + s);
}
}
RUN via IntelliJ:
3. Setup JAR
file project structure
artifacts (on left)
green + for new artifact
jar from modules with dependencies
pick the module to use [default likely OK]
choose the main class
4. Command line
java -jar out/artifacts/MyProjectName_jar/MyProjectName.jar Hello world! Run Java from Jar: IntelliJ Terminal](https://i.ytimg.com/vi/YwohEBqglY0/mqdefault.jpg)



![CLion under Linux: Install & Run
Demo of installing CLion IDE (for C/C++ programming) under Linux (specifically Ubuntu).
To run clion.sh from a terminal
(if double-clicking on the icon fails):
[1] Press the Windows key to open up the menu in the top-left corner of Ubuntu.
[2] type terminal; run it.
[3] Enter the commands:
cd clion-2016.2.2
cd bin
./clion.sh
- Change the clion-2016.2.2 to match the folder name you extracted)
- That ./ is important in the final command.
- This should launch the installer.
For a video on installing VMWare Player and creating an Ubuntu VM, see http://youtu.be/TXGREvxPbL4
Topics:
- Downloading latest Clion installer via a browser
- Running installer via GUI
- Creating C++ Hello World project in CLion
- Import multiple existing C++ files.
- Excluding files from the build.
If double clicking on clion.sh shows you the contents, then right-click and select Open With, then Other Applications... and click View All Applications and select Run Software. CLion under Linux: Install & Run](https://i.ytimg.com/vi/_fs0P7qoQKg/mqdefault.jpg)
