Skip to main content

Posts

Showing posts from December, 2017

Control Statements in Java (Part 2)

W elcome back to my blog!!! In my previous post you learned about if , nested ifs and else-if-else in Java. In this post you will learn about switch . What is a switch? In Java, a switch is a multiway branch statement. General form of a switch: switch(expression) { case value1: statement;                      break; case value2: statement;                      break; . . . . . . default: statement;               break; } The expression must be the type of int , byte , short or char . Duplicate case values are not allowed. The switch  statement works like this: the value of the expression is compared with each of the literal values in the case statements. If a match is found, the code sequence following the case statement is executed. If none of the constants matches the value of the expressions, then the default statement is executed. however, the default statement is optional. If no case matches and no default is present, then no further action is taken. The break statement i

Control Statement in Java (Part-1)

Welcome back, bloggers! In my last post you learned about multidimensional array in Java. In this post you will learn about the control statements in Java. Java supports two selection statements: if and switch.  These statements allow you to control the flow of your program execution based upon the conditions known only during the run time. 1. If: The if statement in Java is a conditional branch statement. It is used to route program execution through two different parts. The general form of if is: if(condition)    statement 1; else    statement 2; Here, each statement may be a single statement or compound statement enclosed by curly braces(that is, block). The condition is any expression that returns a Boolean  value. The else  clause is optional.           The if  statement works like this: If the condition is true, then statement 1 will be executed. Otherwise, statement 2 (if any) will be executed. In no cases will both of the statements be executed. Given below is an example: int a

Multidimensional Array in Java

W elcome back to my blog! In my previous post you learned about single dimensional array in Java. A multidimensional array is a fixed sized sequenced collection of data of a same data type. In multidimensional array, data is stored in rows and columns. A multidimensional array is actually an array of arrays. Syntax to declare a multidimensional array: datatype array_name[][]; Syntax to instantiate a multidimensional array: int array[][] = new int[4][4]; This will allocate 4 rows and 4 columns. Syntax to initialize a multidimensional array: array[0][0] = 1; array[0][1] = 2; array[0][2] = 3; array[0][3] = 4; array[1][0] = 5; array[1][1] = 6; array[1][2] = 7; array[1][3] = 8; array[2][0] = 9; array[2][1] = 10; array[2][2] = 11; array[2][3] = 12; array[3][0] = 13; array[3][1] = 14; array[3][2] = 15; array[3][3] = 16; For printing the multidimensional array: for(int i=0;i<4;i++;) { for(int j=0;j<4;j++) { System.out.println(array[i][j]+"");          } System.out.println();  

Single Dimensional Array In Java

W elcome back, bloggers! In this post you will learn about single dimensional arrays in Java. First of all, what is an array? An array is a fixed sized sequenced collection of elements of a same data type. Array in Java is index-based. The very first element is stored at 0 th  position. Advantages of array in Java: 1. Memory does not get wasted. 2. We can get any data located at any fixed index value. Single Dimensional Array in Java: A single dimensional array contains only one row and no number of columns. Syntax:      datatype name[]; Initialization of a single dimensional array:     array[] = new int[5]; Now, let's see an example of a single dimensional array: class JavaArray {       public static void main(String[] args) { int array[]; //declaration      array = new int [5];  //instantiation a[0] = 1;  //initialization a[1] = 2; a[2] = 3; a[3] = 4; a[4] = 5; //printing the array: for ( int i=0; i<=array. length ; i++) System. out .println(array[i]);                    

Check Whether The String Is Palindrome Or Not

W elcome back to my blog! In my previous post, you learnt how to print a pattern in Java using Eclipse. Today you will learn how to check whether a string from terminal is palindrome or not. Let's get started! Step #1. Open Eclipse and choose the directory where you want to save your work. Step #2. Select File>New>Project as shown in the picture below: Step #3. Select Java>Java  Project. Then, click Next. Step #4. Enter the name of the project in Project name. Then click on Finish. Step #5. You will see the name of your project in Package Explorer: Step #6. You will find a folder named as "src" under the name of your project: Step #7. Right click on the folder "src">New>Class as demonstrated below: Step #8. Enter the name of the class as shown below: Then click on Finish. Step #9. You will see a screen like this: Step #10. Write the following code: import java.util.Scanner; public class Pal {           public static void main(String[] args) { Scan

Pattern design in Java

W elcome back to my blog! You saw how to print "Hello, Java" using Eclipse in the previous post. In this post you will learn how to draw the following design in Java using Eclipse: * * * * * * * * * * * * * * * Step #1. Open Eclipse and enter the directory where you want to save your work as shown in the picture below: Step #2. Select File>New>Java Project. Step #3. Enter the project name in Project name and then click on Next. Step #4. Click on Finish. Step #5. You will see a folder named "src" under the project name. Step #6. Right click on the folder "src">New>Class. Step #7. Enter the name of the class and click on Finish. Step #8. You will see a screen like this: Step #9. Write the following code: public class Design { public static void main(String[] args) {      for (int a=0;a<=5;a++) {      for(int b=0;b<a;b++) {           System.out.print("* "); }           System.out.println();           } } } Note: You can

Simple Java program

J ava is a high level programming language which is used almost everywhere- in Android mobile phones, set top boxes, in Google Maps, video games, etc. Today let's see how to make the simplest Java program- "Hello, world" in Eclipse. Step #1. Select your file location where you want to save your work. Step #2. Select File>New>Project as shown in the picture below: Step #3. Select Java>Java Project>Next as shown below: Step #4. Enter the project name in Project name as shown below: Step #5. Select Finish. Step #6. Select Yes. Step #7. Double click one the project name. You will see a folder named as "src" under the the project HelloWorld. Step #8. Right click on the folder "src">New>Class. Step #9. Enter the name of the class. Then click on Finish. Step #10. You will see a screen like this: Step #11. Write the following code: public class Hello { public static void main(String[] args) { System.out.println("Hello, world!!"); }

Top 10 Programming Languages

Top 10 Programming Languages in Demand W elcome back to my blog! In the growing phase of  IT industry, many new programming languages are designed to fulfill small/big projects, build applications, websites, softwares and what not!? Every programming language has its own significance, uses, advantages and disadvantages. Here are some of the programming languages in high demand: 1. JavaScript. J avaScript is a high-level programming language of HTML and web. It is used for front-end developing. Main purpose of JavaScript is: 1.1. Reduce server side trafficking. It tries to reduce maximum number at client side so that products do not get affected by poor performance. 1.2. Provides client side validation. For example, if a user enters wrong email ID, JavaScript sends validation message that the entered email ID is wrong. 1.3. Used for pop-ups, alerts, client side calculations, etc. 1.4. Provides connection between front-end and back-end users. Note:  DO NOT WRITE SERVER SIDE INFORMATION O