Loading...

Follow The Java Programmer on Feedspot

Continue with Google
Continue with Facebook
or

Valid

In the world of updated and aware world, the world has seen a transition from the computer curve to Mobile Phone or smartphone as it is frequently referred, but what has remain constant in this evolving world is Java. Java was designed keeping syntax similar to C/C++, to make it look familiar to application developers. This forms one of the most important reasons of popularity of Java. But not limiting to this, let’s have a look at the underlying reasons for why a two decade language looks still fresh and popular.

Reasons Why is Java So Popular 1. Feature Rich Properties

Java is a feature rich language, from platform independence to WORA (Write Once, Run Anywhere) and not to forget the multi-threaded environment java supports. These rich features have caught the attention of enterprises for their scalable and distributed large enterprise applications.

2. Memory Management

The perk of using Java, the way java executes and manages memory it reduces a large overhead from developer’s perceptive to manage.

3. Applications Using Java

Market share that Java possess in the market in each segment is huge, from Mobile Application to Web and from Desktop to now IoT devices, java can be seen everywhere. Though exact figures in this regard would be too difficult to collate but see for yourself, Android holds the largest market share in smartphones (no doubt about that), and majority of the Android applications are based in Java. It shows the scale at which Java has captured everyone’s eye.

4. Ample availability of IDE’s

Java code is as simple as to be executed from Notepad and it even has IDE’s like Intelli J which handles debugging, gives you a server runtime and a host of other features. Some of the most common used IDE’s are Net beans, Eclipse, Intelli J. Some Ide’s are lighter and some provide extensive functionalities, well that’s itself a whole new topic to discuss which we plan to discuss later.

5. Rich Third Party API

API available for Java are very extensive, from creating JSON to reading XML, there are third party library for everything. Be it any file type, you can find ways to create, read, and update that file using libraries available. Take an example of Microsoft Office, one of the most used Office suite, you can read these files, edit them and modify them simply by using Apache’s POI class. Moving on take example of database connectivity, java has API which can work will typically any framework. All these benefits the development community and reduces time to market for the enterprises.

6. Strong Framework Communities

We all have heard about spring, Hibernate and JSF and so-on. These are nothing but implementations which use the core of J2EE and J2SE to ease of effort to the developer which reduces the developers overhead by managing Design Pattern and simply providing XML or annotations based implementations. These frameworks are available in almost all category from ORM’s to Security. Not to forget the UI frameworks which are available which help in reducing development effort and help in saving time and effort.

7. Last But Not Least ,Strong Future Roadmap

Java comes as a strong product from Oracle, though Oracle has been trying ways to monetize Java but the foundation of Java and plans of Oracle have a long roadmap for Java which benefits the programmer and enterprises and ultimately Oracle.

As we have seen how this two decade or may be two and half decade (Next Year in 2020, Java turns 25) old language holds for developers and if you still are waiting for the head start, it’s the right time to start learning Java. Follow our blog to start this journey.

All the opinions are Author owned and by no means represent the thought of any Organization. If any facts are missed or misinterpreted, inform the blog admin to get them updated.

The post Why is Java So Popular? appeared first on The Java Programmer.

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Tower of Hanoi is a mathematical puzzle game which contains three rods and N number of disks each incrementally different diameters.

Initial condition: Initially all disks placed on one rod one above the other in stack manner (largest one is at the bottom and this follows…)

Goal: Move all disks from this rod (say rod1) to rod2 by taking help of rod3. (Note: For understanding purpose rod numbers are given. You can give rod numbers in any manner)

Rules to move disks from one rod to another rod:

Rule 1: At a time only one disk has to be moved.

Rule 2: Every time we have to choose only top disk from any rod to move.

Rule 3: While moving disk from one rod to other, at any time, always small size disk must place on larger size disk. In other way, a disk never be placed on other disk which is less size than it.

This is how a tower of Hanoi look like:

Below is the implementation of the tower of hanoi in java using recursion.

Java Tower of Hanoi Program

public class toh{
	static int count = 0;
	static void recursive_toh(int N, char from, char to, char using){
		if (N == 1) {
			// base condition. If only one disk is there we can directly move it to target
			System.out.println ("Removing Disk 1 from rod"+ from +" and placing on rod" +to);
			count = count+1;
			return;
		}
		// see code explanation part for clear understanding of these 3 lins
		recursive_toh( N-1, from, using, to); 
		System.out.println ("Removing Disk "+N+" from rod"+ from +" and placing on rod" +to);
		count = count+1;
		recursive_toh( N-1, using, to, from);
	}
	public static void main(String[] args) {
		int N = 4; //Number of disks
		recursive_toh(N,'1','3','2'); // Meaning of this line is
		// Move N disks from rod 1 to rod 3 using rod 2
		System.out.println("Minimum No of disk movements for "+N+" disks is "+count);
	}
}

Output

Removing Disk 1 from rod1 and placing on rod2
Removing Disk 2 from rod1 and placing on rod3
Removing Disk 1 from rod2 and placing on rod3
Removing Disk 3 from rod1 and placing on rod2
Removing Disk 1 from rod3 and placing on rod1
Removing Disk 2 from rod3 and placing on rod2
Removing Disk 1 from rod1 and placing on rod2
Removing Disk 4 from rod1 and placing on rod3
Removing Disk 1 from rod2 and placing on rod3
Removing Disk 2 from rod2 and placing on rod1
Removing Disk 1 from rod3 and placing on rod1
Removing Disk 3 from rod2 and placing on rod3
Removing Disk 1 from rod1 and placing on rod2
Removing Disk 2 from rod1 and placing on rod3
Removing Disk 1 from rod2 and placing on rod3
Minimum No of disk movements for 4 disks is 15

Code Explanation

Here number of disks N=4. And goal looks like, rec_toh(N, ‘initial rod’, ‘final rod’, ‘helping rod’). i.e. We have to move N disks from initial rod to final rod using other one.

Base condition: When there is only one disk, we can directly move that one to target. Because tower of Hanoi with one disk never violates the rules.

Now there are N disks on rod1. We have to shift them to rod3 in same order means the largest one must be at bottom on rod3 also. But there are N-1 disks on top of it. For this what we have to do is, first move these top N-1 disks to aside (here to rod2). If you observe carefully this is leading to other tower of Hanoi problem of N-1 disks. Here our initial rod is same rod1. But target rod is rod2 since only one rod left we have to use rod3 as helping rod temporarily. So recursive form is rec_toh(N-1,from,using,to);

After moving all N-1 disks to rod2 from rod1 using rod3, now we can freely move Nth disk from rod1 to rod3 (target). That is the next line System.out.println();

Now we have to take back those N-1 disks from rod2 to rod3. So we have to use rod1. For this recursive from is rec_toh( N-1, using, to, from);

We can print the minimum number of disk movements required to move N disks. By giving count whenever we moved a disk. That is equal to 2N-1

Comment below if you have any queries related to tower of hanoi program in java.

The post Java Tower of Hanoi Program appeared first on The Java Programmer.

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

The rock paper scissors is a game where through hand formations; the decision of the winner is made. The game works on the following principles:

  1. The rock defeats scissors.
  2. The scissors defeat the paper.
  3. The paper defeats the rocks.
  4. If the formation is same from both the side, it is considered a draw.
  5. whoever wins 5 times is the winner.

This game is made in java which encompasses a competition between the user and his computer system.

Java Rock Paper Scissors Program

import java.util.Random;
import java.util.Scanner;

public class Game {

	public static final String ROCK = "R";
	public static final String PAPER = "P";
	public static final String SCISSORS = "S";

	/**
	 * Get the game Result
	 * */
	public static void getResult(String usersMove, String computersMove) {
	
        System.out.println("Computer's move is: " + computersMove);

        if (usersMove.equals(computersMove))
	        System.out.println("It's a tie!");
        else if (usersMove.equals(ROCK)) 
        {
	        if (computersMove.equals(SCISSORS))
		        System.out.println("You win!! Rock crushes scissors.");
	        else if (computersMove.equals(PAPER))
		        System.out.println("You lose!! Paper eats rock.");
        } 
        else if (usersMove.equals(PAPER)) 
        {
            if (computersMove.equals(ROCK))
		        System.out.println("You win!! Paper eats rock.");
	        else if (computersMove.equals(SCISSORS))
		        System.out.println("You lose!! Scissor cuts paper.");
        } 
        else if (usersMove.equals(SCISSORS)) 
        {
	        if (computersMove.equals(PAPER))
		        System.out.println("You win!! Scissor cuts paper.");
	        else if (computersMove.equals(ROCK))
		        System.out.println("You lose!! Rock breaks scissors.");
        } 
        else
    	    System.out.println("Invalid user input.");
    }
	/**
	 * Get Computer's move
	 * */
public static String getComputersMove(){
		int computersNum;
		String computersMove="";
		Random random = new Random();
		computersNum = random.nextInt(3) + 1;
		if (computersNum == 1)
			computersMove = ROCK;
		else if (computersNum == 2)
			computersMove = PAPER;
		else if (computersNum == 3)
			computersMove = SCISSORS;
		
		return computersMove;
	}
	/**
	 * Get User's move
	 * */
	
	public static String getUsersMove(){
	    Scanner scanner = new Scanner(System.in);
	    System.out.println("Enter your play: ");
		String input = scanner.next().toUpperCase();
        return input;
    }
	
    /**
     * Main method
     * */	
	public static void main(String[] args) {
		System.out.println( "Rock, Paper, Scissors!\n"
				+ "Please enter a move.\n" 
				+"Rock = R, Paper= P, and Scissors = S.\n");
	
		String userInput = getUsersMove(); 
		if (userInput.equals(PAPER) || userInput.equals(ROCK) || userInput.equals(SCISSORS)) 
			getResult(userInput, getComputersMove());
		else 
			System.out.println("Invalid Input " + userInput);
	}
}

Output

Rock, Paper, Scissors!
Please enter a move.
Rock = R, Paper= P, and Scissors = S.

Enter your play: s

Computer’s move is: R
You lose!! Rock breaks scissors.

The post Java Rock Paper Scissors Game appeared first on The Java Programmer.

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

So you think of learning Java. Good choice! This language is 20 years old but still progressive. The freshest (Java 11) release was in September 2018, and the next one will be in March 2019. Java is platform independent and you can do almost anything with it. Java is object oriented language but you can use different concepts, such as functional programming if you want to. It has very reach API. Java is beginner’s friendly and has the best community and documentation base. And while Java is so popular it is easier to find a good job knowing this language than else.

Well, Java is good…but how to learn it? You can find a lot of different Java courses in Internet or elsewhere. Which one to choose?

This article is about one of the unique Java online courses called CodeGym. It is a Java Core classes from scratch to confident upper intermediate student. It has solid and logical structure. First, you read one or two short theory lectures, then do some (5-10) coding tasks checking them via automated validator. You get the response, recommendations and keep some points. Now you can go to the next lectures etc… What is so special about CodeGym? It stands out for successful ideas and implementation. Now we come to details about this course, its pros and cons.

Learning Through Practice

People are getting use to standard way of learning.  Such as in high school or college. You get the book, start to read it then do some tasks. Theory to practice ratio is about 1/1.

However, programming is a practical skill you can develop only through coding. It is more like dancing, swimming or painting. You can’t learn how to paint or swimming reading books. The same story with programming. You just need to practice more. And the CodeGym creators understand it well. They claimed on their landing page that the course contains 80% of practice… Well, is this true? It looks like the one. Course has 1200 (!) coding tasks. Some of them are very easy, the others are more complicated to solve. You can code for CodeGym in special online IDE right on the site or in IntelliJ IDEA, using special CodeGym plugin.

Together with tasks conditions you get very understandable step by step requirements. They are priceless for the beginners, but probably way too detailed for more experienced students. It would be better for future programmer not using the requirements too often and try to make this up by her or himself.

When you push “verify” button in CodeGym IDE or IDEA Plugin, you get your checked tasks almost in a moment. It is convenient. If something gets wrong with your solution “Virtual trainer” of CodeGym tells you, where you made a mistake and how to fix it. Very valuable feature!

What kind of tasks has CodeGym? It covers all Java Core topics such as Java Syntax, OOP, Structures, Multithreading and a little bit more. You can find there some algorithm problems but not too many, probably it would be nice to have more of these in the course. In the middle of the course you will get some mini projects, bigger and more complicated problems divided by many consecutive steps. For example, once you create your own version of Arkanoid video game.

Gamification

When you solve your problem right, you get so called dark matter – the points you need to open the next lecture or the next level… sounds like a videogame! And it is kind of a game. CodeGym is divided into 40 levels. Each level includes about 15-30 coding tasks, 10-20 Java lectures and motivation articles to cheer up the students.

You have your character, anthropomorphic robot Amigo, nice and full of humor story about spaceship and your teachers from different planets. So you go with your character through the course level by level, collecting and spending the dark matter, and your own programming level is increasing.

Community

It’s alive! So you never feel like you are all alone on CodeGym. This community is quite friendly so if you stuck with your task, you can use this shared mind in Help section. Usually you’ll get the answer for your question fast. Some students and probably administration write new articles about Java and learning process in Group Section. Not all of them are really useful, but some of them definitely are. One more thing: you can write your own article or help others with their tasks, which is very useful for learning.

CodeGym has a lot of motivational lessons and success stories of graduates who are already working as programmers. Judging by the comments made under those stories, they really motivate people to not give up learning.

Conclusion

To become a programmer, you need to program. This phrase could be a motto of CodeGym as well as ‘not to be boring’. CodeGym is not a game but very well structured Java Core course with gamification elements and interesting story. After you solve all the tasks you get about 500 hours of clear programming experience. So in that point you are very close to Java Junior level. Not bad for an online course.

Pros:

  • Well-structured course
  • You’ll get 1200 coding tasks from very easy to tough
  • You can check your code very fast
  • You’ll get the recommendations and tips
  • Community that helps

Cons:

  • Sometimes while you’re coding you are led by the hand like you are little kid
  • Some lectures are well presented some are not
  • Not enough algorithms tasks

The post CodeGym: An Effective Way to Learn Java appeared first on The Java Programmer.

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Separate tags by commas
To access this feature, please upgrade your account.
Start your free month
Free Preview