Learn different technologies online for free . you will easily find out lots of tutorials books of different technologies . You can search for your favorites .You can contact us if you have a question or want to report any problems. You can add comments to the site and ask questions to get help.

 

 

What is Queue?

Queues are dynamic collections which have some concept of order. This can be either based on order of entry into the queue - giving us First-In-First-Out (FIFO) or Last-In-First-Out (LIFO) queues. Both of these can be built with linked lists: the simplest "add-to-head" implementation of a linked list gives LIFO behaviour. A minor modification - adding a tail pointer and adjusting the addition method implementation - will produce a FIFO queue.

Queue Implementation

package queue

import java.util.Scanner;

public class Queue {

int[] arr = new int[10];
int a = -1;
int b=0;
public void enqueue(int i){

if(a==9){

System.out.println("Queue is full");

}

else
arr[++a]=i;

}
public void dequeue(){

if(a>b){

for(b=0; b

arr[b]=arr[b+1];

}
a--;
b=0;
}

}

public void display(){

for(int i=0; i<=9; i++){

System.out.println("values at index "+i+":"+arr[i]);

}

}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
Queue q = new Queue();
int var = -1;
while( var !=0 ){

System.out.println("1. Insert item in queue");
System.out.println("2. Delete item from queue");
System.out.println("3. Display Queue");
System.out.println("0. Exit");
var = sc.nextInt();
switch(var){

case 1:
System.out.print("Enter item in Queue: ");
int pushItem = sc.nextInt();
q.enqueue(pushItem);
break;
case 2:

q.dequeue();
break;
case 3:
q.display();
break;
}
}

}
}

In this tutorial , i will teach you about a database connectivity with mysql database using java programming language.

As java is a object oriented programming language so the best approach to follow is :

1. Make a individual package for a database.

1.1 In this package create a class for database connectivity.

2. Make a individual packages for each of tables in a database.

2.1 In each of package make a bean class of a particular table.

2.2 Make a class for a task which you want to do. (e.g Selection , insertion etc ).

The following code is for a database connectivity with mysql refer to step 1 and 1.1

 DatabaseConnection.java

package database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;
public class DatabaseConnection {

public static Connection con;

public static void init() throws Exception{
String JDBC_DRIVER   = "com.mysql.jdbc.Driver";
String JDBC_URL      = "jdbc:mysql://localhost:3306/test";
String JDBC_USER     = "root";
String JDBC_PASSWORD = "";

Class.forName(JDBC_DRIVER);
con = (Connection)
DriverManager.getConnection(JDBC_URL,JDBC_USER,JDBC_PASSWORD);
System.out.println("Driver Loaded Sucessfully");

}//end init
}

now i want to fetch record so i follow the step no 2.

for example create EmployeeBean.java class. In a bean class we have only setters and getter of a properties.

package employee;
public class EmployeeBean {
private int emp_id;
private String emp_name;
private String emp_fname;
private String emp_surname;

public int getEmp_id() {
return emp_id;
}
public void setEmp_id(int emp_id) {
this.emp_id = emp_id;
}
public String getEmp_name() {
return emp_name;
}
public void setEmp_name(String emp_name) {
this.emp_name = emp_name;
}
public String getEmp_fname() {
return emp_fname;
}
public void setEmp_fname(String emp_fname) {
this.emp_fname = emp_fname;
}
public String getEmp_surname() {
return emp_surname;
}
public void setEmp_surname(String emp_surname) {
this.emp_surname = emp_surname;
}

@Override
public String toString(){
return emp_name;
}

}

use following where you want to perform database operations.

class EmpData{

public  Vector<EmployeeBean> getAllEmployees() throws SQLException{
String query = "SELECT emp_id, emp_name, emp_fname, emp_surname FROM employee";

Statement ps = null;
ResultSet rs = null;
Vector<EmployeeBean> vector = new Vector<EmployeeBean>();
try{
ps = (Statement)database.Mysqlstudent.con.createStatement();
rs = ps.executeQuery(query);
while(rs.next()){
EmployeeBean bean = new EmployeeBean();
bean.setEmp_id(rs.getInt("emp_id"));
bean.setEmp_name(rs.getString("emp_name"));
bean.setEmp_fname(rs.getString("emp_fname"));
bean.setEmp_surname(rs.getString("emp_surname"));
vector.add(bean);
}//end while loop
}finally{
if(ps != null) ps.close();
if(rs != null) rs.close();
}

return vector;

}//end getEmployees

}

and use it by creating a object of Empdata where we requires it. Like,

Empdata data = new Empdata();

Vector<EmployeeBean> vect = data.getAllEmployees();

so in vect variable you get all record of employees.

Serialization is the process of converting an object into a stream of bytes in order to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.

So we are going to learn that , how we doing serialization in Java.

Lets start...

i m going to create a class person named as Person which implements Serilizable interface.

Serializability of a class is enabled by the class implementing the java.io.Serializable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable.

Person.java
package serialization;

/**
*
* @author Maria
*/
import java.io.Serializable;
public class Person implements Serializable {

private String firstname;
private String lastname;
person(String firstname,String lastname){

this.firstname = firstname;
this.lastname = lastname;

}

/**
* @return the firstName
*/
public String getFirstname() {
return firstname;
}

/**
* @param firstname the firstName to set
*/
public void setFirstname(String firstname) {
this.firstname = firstname;
}

/**
* @return the lastName
*/
public String getLastname() {
return lastname;
}

/**
* @param lastname the lastName to set
*/
public void setLastname(String lastname) {
this.lastname = lastname;
}

}

In above class we have a setters and a getters of a serialiable class.

And now we have a main class in which we create the objects of Person class so we can use our serialized class.

Main.java 

package serialization;

/**
*
* @author  Maria
*/
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Main {

public static void main(String args[]) throws FileNotFoundException, IOException, ClassNotFoundException{

FileInputStream fis;
FileOutputStream fos;
ObjectInputStream ois;
ObjectOutputStream oos;

String filename = "p.ser"; // creating a file named as p and .ser is extension for serlizable file
person p = new person("maria","soomro");

fos = new FileOutputStream(filename);
oos = new ObjectOutputStream(fos);
oos.writeObject(p);

}
}

In Above Main.java class ,  the main methods throws some exceptions. ObjectOutputStream used for writing  object through writeObject  method.

When i run this main class the p.ser class is created

Serialization

Serialization

and for deserialization you have to write following code in calling class like in our example a Main class inside main method.

fis = new FileInputStream(filename);
ois = new ObjectInputStream(fis);
person pe = (person)ois.readObject();

System.out.println(pe.getFirstname());
System.out.println(pe.getLastname());
ObjectInputStream used for reading object through readObject method.

Output is :

Serialization

Serialization

 

 

 

 

 

 

 

 

1 Comment

Android L

Android L

New Android Runtime (ART)

The 4.4 release introduced a new, experimental Android runtime, ART. Under 4.4, ART was optional, and the default runtime remained Dalvik. With the L Developer Preview, ART is now the default runtime.Most Android apps should just work without change under ART. However, some techniques that work on Dalvik do not work on ART.

If your app implements notifications...

Notifications are drawn with dark text atop white (or very light) backgrounds to match the new material design widgets. Make sure that all your notifications look right with the new color scheme:

  • Update or remove assets that involve color.
  • The system automatically inverts action icons in notifications. Use android.app.Notification. Builder.setColor() to set an accent color in a circle behind your icon image.
  • The system ignores all non-alpha channels in action icons and the main notification icon. You should assume that these icons are alpha-only.

If your app uses RemoteControlClient...

Instead, your app can provide media playback control from the lockscreen through a notification. This gives your app more control over the presentation of media buttons, while providing a consistent experience for users across the lockscreen and unlocked device.

User Interface

  • Material design support
  • Lockscreen notifications
  • Notifications metadata
  • Concurrent documents and activities in the Recents screen
  • WebView updates

Multiple network connections

The L Developer Preview provides new multi-networking APIs. These let your app dynamically scan for available networks with specific capabilities, and establish a connection to them. This is useful when your app requires a specialized network, such as an SUPL, MMS, or carrier-billing network, or if you want to send data using a particular type of transport protocol.

Bluetooth broadcasting

Android 4.3 introduced platform support for Bluetooth Low Energy (BLE) in the central role. In the L Developer Preview, an Android device can now act as a Bluetooth LE peripheral device. Apps can use this capability to make their presence known to nearby devices. For instance, you can build apps that allow a device to function as a pedometer or health monitor and communicate its data with another BLE device.

The new android.bluetooth.le APIs enable your apps to broadcast advertisements, scan for responses, and form connections with nearby BLE devices. You must add the android.permission.BLUETOOTH_ADMIN permission in your manifest in order for your app to use the new advertising and scanning features.

Developer tools for power measurement

The L Developer Preview provides several new developer tools and APIs to help you better measure and understand your app's power usage.

batterystats
The dumpsys batterystats command allows you to generate interesting statistical data about battery usage on a device, organized by unique user ID (UID). The statistics generated by the tool include:

  • History of battery related events
  • Global statistics for the device
  • Approximated power use per UID and system component
  • Per-app mobile ms per packet
  • System UID aggregated statistics
  • App UID aggregated statistics

 

1 Comment

Surface Pro 3 The tablet that can replace your laptop.

Surface Pro 3
The tablet that can replace your laptop

Microsoft recently unveiled the Surface Pro 3, a super-light tablet the company says will replace your laptop. The Surface Pro 3 features a 12-inch screen and is capable of running PC applications as well as acting like a traditional tablet, depending on the situation or project.

It’s impressive at merely 800 grams and 9.1 mm thick and an optional magnetically attachable keyboard for ease of use. The Surface Pro 3 starts at a $799 price tag.

 

Apple Swift

Apple Swift

Apple announced  that it has developed a successor to its venerable Objective C with a language it's calling Swift. Providing a new language with "none of the baggage of C," Swift code can still be mixed with standard C and Objective C code in the same project.

Swift seems to get rid of Objective C's reliance on defined pointers; instead, the compiler infers the variable type, just as many scripting languages do. At the same time, it provides modern features similar to those found in C++ and Java, like well-defined namespaces, generics, and operator overloading. From the few fragments of code shown during the demo, Swift appears to rely heavily on the dot-notation that Apple introduced in an earlier iteration of Objective C.

The new language will rely on the automatic reference counting that Apple introduced to replace its garbage-collected version of Objective C. It will also be able to leverage the compiler technologies developed in LLVM for current development, such as auto vectorization.

Apple showed off a couple of cases where implementing the same algorithm in Swift provided a speedup of about 1.3X compared to the same code implemented in Objective C. It also showed off a Swift "playground," where code is compiled as it's typed and the output is displayed in a separate pane of the editing window. The goal here is to allow developers to test code fragments without having to recompile an entire complex project.

Use of Swift will be supported as soon as the next version of Xcode is released—it's currently available in beta form to registered developers, and will presumably see more widespread release during OS X Yosemite's public beta later this year. Apple also promises to release a free iBook on the language's syntax later today.

1 Comment

Tizen OS

Tizen OS

Samsung Electronics Co. said it will begin selling a smartphone that runs on its Tizen operating system in the third quarter of this year, advancing the company's plans to reduce dependence on Google's Android software.
Tizen is already used in a few Samsung products including a smartwatch but has not been deployed in a mass produced smartphone until now.
The Tizen phone will have preinstalled apps and users will have access to additional apps through Tizen Store.

Driverless car by google

Driverless car by google

Google will build a car without a steering wheel. It doesn’t need one because it drives itself.
Those cars have Google-employed “safety drivers” behind the wheel in case of emergency. The new cars would eliminate the driver from the task of driving. No steering wheel, no brake and gas pedals. Instead, buttons for go and stop.
The electric-powered car is compact and bubble-shaped something that might move people around a corporate campus or congested downtown. Google is unlikely to go deeply into auto manufacturing.

2 Comments

The new lambda expressions included in Java Platform Standard Edition 8 (Java SE 8).

Lambda expressions are a new and important feature included in Java SE 8. They provide a clear and concise way to represent one method interface using an expression. Lambda expressions also improve the Collection libraries making it easier to iterate through, filter, and extract data from a Collection. In addition, new concurrency features improve performance in multicore environments.

The following is a list of hardware and software requirements:

  • Java Development Kit (JDK 8) early access
  • NetBeans 7.4

Lambda Expression Syntax

Lambda expressions address the bulkiness of anonymous inner classes by converting five lines of code into a single statement. This simple horizontal solution solves the "vertical problem" presented by inner classes.

A lambda expression is composed of three parts.

Argument List Arrow Token Body
(int x, int y) -> x + y

The body can be either a single expression or a statement block. In the expression form, the body is simply evaluated and returned. In the block form, the body is evaluated like a method body and a return statement returns control to the caller of the anonymous method. The break and continue keywords are illegal at the top level, but are permitted within loops. If the body produces a result, every control path must return something or throw an exception.

Example

Here is how you write a Runnable using lambdas.

 6 public class RunnableTest {
 7   public static void main(String[] args) {
 8     
 9     System.out.println("=== RunnableTest ===");
10     
11     // Anonymous Runnable
12     Runnable r1 = new Runnable(){
13       
14       @Override
15       public void run(){
16         System.out.println("Hello world one!");
17       }
18     };
19     
20     // Lambda Runnable
21     Runnable r2 = () -> System.out.println("Hello world two!");
22     
23     // Run em!
24     r1.run();
25     r2.run();
26     
27   }
28 }

In both cases, notice that no parameter is passed and is returned. The Runnable lambda expression, which uses the block format, converts five lines of code into one statement.

Reference Source for this information is www.oracle.com

 

2 Comments

Java8 has been released with a many new features and no doubt these new features are very useful and very interesting to use such as Lambda expressions.

So have a look on java 8's features :

Lambda Expressions 

Lambda Expressions, a new language feature, has been introduced in this release.They enable you to treat functionality as a method argument, or code as data. Lambda expressions let you express instances of single-method interfaces (referred to as functional interfaces) more compactly.

Methods References

Method references provide easy-to-read lambda expressions for methods that already have a name.

New Api for Date and Time 

A new set of packages that provide a comprehensive date-time model.

New Stream Api

Improved Type Interface

Method parameter References

Repeating Annotations 

Repeating Annotations provide the ability to apply the same annotation type more than once to the same declaration or type use.

Type Annotations

Type Annotations provide the ability to apply an annotation anywhere a type is used, not just on a declaration. Used with a pluggable type system, this feature enables improved type checking of your code.