To know more about java tutorials.... Click here
More Javascript tutorials you can found here

Clinet Tools Required to pre-install to access or create a new Open Shift application

July 12, 2014 Leave a comment

I have faced hell lot of issues when I started implementing the Openshift sample application. I thought of sharing my experience with everybody so that it will help if there is any issue during others project implementation. Most important thing in accessing the application is to install the client tools in your machine.

In this post I would like to explain about the Client tools required, install the tools in to windows machine and check the installation status of the tools.

Install Client Tools:

For Windows based desktop it is required to install the three client tools as mentioned below:

1) Ruby: All open shift tools runs on the Ruby, this is the basic software that is required to install. Download suitable Ruby installer for your desktop from Ruby Down loads page and install the by accepting all default options. After the installation is completed, to verify that the installation is working run:

RubyRunningStatus

2) Git Client: Git is used to synchronize local application source and your OpenShift application. Download and install the latest version of Git for Windows. After installing the git, it is required to ensure that git is added into your system PATH. If it is not added, make sure to add it manually in system environment variables.

After installing the git, you can check the git version installed in machine using below command.

GitVersion

3) Openshift client: After Ruby and git installed properly, run the openshift client tools bundled in the ruby installer.

OpenshiftClinet

After installation completes, run the rhc command as below, then complete list of options to be displayed.

RHCOptions

 

Other Useful Links:

Openshift – The Open Hybrid Cloud Application Platform by Red Hat

About these ads

Example Program: Search Word in Folder files and print output

May 4, 2014 Leave a comment

To Search a word in in list of files available in Folder, you need to find the list of files first and then scan each and every for required word. Below is the sample program to find the a given word Java in D:\\test folder of files.

package in.javatutorials;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.MatchResult;

/**
* @author malliktalksjava
*
* Search for the files in a folder and prints all file details.
*
*/
public class WordCrawlerInFolder {

private static String directoryPath = “D://test”;
private static String searchWord = “Java”;
/**
* Creating constructor
*/
public WordCrawlerInFolder() {
super();
}

/**
* main method
*
* @param ags
*/
public static void main(String[] args) {
WordCrawlerInFolder crawler = new WordCrawlerInFolder();
File directory = new File(directoryPath);

if (directory == null || !directory.exists()) {
System.out.println(“Directory doesn’t exists!!!”);
return;
}

crawler.directoryCrawler(directory, searchWord);
}

/**
* Gets all the file and directories and prints accordingly
*
* @param directory
* Directory path where it should search
*/
public void directoryCrawler(File directory, String searchWord) {

// Get List of files in folder and print
File[] filesAndDirs = directory.listFiles();

// Print the root directory name
//System.out.println(“-” + directory.getName());

// Iterate the list of files, if it is identified as not a file call
// directoryCrawler method to list all the files in that directory.
for (File file : filesAndDirs) {

if (file.isFile()) {
searchWord(file, searchWord);
//System.out.println(” |-” + file.getName());
} else {
directoryCrawler(file, searchWord);
}
}
}

/**
* Search for word in a given file.
* @param file
* @param searchWord
*/
private void searchWord(File file, String searchWord){
Scanner scanFile;
try {
scanFile = new Scanner(file);
while (null != scanFile.findWithinHorizon(“(?i)\\b”+searchWord+”\\b”, 0)) {
MatchResult mr = scanFile.match();
System.out.printf(“Word found : %s at index %d to %d.%n”, mr.group(),
mr.start(), mr.end());
}
scanFile.close();
} catch (FileNotFoundException e) {
System.err.println(“Search File Not Found !!!!! “);
e.printStackTrace();
}
}
}

We have used some escape characters in above class searchWord() method, below is the notation for the same.

  1. (?i) turn on the case-insensitive switch
  2. \b means a word boundary
  3. java is the string searched for
  4. \b a word boundary again.

If search term contain special characters, it would be suggested to use \Q and \E around the string, as it quotes all characters in between. Make sure the input doesn’t contain \E itself.

Other Useful Links:

Javac/Java searching algorithm for other classes

Example program to reverse a Number in Java

How to find count of duplicates in a List

Threads Interview questions in Java

How to Identify Browser Agent in JavaScript

May 4, 2014 1 comment

Here is the Example code to identify the Browser Agent using Java script:

<script type=”text/javascript”>
alert(navigator);
var browserName=navigator.appName;
var userAgent = navigator.userAgent
alert(browserName);
if (browserName==”Microsoft Internet Explorer”){
alert(“Microsoft Internet Explorer”);
alert(“Microsoft Internet Explorer Version : “+navigator.appVersion);
alert(document.documentMode;);

}
else if (browserName==”Netscape” && userAgent.indexOf(“Chrome”) != -1 ){
alert(“Google Chrome”);
alert(“Google Chrome Version: “+navigator.appVersion);
}
else if(browserName==”Netscape” && userAgent.indexOf(“Mozilla”) != -1){
alert(“Mozilla Firefox”);
alert(“Mozilla Firefox Version : “+navigator.appVersion);
}else{
alert(“Another browser”);
}
</script>

Other Useful Links:

Top Java script Charting Frameworks

List of Java script MVC Frameworks

Enabling javascript in browsers

Creation of Dynamic rows in javascript

Example Java Program to Search Files in a Folder

May 4, 2014 Leave a comment

Below Java Program lists the file names and directory names available in given folder. To do this implementation , we can get the files list in a folder using File class available in Java API. Iterate the files one by one and write the file name on to console.

If it is identified as a directory instead of a file, then iterate the process as mentioned in directoryCrawler() method in the below class.

package in.javatutorials;

import java.io.File;

/**
* @author malliktalksjava
*
* Search for the files in a folder and prints all file details.
*
*/
public class FolderCrawler {

private static String directoryPath = “D://test”;

/**
* Creating constructor
*/
public FolderCrawler() {
super();
}

/**
* main method
*
* @param ags
*/
public static void main(String[] args) {
FolderCrawler crawler = new FolderCrawler();

File directory = new File(directoryPath);

if (directory == null || !directory.exists()) {
System.out.println(“Directory doesn’t exists!!!”);
return;
}

crawler.directoryCrawler(directory);
}

/**
* Gets all the file and directories and prints accordingly
*
* @param directory
* Directory path where it should search
*/
public void directoryCrawler(File directory) {

// Get List of files in folder and print
File[] filesAndDirs = directory.listFiles();

// Print the root directory name
System.out.println(“-” + directory.getName());

// Iterate the list of files, if it is identified as not a file call
// directoryCrawler method to list all the files in that directory.
for (File file : filesAndDirs) {

if (file.isFile()) {
System.out.println(” |-” + file.getName());
} else {
directoryCrawler(file);

}
}// end of for

}// End of directory Crawler
}

 

Other Useful Links:

Javac/Java searching algorithm for other classes

Example program to reverse a Number in Java

How to find count of duplicates in a List

Threads Interview questions in Java

Openshift – The Open Hybrid Cloud Application Platform by Red Hat

May 2, 2014 1 comment

When I saw about Openshift for the first time, it was kind of amazing feeling to me. When I started using it, I feelings never decreased.

It is an Open Hybrid Cloud Application Platform by Red Hat. I have looked into IDE based implementation, I have looked into command based implementation for JAVA application deployment in JBoss Enterprise application server. I felt like I have learned something new, which may change my life entirely if I become a master in that.

Hope, keep exploring about it from your side, you will definitely love it. I am sure, I have not given any mis perception on this to you.

Base Site : https://www.openshift.com

About Product : https://www.openshift.com/products

User Guide : https://access.redhat.com/site/documentation/en-US/OpenShift_Online/2.0/html/User_Guide/index.html 

 

I am very happy if you keep posting your comments on OpenShift, lets others know about this interesting thing. All comments are invited!!!

Thanks…

 

Follow

Get every new post delivered to your Inbox.

Join 315 other followers