Manipulate Java Strings

quizWhat are strings?

In computer science, a string is a sequence of characters as either a variable or a literal constant. Read this article about strings to gain some understanding of strings: http://en.wikipedia.org/wiki/String_%28computer_science%29

Why reverse strings?

Manipulating strings is a  basic fundamental knowledge that every software engineer must understand. Most software programs use strings as input and output strings for many reasons such as providing a human friendly interface.  This is a standard question during technical interviews too, so make time to learn this, be able to explain it, code it and explain what your code is doing.

How to reverse strings.

  1. Login to your Browxy account.
  2. Create a new java file and enter the following code for your new java file.
  3. Run your new java file and view results in your web browser.

You can view and run this code in your web browser right now with Browxy.

 public class ReverseString {

     public static void main(String []args){
        System.out.println ( reverse("Hello Monica") );
     }
     
    public static String reverse ( String s ) {
        int length = s.length(), last = length - 1;
        char[] chars = s.toCharArray();
        for ( int i = 0; i < length/2; i++ ) {
            char c = chars[i];
            chars[i] = chars[last - i];
            chars[last - i] = c;
        }
        return new String(chars);
    }
}

Code Explanation

//Create java class that other java classes can reuse.
 public class ReverseString {

     //main java function is required
     //take in string array[] of args from other java functions in this program
     //public
     //static
     //void
     public static void main(String []args){
        //test our reverse java function
        //enter a string to run reverse function on
        System.out.println ( reverse("Hello Monica") );
     }
     
    //create reverse java function
    //String
    //(String s)
    public static String reverse ( String s ) {
        //length set to input String s (Hello Monica input from main function)
        //last set to length minus the previous String s
        int length = s.length(), last = length - 1;

        //[]array chars set to input string (String s / Hello Monica) 
        //convert input string (Hello Monica) to array
        char[] chars = s.toCharArray();

        //loop to build out the new reversed string
        //look at each char (H e l l o M o n i c a)
        //run this when i is less than half the length of input string (Hello Monica)
        //each time loop runs, add another i to the new reversed string
        for ( int i = 0; i < length/2; i++ ) {
            //c set to array i
            char c = chars[i];

            //array i set to last character we did not add yet
            chars[i] = chars[last - i];

            //last char set to c
            chars[last - i] = c;
        }
        
        return new String(chars);
    }
}

Assignment

Create one blog post with all of the following:

  1. Create your own personal notes based on what you understand about manipulating strings with java. Keep your notes short & focused, following the note taking suggestions in the references at the end of this post.
  2. Create a 2 to 5 minute video review of your java projects for this assignment and upload it to YouTube as a public video, following the guidelines later in this post.
  3. Embed your YouTube video or Link to your YouTube video on your blog post.
  4. Include links to your public Github repository or your Browxy files for this assignment.

YOUR BLOG POST

Your personal notes should be short and focused to include what stood out the most to you as something you want to remember in the future. Review the note taking suggestions you will find in the references at the end of this post.

YOUR YOUTUBE VIDEO

Your YouTube video title: “Manipulate Strings with Java Assignment for MoniGarr.com”.Your YouTube video description:  “This is my video review of my Manipulate Strings with Java assignment for MoniGarr.com”.  You can include more details if you wish, but please include the minimum I’m asking you for, to make it easier for our team to locate your work.Your YouTube video keywords: “java, string, assignment, monigarr”Your video content should include the following:

  • Start video stating Your Name, the current Date, and brief description of what your video is going to show.  (example: “My name is Monica and today is August 25th 2014. This video is going to review my Manipulate Strings with Java Assignment for MoniGarr.com”)
  • Show your computer screen and briefly show your work while describing what you are showing (java files in browxy or Github you created or edited & why you did that, one or two specific pieces of code you learned about.
  • End video with a link to your Browxy java file or Github repository and state what you just showed the audience (example: This concludes my video review of the Manipulate Strings with Java Assignment for MoniGarr.com”).

Go the Extra Mile? This is optional, but you might enjoy going the extra mile to promote your work and connect with other software developers.

  • Be confident and be yourself. If you want to be humorous, go for it. If you want to show viewers what is unique, entertaining, and valuable about your views of the topic in your video, go for it.
  • Ask your viewers a question about the topic in your video and invite them to answer your question in the comments for your video.
  • Invite your viewers to comment on or ask questions about the content in your video or the specific java android code in your video review. This is a great way to network with other software developers and promote your own work.
  • Consider enabling monetization on your videos to earn a little extra money from YouTube advertisers. Review the YouTube guidelines to improve your earnings and your video popularity: https://www.youtube.com/yt/creators/
  • Share your videos on all your social networks to help you connect with other software developers and employers that are looking to hire a software developer like you.

 

YOUR BROWXY JAVA FILE

Create your own browxy java file for the lesson above. Follow good practices and include:

  • Author comment at top of your file with the following:
  • // Author: Your Name, youremail@email.com
  • // Date: month/day/year
  • // Manipulate Strings with Java assignment for MoniGarr.com

MANIPULATE STRINGS WITH JAVA QUIZ

Complete and Pass Monigarr.com’s Manipulate Strings with Java Quiz

References: