Skip to content
May 6 12

Installing Google Chrome in Ubuntu – Fix error for missing package libcurl3 libnss3-1d libxss1

by Manish

I went to the Google Chrome download page and downloaded the file google-chrome-stable_current_i386.deb

But when I went to install it using command

sudo dpkg -i google-chrome-stable_current_i386.deb

and got the following output.

dpkg: dependency problems prevent configuration of google-chrome-stable:
google-chrome-stable depends on libnss3-1d (>= 3.12.3); however:
Package libnss3-1d is not installed.
google-chrome-stable depends on libxss1; however:
Package libxss1 is not installed.
google-chrome-stable depends on libcurl3; however:
Package libcurl3 is not installed.
dpkg: error processing google-chrome-stable (–install):
dependency problems – leaving unconfigured
Processing triggers for gnome-menus …
Processing triggers for desktop-file-utils …
Processing triggers for bamfdaemon …
Rebuilding /usr/share/applications/bamf.index…
Processing triggers for man-db …
Errors were encountered while processing:
google-chrome-stable

(Please note, you can install .deb files by using GDebi tool but you will still get the same error regarding missing dependencies).

You can fix this by installing missing dependencies. Just run the following command (after you have run “sudo dpkg -i google-chrome-stable_current_i386.deb“).

sudo apt-get install -f

This will install missing dependencies and configure Google Chrome for you.

Please share this. It's how ideas spread:
  • email
  • Facebook
  • Twitter
  • LinkedIn
  • Digg
  • StumbleUpon
  • del.icio.us
  • Tumblr
  • Slashdot
  • Reddit
  • Google Bookmarks
  • FriendFeed
  • Print
May 6 12

Installing Oracle Sun Java (JDK) and setting JAVA_HOME in Ubuntu (Linux)

by Manish

This post is not only for people who are new to Linux or Java but also quick notes for me to setup my environment next time I install my system or setup a virtual machine.

Installing OpenJDK can be very simple but not Oracle JDK. You can use one of the two following commands (depending on which version you which to install) to setup OpenJDK in your linux environment.

sudo apt-get install openjdk-6-jdk
or
sudo apt-get install openjdk-7-jdk

But I have always used Oracle Sun JDK for my development. While Oracle JDK (earlier Sun JDK) is under the Binary Code License (earlier Sun License), OpenJDK is under GPL with a linking exception. From JDK version 7, Oracle has planned to support OpenJDK and withdraw the Operating System Distributor License for Java. This has resulted in a withdrawal of Oracle JDK from the repositories of Linux distributions. Therefore you can’t just use apt-get to install Oracle JDK.

Here is the stackoverflow link to help you choose between the Oracle JDK or OpenJDK.

But users who prefer to use the Oracle JDK binaries over OpenJDK builds packaged in their Linux distributions of choice can of course download the package from http://oracle.com/java under the same terms as users on other platforms. Here is the direct link to JavaSE downloads.

Coming the point I have downloaded JDK 7 (update 4) for Linux x86 (32-bit) – file: jdk-7u4-linux-i586.tar.gz

Step 1: After downloading the file open the terminal and navigate to the file

tar -xf jdk-7u4-linux-i586.tar.gz

This will extract and create a jdk folder at your current path.

Step 2: Create a location to keep your new JDK . I prefer and usually use /usr/lib/jvm/

You may need root permission to create the /usr/lib/jvm (hence use sudo).

sudo mkdir /usr/lib/jvm 

Step 3: Move the extracted jdk folder to /usr/lib/jvm/

sudo mv jdk1.7.0_04 /usr/lib/jvm/

Step 4: Now we have to setup our system to use refer to our new jdk

sudo update-alternatives --install "/usr/bin/java" "java" \
"/usr/lib/jvm/jdk1.7.0_04/bin/java" 1

sudo update-alternatives --config java

And also register Firefox Java Plugin

sudo update-alternatives --install "/usr/lib/mozilla/plugins/libjavaplugin.so" \
"mozilla-javaplugin.so" "/usr/lib/jvm/jdk1.7.0_04/jre/lib/i386/libnpjp2.so" 1

sudo update-alternatives --config mozilla-javaplugin.so

ALL DONE. You can test your java install by

java -version

Here is a small screen capture of what happened on my screen when I went through above steps

Oracle JDK Install

Finally if you need to add JAVA_HOME variable, you can do so by adding it to the .bashrc file in your home directory

Open .bashrc file using an editor. If you use VI then
vi ~/.bashrc

and add the following 2 lines in your .bashrc file.

JAVA_HOME=/usr/lib/jvm/jdk1.7.0_04/
export JAVA_HOME

There may be other ways to install, but this is what I have followed always.

Cheers

Please share this. It's how ideas spread:
  • email
  • Facebook
  • Twitter
  • LinkedIn
  • Digg
  • StumbleUpon
  • del.icio.us
  • Tumblr
  • Slashdot
  • Reddit
  • Google Bookmarks
  • FriendFeed
  • Print
Jan 16 12

Java 7: New Features

by Manish

The development of Java Programming language continues, albeit a bit slow. Oracle announced availability of Java SE 7 on 28th July 2011 (link).  It took nearly 5 years after the release of Java 6 in December 2006, but still it shipped with bugs (example). But now after two updates (Update 1 in Oct 2011 and Update 2 in Dec 2011) you might seriously start looking at some cool new features of Java 7.

You can download the new JDK from here.

Here is a list of some of the new features in Java SE 7

  • Diamond Operator (GENERICS)

You may have noted on many occasions your IDE complaining of types when working with Generics. For example, if we have to declare a map of trades using Generics, we write the code as follows:

Map<String, List<Trade>> trades = new TreeMap<String, List<Trade>> ();

The not-so-nice thing about this declaration is that we must declare the types on both the sides, although the right-hand side seems a bit redundant. Can the compiler infer the types by looking at the left-hand-side declaration? Not unless you’re using Java 7. In 7, it’s written like this:

Map<String, List<Trade>> trades = new TreeMap<> ();

Saves a few keystrokes without removing any type safety. Nice but small improvement.

  • Automatic Resource Management

This is the try-with-resources or Automatic Resource Management block. If you declare a variable in the try() statement, Java automatically calls close on it, like you would in a finally block. This is a small improvement, but nice. You can use try-with-resources on your own object by implementing the new interface java.lang.AutoCloseable.

try ( BufferedReader reader = new BufferedReader(new FileReader(...))) {
    String line = reader.readLine();
    process(line);
}
  •  Improved exception handling

There are a couple of improvements in the exception handling area. Java 7 introduced multi-catch functionality to catch multiple exception types using a single catch block.

Let’s say you have a method that throws three exceptions. In the current state, you would deal them individually as shown in below:

public void oldMultiCatch() {
    try {
        methodThatThrowsThreeExceptions();
    } catch (ExceptionOne e) {
        // log and deal with ExceptionOne
    } catch (ExceptionTwo e) {
        // log and deal with ExceptionTwo
    } catch (ExceptionThree e) {
        // log and deal with ExceptionThree
    }
}

Catching an endless number of exceptions one after the other in a catch block looks cluttered and I have seen code that catches a dozen exceptions. This is incredibly inefficient and error prone. Java 7 has brought in a new language change to address this ugly duckling. See the improved version of the method oldMultiCatch() below:

public void newMultiCatch() {
    try {
        methodThatThrowsThreeExceptions();
    } catch (ExceptionOne | ExceptionTwo | ExceptionThree e) {
        // log and deal with all Exceptions
    }
}

The multiple exceptions are caught in one catch block by using a ‘|’ operator. This way, you do not have to write dozens of exception catches.

  • Using strings in switch statements

Switch statements work either with primitive types or enumerated types. Java 7 introduced another type that we can use in Switch statements: the String type.

Say we have a requirement to process a Trade based on its status. Until now we used to do this by using if-else statements.

private void processTrade(Trade t) {
    String status = t.getStatus();
    if (status.equalsIgnoreCase(NEW)) {
        newTrade(t);
    } else if (status.equalsIgnoreCase(EXECUTE)) {
        executeTrade(t);
    } else if (status.equalsIgnoreCase(PENDING)) {
        pendingTrade(t);
    }
}

This method of working on strings is crude. In Java 7, we can improve the program by utilizing the enhanced Switch statement, which takes a String type as an argument.

public void processTrade(Trade t) {
    String status = t.getStatus();
    switch (status) {
        case NEW:
          newTrade(t);
          break;
        case EXECUTE:
          executeTrade(t);
          break;
        case PENDING:
          pendingTrade(t);
          break;
    }
}

In the above program, the status field is always compared against the case label by using the String.equals()method.

  • Improved File IO API

There are quite a bit of changes in the java.nio package. Many are geared towards performance improvements, but long awaited enhancements over java.io (specially java.io.File) have finally materialized in a new package called java.nio.file.

For example, to read a small file and print all the lines;

	List lines =  Files.readAllLines(
	FileSystems.getDefault().getPath("test.txt"), StandardCharsets.UTF_8);  

	for (String line : lines) System.out.println(line);

java.nio.file.Path is an interface that pretty much serves as a replacement for java.io.File, we need a java.nio.file.FileSystem to get paths, which you can get by using thejava.nio.file.FileSystems factory (getDefault() gives you the default file system).

java.nio.file.Files then provides static methods for file related operations. In this example we can read a whole file much more easily by using readAllLines(). This class also has methods to create symbolic links, which was impossible to do pre-Java 7. Another feature long overdue is the ability to set file permissions for POSIX compliant file systems via the Files.setPosixFilePermissions method. These are all long over due file related operations, impossible without JNI methods or System.exec() hacks.

I didn’t have time to play with it but this package also contains a very interesting capability via the WatchService API which allows notification of file changes. You can for example, register directories you want to watch and get notified when a file is added, removed or updated. Before, this required manually polling the directories, which is not fun code to write.

For more on monitoring changes read this tutorial from Oracle.

JVM changes

The Java virtual machine gets a new instruction: invokedynamic. Using invokedynamic, the JVM can invoke a method on an object without having to know on which class or interface the method is declared. If it walks like a duck and talks like a duck…
Invokedynamic will be very helpful for implementors of dynamic languages in the JVM, so it’s great. But the average developer will never encounter it in the wild.

Library changes

Looking at the release notes for Java 7, you may first suspect that there are some interesting library changes here. However, when examining the list more thoroughly, I couldn’t find a single change that I expect I will actually use. The library changes are mostly low-level, behind the scenes fixes of small problems.

Conclusions

So there it is: try-with-resources, multi-catch and a very limited type inference. Hopefully, Java 8 will be released as planned in early 2013 with all the stuff we’ve been waiting for. If so, I expect most shops will skip Java 7 and jump straight to Java 8. But hopefully Java 8 won’t follow the pattern of delays from Java 7.

Please share this. It's how ideas spread:
  • email
  • Facebook
  • Twitter
  • LinkedIn
  • Digg
  • StumbleUpon
  • del.icio.us
  • Tumblr
  • Slashdot
  • Reddit
  • Google Bookmarks
  • FriendFeed
  • Print