What is Java?

A Beginner's Guide to Java and its Evolution
Written by Paayi Tech |12-Aug-2019 | 0 Comments | 52 Views

Java is used generally for several purposes, and it has JVM has its cornerstone. In this article I going to show:

What is Java?

Examples With Codes And their Output

What is Java Used?

Reasons Why You Should Use Java. 

Jumping into the definition of Java or answering your questions will not give you an apparent reason why this programming language needs to be learned. 

For this reason, I want to brief you on the history of Java quickly. 

 

Brief History Of Java

It was first developed by a group of developers which include James Gosling and his other team members who were Mike Sheridan and Patrick Naughton in the year 1995. As a result of their teamwork named Green Team, they were employed to work under Sun Microsystems. 

 

What is Java?

Java is a programming language, that is used to develop apps like mobile apps, web apps, desktop apps, games, and much more. It freely accessible, making its features more advanced than the C++. 

It allows the write-once and runs anywhere system whereby, making it easier for developers to create and compile codes which can run on all platforms. 

Its syntax has a lower level facility than that of the C and C++, which makes it one of the popular programming language. 

 

Java Syntax

Java Syntax is the set of rules which gives instructions on how a Java Program is going to be written and interpreted. Its syntax is majorly formed from C and C++, which include some features like operators, integers, etc. 

 

Java Syntax Example:

public class MyClass {

 public static void main(String[] args) {

  System.out.println("Hello World");

 }

}

 

Output:

C:UsersNamejava MyClass

Hello World

Let's take some other examples with Codes to make it more explainable:

 

Java Examples With Codes And Their Output. 

 

1. Java Comments:

If you want to explain what code is written, then you can understand it from the comments, and also they make the code more readable. It is also used when testing code. This is divided into two(2), and they are:

 

• Single-Line Comments:

This comment has the two forward slashes (//) which are used to start them. 

 

Example:

public class MyClass {

 public static void main(String[] args) {

  // This is a comment

  System.out.println("Hello World");

 }

}

 

Output:

Hello World

 

Note, any Letter and text that is between the two forward slashes are always ignored. 

 

• Multi-Line Comments:

This comments all starts with /* and all ends with */. 

 

Example:

public class MyClass {

 public static void main(String[] args) {

  /* The code below will print the words Hello World

  to the screen, and it is amazing */

  System.out.println("Hello World");

 }

}

 

Output:

Hello World

 

Note, just like the singe_line comments, all text between /* and */ are all ignored. 

 

 

2. Java Operators:

These operators are used to perform all kinds of operations, including variables and values. 

The value is called an operand, while the operation (to be performed between the two operands) is defined by an operator:

 

Operand Operator Operand

25 + 4

In the example below, the numbers 25 and 4 are operands, and the + sign is an operator:

 

Example 1:

public class MyClass {

 public static void main(String[] args) {

  int x = 25 + 4;

  System.out.println(x);

 }

}

 

Output:

29

 

Example 2:

public class MyClass {

 public static void main(String[] args) {

  int sum1 = 100 + 50;

  int sum2 = sum1 + 250;

  int sum3 = sum2 + sum2;

  System.out.println(sum1);

  System.out.println(sum2);

  System.out.println(sum3);  

 }

}

 

Output:

150

400

800

 

 

3. Java Strings:

This string is an object that contains some method which performs special operations, and they are also used to keep text which is surrounded by double-quotes. 

 

Example 1:

public class MyClass {

 public static void main(String[] args) {

  String greeting = "Hello";

  System.out.println(greeting);

 }

}

 

Output:

Hello

 

Example 2:

public class MyClass {

 public static void main(String[] args) {

  String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  System.out.println("The length of the txt string is: " + txt.length());

 }

}

 

Output:

The length of the txt string is: 26

 

 

4. Java Switch:

This switch is used to select code from code blocks which are to be executed. And this switch as some syntax which are:

 

switch(expression) {

 case x:

  // code block

  break;

 case y:

  // code block

  break;

 default:

  // code block

}

 

This is how the switch works:

The switch expression is evaluated once.

The value of the expression is compared with the values of each case.

If there is a match, the associated block of code is executed.

The break and default keywords are optional and will be described later in this chapter.

 

Example 1:

public class MyClass {

 public static void main(String[] args) {

  int day = 4;

  switch (day) {

   case 1:

    System.out.println("Monday");

    break;

   case 2:

    System.out.println("Tuesday");

    break;

   case 3:

    System.out.println("Wednesday");

    break;

   case 4:

    System.out.println("Thursday");

    break;

   case 5:

    System.out.println("Friday");

    break;

   case 6:

    System.out.println("Saturday");

 

Output:

Thursday

 

Example 2:

public class MyClass {

 public static void main(String[] args) {

  int day = 4;

  switch (day) {

   case 6:

    System.out.println("Today is Saturday");

    break;

   case 7:

    System.out.println("Today is Sunday");

    break;

   default:

    System.out.println("Looking forward to the Weekend");

  }   

 }

}

 

Output:

Looking forward to the weekend

 

 

5. Java Loops:

Java loops are used to code as long as a certain condition is met. Test syntax for this is:

 

while (condition) {

 // code block to be executed

}

 

Example:

public class MyClass {

 public static void main(String[] args) {

  int i = 0;

  while (i < 5) {

   System.out.println(i);

   i++;

  }  

 }

}

 

Output:

0

1

2

3

4

 

 

Best Three Uses of Java

Its platform is used to run all Java supported devices, which include smartphones and mobile phones. 

It serves as a chip to embedded systems like SIM card, SD cards, blue-ray disk players, etc. 

Java support several web applications using servlets and JSPs. 

 

 

Excellent Reasons Why You Should Use Java

It supports work on many platforms. 

It is one of the most straightforward programming languages to learn

It is the most popular coded language

It is swift, protective and powerful

Its developers are well experienced and much in numbers. 

 

Well, if you have genuinely read to this point, then your journey to becoming a professional in Java computer programming language is for sure secured. Because by reading this article, you have built a strong foundation. 

 





Login/Sign Up

Comments




Related Posts



© Copyright 2019, All Rights Reserved. paayi.com

This site uses cookies. By continuing to use this site or clicking "I Agree", you agree to the use of cookies. Read our cookies policy and privacy statement for more information.