Blogs  

Java Tutorial For Beginners – Java Programming Made Easy!
Java Lessons for Beginners!

Java concepts are a must for all programmers. Usually, we learn C, C++ for starting, And the next language we learn is Java. In this article, we are going to put in front of you some of the fundamental concepts of Java. And before we start, we need to learn what it is, what are the features of Java and how we can install it. In this blog we are going to cover the installation process of Java, how we write the Hello World program, what member variables are, what are data types and operators, and what are control statements. Then we will go through the classes and objects, and the structure of a program. Finally, we will look into Input and Output handling of the file in Java, and the arrays in Java. And we will finish off the article discussing the OOPS concept and Exception Handling. So, let’s begin the article. And you can contact us for your Core Java online training. Naresh I Technologies is the number one computer training institute in Hyderabad and among the top five computer training institutes in India. Contact us anytime for your Java training.

Installation of Java

You can download Java from here. However, make sure you have an Oracle Account, and you will require to accept the terms and conditions. You need to download the developer version from here. Download Java's latest version. However, remember that JRE has been deprecated from Java 10 onward. Hence now you need not include it in the URL after JDK plus there is no JRE now. This will show when you will be installing the Netbean. Before, when you used to download, both the JDK and the JRE used to be present in the zipped file. However, now you will find only JDK. Download hence and follow all the instructions, and go on clicking ok. Once you install Java successfully, you need to update the Environment variable. You will witness here as well. If you are downloading a version post-Java 10, you need to add only the jdk bin URL in the environment variable path section. Or else you need to add till bin the URL for JRE as well.

Remember we are installing on Windows 10. Go to Start and search for System. And then search for the Advanced System Settings. Now click on Environment variable, and double click on Path. Now go to C drive, and under Program files find Java, and then inside that bin. Now click on the arrow in the Address bar, and copy the URL from there. In case, you have the Java version less than 10, you need to repeat this process for the JRE as well. Now add both of these URLs to the path, which you get after double-clicking on Path in the Environment Variable. Click ok and you are done. Now open the CMD, and enter Java -version. The Java version you downloaded will be shown. Congratulations, you have successfully installed Java on your Windows 10 machine.

Now you need to install the NetBeans or the Eclipse IDE. We are mentioning both so that you can install both of them or anyone. Download NetBeans full version from the internet, and also the Eclipse. Follow the installation process, as it shows. The JDK is required for both, which we have already installed. And the IDE will pick the JDK URL automatically. On successful installation, you need to add the server. And we will show later how to add the Apache Tomcat 9.0 server to the Netbeans. Remember, the web application will run on this Apache Tomcat 9.0 server. Let’s now see how we can curate a Hello world program, and that is our next point of discussion. 

However, before that, let's have a look at some of the salient features of Java. The salient features are as below:

Open Source

Java has always been an open-source product, and all have public access. As a programmer, you can post the entire source code, and it's downloadable by anyone. No license is required, and you get a GPL license or the General public License that we get through the open-source software.

High Performance

It’s an interpreted language, and hence it is not as fast as C or C++. However, it enables the best performance through the just-in-time compiler.

Multi-threading

Through Java, you can perform several tasks simultaneously as it is multithreaded. The advantage is you make use of the same memory and various other resources for executing numerous threads at one time, such as during typing, grammatical errors get checked.

Secure

Java is the best in security. Through its security features, we can develop virus and temper-free systems. And it always run-in runtime environment that has no interaction with the system OS, and therefore secure.

Platform independent

The C and C++ are compiled in platform-specific machines. Whereas Java is writing once, run anywhere programming setup. Java gets compiled into bytecode. And this is platform-independent, and you can run it on any of the machines. It also ensures security. And if the JRE is present on a machine, it can run the Java program.

Portability

The Java code is quite portable, and highly in fact. You can write the code in the windows environment and execute it in the Linux environment.

Object-Oriented

You will find all Java is an object which has data and behavior. And it can be easily extended as it is Object model-based.

Robust

Java to remove error-prone code put weights on runtime and compile-time checking. However, the main improvement in Java is in mishandled exception and memory management through the inclusion of exception handling and the Garbage collector.

Let’s now write the first Java program, which is the Hello world program

Hello World Program

Our first Java program is as below. We have declared a class called HelloWorld and printed the “Hello World” message inside it. The code is as below:

public class HelloWorld { 

      public static void main(String[] args){ 

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

      } 

}

Member variables in Java
Member Variable

It is used to store the data value. There are three ways of declaring the data variable in a class. they are Local variables, instance, and Class/static variables.

Local: It’s the variable declared within a class method shown as below:

public class Student {

      public void PrintStudent(string name){  

           string name1=name;  // This is a local variable

           System.out.println("Student Name is:" +name1);

     }

}

Above we have a local variable name1, declared with the method PrintStudent with parameter “name.”

The Instance variable

public class Student {

      public String name;     // instance variable

      Student(String n){

            name=n;

      }

      public void PrintStudentName() {  // Method 

            System.out.println("The name of the student is:"+name);

      }

public static void main (String args[]){

           Student obj=new Student("NareshIt");

                  obj.PrintStudentName();

      }

}

Above “name” is the instance variable and it gets the value “NareshIt in the main function.

Class Variable or the Static Variable

These variables have one copy stored by all objects in a class. Let’s see the below code.

public class Student {

      public static int HeadBoy;   // This is class or static variable

      public static void main(String args[]){

           HeadBoy="NareshIT";

           System.out.println("HeadBoy is"+HeadBoy);

      }

}

Above “HeadBoy” Is the class variable or the static variable.  And its value remains the same everywhere in the class.

Data types and operators

We make use of the Data type to store various values in a variable. The main data types are Integer, character, float, and Boolean. Various data types under the Integer is the byte, Long, Short, and Int. Various under Float are float and double. Various character types are char, and various Boolean types are Bool. We also have the string data type. And we have used that in the code that we have written till now in this blog post on various instances. 

Now let's have a look at the Operators.

We have mainly four types of operators which are respectively Arithmetic Operators, Unary operators, Logical operators, and relational operators. Let’s discuss each of them one by one.

Arithmetic Operator: The four arithmetic operators are addition, subtract, multiply, divide, and modulus.

Unary Operators: The unary operators are like increment and decrement operators. ++ is the increment and – is the decrement.

Relational Operator: It sets up the relation between the two entities. Like <,>,>=,<=,!=,==

Logical Operator: They are applied to Boolean values.

Before understanding anything else, let's first discuss the oops concept. And then we will continue with the basics of JAVA.

OOPS concepts like Inheritance, Polymorphism, Encapsulation, and Abstraction

Inheritance

We already know what this is. However, let's repeat that it’s the process where one class inherits the other class properties. There are two classes, the child class, and the parent class. It is the child class that inherits the properties of the parent class. it is also the derived class or we also know it as the subclass. And the class from which the child class inherits the properties is the parent class. And we also know it as the base class.

Let’s have one example to understand it more elaborately.

Suppose, there are “Class 9” and “Class 9 passed Students” and “Class 9 failed students”, which are the respective classes. The two of the last classes are the child class. And the first class is the parent class or the base class. You can clearly understand that both passed and failed students of class 9 will have the same list of subjects. Hence, it's not a must that the child class inherits everything from the base class. We do have the scope specifiers which explain what is inherited and what is not.

The inheritance puts aside the code redundancy. There is a long list of inheritance types, and we will discuss that deep in the forthcoming blog post, please be assured. In that post, we will cover Object-oriented programming elaborately.

Encapsulation

We have the data and the code wrapped In one unit and that is the Encapsulation. Or you can experience that methods and variables are bound together in one class. And that is what we know as encapsulation. We can use the class variables only through the class method, and that ensures security. These variables are hidden from other classes but can be inherited through inheritance.

Polymorphism

Through this, we can have multiple forms of the variables, functions, and objects. And the most appropriate example of polymorphism is when various child classes implement the parent class differently. Also, it is implemented while we do the function overloading. The entire concept we will cover in a forthcoming blog, so please do not worry about these for now. One more example, however, is the Teacher asks the students to draw a shape. And the students draw the circles, and some draw the rectangle. This is what we know as Polymorphism.

Let's, however, brief the function overloading here. Suppose we have the three definitions of the same function as below:

Void calculatearea(int a, int b);

Void calculatearea(int radius);

Void calculatearea(float side);

Based on the parameters passed the above same method will calculate the area of the rectangle, circle, or Square. And this is polymorphism. If you still didn’t get it please do not worry. We will have an elaborate post on OOPS soon.

Abstraction:

When talk about calculating an area, we can sometimes use the function, pass the parameters, and get the results. We are only concerned with the results and don’t care about the code and the calculation. Like Data Scientists use the Python methods and they don’t care about the code involved, whereas the data engineer deals with the code. And this is what we know as an abstraction. It makes the task simpler for the layman and puts the burden of coding and the calculation of one other person like above we have the data engineers. 

And that completes the OOPS part for now. If you are finding difficulty in understanding the above, then you need not worry as we will soon cover the OOPS in a separate blog and detail.

Exception Handling

An exception is some issue that is not expected and arises at runtime. It hinders the sequential and normal flow of the program. Hence, we need to resolve it for avoiding the problems. Some of the exceptions are as below.

  • Invalid format for function calling parameter missing
  • Arithmetic out of bound exception
  • Arithmetic divide by zero exception.
  • And so on.

Let’s have a look at one through below code:

public class Student {

    public static void main(String args[]) {

          try {

                 float marks[] = new marks[20];

                 System.out.println("Printing 21st element:" + marks[21]);

          } 

          catch (ArrayIndexOutOfBoundsException e) {

                 System.out.println("The Error encountered is :" + e);

          }

          System.out.println("Out of bound");

    }

}

The output will be “Out of bound” 

Now let’s hit back at the Java Core, and discuss the Control statements.

Why Java is a Popular Programming Language

Java happens to be a very popular programming language that was developed by Sun Microsystems way back in 1995.  And it's still quite popular. You will find in all sources that Java is at no. 5 still among the most popular languages. And around 41% of the Stack Overflow users marked Java as being popular. And you can contact us for your Java training. Naresh I Technologies is the number one computer training institute in Hyderabad and among the top five computer training institutes in India. Contact us anytime for your Core Java training.

In this article, we will be discussing features of Java, why it is so popular, and where Java is being used. And finally, we will end up with a conclusion. And make up in your mind that Java is never going to lose its shine in near future for sure. Hence, let's start our article.

Features of Java

Below are the features of the Java

  1. It's Object-oriented
    All the things in Java act as an object. And it's easily extended as it’s Object model-based.
  2. It's platform-independent
    Unlike others, Java does not get compiled into platform-specific machines. Rather it gets compiled into platform-independent bytecode. This bytecode is distributed over the webs, and the JVM interprets it on whatever platform we run it on. JVM is a Java virtual machine. 
  3. It’s Simple
    You can learn it easily if you know OOPS. You can easily master it.
  4. It's secure
    Java comes with security features. It helps us develop virus-free, tamper-free systems as well as authentication options based on public-key encryption.
  5. Architectural-neutral
    The output of the Java compiler is an architectural neutral object file format, that develops the compiled code executable on almost all the processors if the JVM is present.
  6. It's portable
    As Java is Architectural neutral and does not have any implementation dependency, Java is portable. The java compiler is in C that has clean portability limitations and comes with a POSIX subset.
  7. Robust
    Java emphasizes chiefly the compile-time error checking and other than that run time.  This is an attempt to dismantle the error-prone conditions.
  8. Multi-threading
    Yes, multithreading is possible in Java, and we can carry on numerous tasks in parallel using java. And thus, we can make interactive applications that run quite smoothly.
  9. Interpreted
    Java Bytecode gets translated to the native machine instructions on the fly and is never stored anywhere. You will find development procedure faster, as well as analytical as its quite incremental and lightweight procedure the linking.
  10. High in performance
    Java ensures the best performance through just-in-time compilers.
  11. Distributed
    Java supports the distributed setup on the internet.
  12. Dynamic
    It’s more dynamic as it adapts to a new environment. It can execute an enormous amount of run-time information used for verifying and resolving object access at run time.
Why Java is so popular?

Its code is easy to understand and troubleshoot. And its growing at great speed for many years now as it's object-oriented based, and this makes it simpler for designing the software through breaking of the execution procedure into simpler and easily processed chunks. Various complex coding issues found in languages such as c and c++ are not found in Java. Also, Java ensures better modularity and easily 

Java is independent because of the JRE

JRE is the prime source for making Java platform-independent. You are just required to install the JRE on the computer and then you can run the Java program, and it does not matter where you make it.

Java runs quite smoothly on all the computers and not just Windows. The JRE is even compatible with mobile phones. And as a fresher, you will find this independence and the flexibility to be great for you.

You can easily reuse the common code

Through the Java objects, a programmer can reuse the common codes whenever possible rather than rewriting the whole code again and again. And all the common things between the two objects inside a class are shared so that the developers can focus on the development of uncommon attributes. And thus, the coding becomes simple, inexpensive, and speedier.

The versatility of the Java

You get tons and tons of classes and around 50 keywords through Java API. And this leverages the programmers to apply the coding methods which execute to lacs. Hence the programmers find versatility in Java and able to accommodate numerous coding tactics.  And even a newbie can easily learn the Java API as it is less complex, and you need to learn a part of it only for starting. a portion of it. And as you become comfortable with the utility functions, you can learn all the things related to Java API. And you can run the program across different servers.

Through Java’s PATH and the CLASSPATH, you can distribute the Java program among various servers. And we often need to code using a computer network in a big organization. And we need to sync all the computers ensuring the program runs faultlessly on all the computers.

It's adaptable, robust, and stable 

The Java program runs well on computers as well as mobile devices. And hence Java Language is quite adaptable. And it runs quite perfectly on all the devices. And you can run Java on any scale. And it's quite stable and strong on any scale. And Java has no limitation, and you can develop any software using Java.

It comes with a strong source code editor

We have two very powerful IDEs for crafting the Java programs and they are the NetBeans and Eclipse. And these are very powerful and ensures faster and easier coding, and you also get with them an automated built-in debugger option. And all the features of an IDE are available through NetBeans and Eclipse.

You can hence think of Java as your career, and you will find that a lot many companies are making use of Java programming still for web application and website development as well as software development. And hence you can get a job easily as a Java programmer.

Where is Java being used?

As a fresher, you might be wondering where Java is being used. You will not find a lot of games in Java. Also, the majority of desktop tools are in other languages. Also, the major OS is not in Java. So, the question arises where Java is being used? Is there any real-world application developed using Java? And why Java is considered so highly in graduation courses. You run Java by installing the Java on your desktop. According to Oracle, more than 3 billion devices are run using Java. And that is a huge number. The majority of businesses make use of Java in some form. You will find a lot of server-side applications coded in Java. And below we list the kind of projects which use Java. Also, we list the sector and domains where Java is dominating. And we discuss where Java is being used in the real world.

Real-World Java Applications

Various commercial eCommerce websites and android apps make use of Java. A lot of financial applications make use of Java. You can build games as well as desktop applications in Java as well. J2ME is used extensively in embedded devices. Let’s elaborate all.

  • Android Apps

All the Android developers make use of the Java programming language. And the Google Android API is quite similar to the JDK. You will find that majority of Android app developers were Java Developers in the past. The Android, however, makes use of different JVM and new packaging, though the coding still is done in Java only.

  • Server Apps 

Java is used extensively in financial services. However, you will find that Java is mainly used for writing server-side applications, and it's not generally used for making the front end, that gathers the data from one server, processes, and then sends that to another process. Swing used to be applied for making client GUI, however, it is being now replaced by C#.  Mainly, you will hence find the Java being used for creating the backend servers.

  • Java Web applications

A lot of web applications are made using Java. Various RESTFUL services make use of Spring MVC, Struts, and various frameworks like these. You will find that even smaller servlet, struts, and JSP-based web applications have become quite known. Various government, insurance, defense, and various other departments make use of Java to make web applications.

  • Software Tools

Various desktop applications are written in Java like Eclipse, NetBeans IDE, IntelliJ Idea, and various others. At one time Swing was used extensively for writing thick clients, and was used mostly by the investment banks and the financial services. Now the Java FX is becoming more and more popular though it's not the replacement of the Swing and C# is the actual replacement for Swing in finance.

  • Trading Applications

Java is also used extensively in coding third-party trading applications, which is a good part of financial services.

  • J2ME Apps

Even after the IOS and the Android, J2ME is not finished, and still holds the big share in low-end Nokia and Samsung mobiles that make use of the J2ME. You will find them being used in games, and applications in Android through MIDP and CLDC that are part of the J2ME platform. You will find J2ME still being used extensively in cards, set-top boxes, and various others. You will be surprised to know that WhatsApp is also available in J2ME for various Nokia handset and it’s the reason for WhatsApp success to an extent as well.

  • Embedded Space

You will also find Java being used extensively in embedded systems, as we need only 130 KB to make use of the Java technology on the smart card and sensors. You should know that Java in originality was for embedded systems, and that was Java's initial campaign, “write once use anywhere” and now it's showing the fruit. 

  • Big data technologies 

Hadoop and various big data technologies make use of Java. Like the HBASE and the Accumulo as well as Elasticsearch make use of Java, Java is not dominant here as it's now superseded by technologies like MongoDB, which is written in C++. However, its products like Hadoop and Elasticsearch make use of Java extensively.

  • High-frequency trading Space

Java can deliver performance at the C++ level. And hence we use Java in coding high-performance systems. However, the performance is a little less as compared to the native languages. However, it ensures safety, maintainability, and portability as well as speed.

  • Scientific Applications

For all the scientific applications the Java is the default application, and may it be natural language processing, Java is extensively used. Its because Java is more safe, maintainable, and portable, and is available with high-level concurrency tools such as C++ or any of the languages.

If you will go back to the 90s Java used to be everywhere on the internet because of Applet though, over the years, Apple became less popular, and this was due to security issues due to the sandboxing model of Applet. And now Desktop Java and the Applet are no more used, though Java is the default application development language in the Software industry, and is used heavily in the financial industry, E-commerce web application sector, investment banks. And hence, Java has quite a good future. And Java will be continuing its dominance in software development for many more years.

Naresh I Technologies is the number one computer training institute in Hyderabad and among the top five computer training institutes in India. Contact us anytime for your Java training. You can also opt for Java online training, and from any part of the world. And a big package is waiting for you. And all is yours for a nominal fee affordable for all with any range of budget. Let's have a look at what you will get with this Java training package:

  • You need to pay a nominal fee.
  • You can choose any Java certification, as per your skills and interest.
  • You have the option to select from online and classroom training.
  • A chance to study at one of the best Java training institutes in India 
  • We provide Java training in Hyderabad and USA, and no matter in which part of the world you are, you can contact us.
  • Naresh I technologies cater to one of the best Java training in India.
  • And a lot more is waiting for you.

Contact us anytime for your complete Core Java online training.