Introduction to Programming Using JAVA

Hello Everyone! I am M.R.K.SIVA NAGA SAI. Currently I am pursuing my Masters in NATIONAL INSTITUTE OF TECHNOLOGY CALICUT, with Signal Processing as my specialization. Today I would like to share my experience of my learning era with TestPrepTraining.com, by using their Test Series. I completed and acquired the knowledge in 2 courses. They are: 

1. Introduction to programming using PYTHON.

2. Introduction to programming using JAVA. 

In the previous Section, I explained “How I benefitted through Introduction to Programming using PYTHON” course. Now I will share my views of my journey through Testpreptraining.com with Introduction to programming using JAVA also!! 

You can access the Testpreptraining’s Test Series Content from this link: 

https://www.testpreptraining.com/introduction-to-programming-using-java-98-388- certification-exam 

Before going to the topic, I will explain why I completed PYTHON, then to JAVA. Python has several Pros and very easier for beginner to start and enter into Competitive coding. 

Python is a popular, high-level, general purpose, dynamic programming language that has been present on the market for almost 30 years now. It can be easily found almost anywhere today: web and desktop apps, machine learning, network servers and many more. It’s used for small projects, but also by companies like Google, Facebook, Microsoft, Netflix, Dropbox, Mozilla or NASA. Python is becoming very popular in the world of programming. It’s growing faster than other languages, and it’s expected to become even more popular than Java in 2019. Job search engines also say that Python is one of the top three languages that can help you earn a good income. So, lots of programmers are learning and using Python.

Other Important advantages are: 

  • It’s open source and has a lively community.
  • It comes with a wide range of libraries.
  • Perfect for making prototypes, allowing you to do a lot with less code.
  • Has speed limitations.
  • Faces challenges with threading.
  • Not Native to Mobile Environment.

By considering all these benefits, I preferred Python to JAVA. Python coding is very useful to do projects in Machine Learning, AI and Data science. But java would be widely used in Embedded and Cross Platform applications. As I am studying M.Tech with Signal Processing as my specialization, I opted for Python. 

Then why we should learn JAVA? 

This is a perfect question for Java Lover. Java & Python both have secret magic, everyone is comparing both of them! 

Advantages of Java over Python: 

1. Java is Static type system and Python is Dynamic type system.J

2. Java is a better choice for cross platform support

3. Java is Faster than Python.

4. Java is Platform independent, python is not.

5. Java has support for concurrency and python is more resolutely a sequential  language.

6. Java is more verbose than Python.

7. Java is ideal for android and IoT development and Python is for Data Science (Mainly).

8. Java has Strong database connectivity on the other hand Python has weaker database access than java.

9. Java is in demand from last decades.

10. Java is compiled and Python is interpreted Language.

11. Today, 95 % of the enterprise are using Java and more than 1 billions Smart phone are having Java in them. 

The IDE support situation…This is most Important and we can say Prime comparision!! 

The strict typing makes it way easier to provide auto-completion for Java. 

For example, Let’s consider a sample code in Python… 

1. myVar = getRecord() 2. myVar.<lets autocomplete here> 

An IDE cannot reliably autocomplete the methods on myVar, because it does not, and cannot know what it is, as Python allows you to return anything (or nothing) from a method without declaring what that might be. 

Another example… In Python… 

1. if a == 1: 2. print “hmmm?” 3. if b == 2: 4. print “woop!” 

If I want my IDE to autoformat the above code, it can’t. Is the second “if” nested in the first? We can’t know, as Python doesn’t explicitly declare the end of scope. So the IDE can’t help you. In such cases, JAVA is quite preferrable 

Article on TestPrepTraining’s: Introduction to Programming Using JAVA – M.R.K.S.N.SAI 

JAVA Course Content and its Test Series outline: 

In our TestPrepTraining.com, the course is arranged in well systematic order. 

1. Introduction to Java Programming 

• Course Introduction 

• Course Objectives 

• Course Overview 

• Using the Workbook 

• Suggested References 

2. Getting Started with Java 

• What is Java? 

• How to Get Java 

• A First Java Program 

• Compiling and Interpreting Applications 

• The JSDK Directory Structure

3. Eclipse 

• Introduction to Eclipse 

• Installing Eclipse 

• Running Eclipse for the First Time 

• Editors, Views, and Perspectives 

• Setting up a Project 

• Creating a New Java Application 

• Running a Java Application 

• Debugging a Java Application 

• Importing Existing Java Code into Eclipse

4. Language Fundamentals 

• A Java Program 

• If Statements 

• Switch Statements 

• Loop Statements 

• Syntax Details 

• Primitive Datatypes 

• Variables 

• Expressions in Java 

• Strings 

• Arrays 

• Enhanced for Loop 

5. Objects and Classes 

• Defining a Class 

• Creating an Object 

• Instance Data and Class Data 

• Methods 

• Constructors 

• Access Modifiers 

• Encapsulation

6. Using Java Objects 

• Printing to the Console 

• Printf Format Strings 

• StringBuilder and StringBuffer 

• Methods and Messages 

• toString 

• Parameter Passing 

• Comparing and Identifying Objects 

• Destroying Objects 

• The Primitive-Type Wrapper Classes 

• Enumerated Types

7. Inheritance in Java 

• Inheritance 

• Inheritance in Java 

• Casting 

• Method Overriding 

• Polymorphism 

• Super 

• The Object Class

8. Advanced Inheritance and Generics 

• Abstract Classes 

• Interfaces 

• Using Interfaces 

• Collections 

• Generics 

• Comparable

9. Packages 

• Packages 

• The import Statement 

• Static Imports 

• CLASSPATH and Import 

• Defining Packages 

• Package Scope 

10. Exception Handling 

• Exceptions Overview 

• Catching Exceptions 

• The finally Block 

• Exception Methods 

• Declaring Exceptions 

• Defining and Throwing Exceptions 

• Errors and Runtime Exceptions

11. Input/Output Streams 

• Overview of Streams 

• Bytes vs. Characters 

• Converting Byte Streams to Character Streams 

• File Object 

• Binary Input and Output 

• PrintWriter Class 

• Reading and Writing Objects 

• Closing Streams

12. Core Collection Classes 

• The Collections Framework 

• The Set Interface 

• Set Implementation Classes 

• The List Interface 

• List Implementation Classes 

• The Queue Interface 

• Queue Implementation Classes 

• The Map Interface 

• Map Implementation Classes

13. Appendix A – Collection Sorting and Tuning 

• Sorting with Comparable 

• Sorting with Comparator 

• Sorting Lists and Arrays 

• Collections Utility Methods 

• Tuning ArrayList 

• Tuning HashMap and HashSet

14. Appendix B – Java EE Overview 

• Introduction to Java EE 

• Java SE Building Blocks 

• Web Applications 

• Web Services 

• Enterprise JavaBeans 

• Additional J2EE APIs 

• POJO, Dependency Injection, and Annotations 

• The Java EE Platform

15. Appendix C – Eclipse Shortcuts 

• Shortcut Key Sequences 

• More Shortcut Key Sequences 

Do you know about 5 Primary goals of JAVA? 

There were five primary goals in the creation of the Java language: 

1. It must be simple, object-oriented, and familiar.

2. It must be robust and secure.

3. It must be architecture-neutral and portable.

4. It must execute with high performance.

5. It must be interpreted, threaded, and dynamic. 

Besides Seeing the course videos, we should be able to code daily. In what view we should start our coding practice, to absorb the concepts systematically?? That’s should be taken take. 

You can access the TestPrepTraining.com’s Test Series Content from this link: 

https://www.testpreptraining.com/introduction-to-programming-using-java-98-388- certification-exam 

So we should opt for daily practicing of coding such that we will derive the new corners of the Programming Language. Not only JAVA, If choose C, Python… any Language needs good practice to cherish in it. While I was practicing, I found out few things which exclaimed me. They are all seems to be general for programmer, but those things were exclaimed me!! 

Hello world Program 

The traditional Hello world program can be written in Java as: 

public class HelloWorldApp { 

public static void main(String[] args) { 

System.out.println(“Hello World!”); // Prints the string to the console. 

Every source file in Java should have the same name as the public class it contains, followed by “.java.” For instance, if it has a public class called “HelloWorldApp,” the file should be named “HelloWorldApp.java.”

Before you can run it, you must first turn it into bytecode using a Java compiler. This will create a file with the “.class” extension, like “HelloWorldApp.class.”

In a Java source file, you can have just one public class. However, you can have multiple classes with non-public access and any number of public inner classes. When your source file has multiple classes, one class must be declared public (using the “public” keyword), and the source file should be named after that public class.

A class that is not declared public may be stored in any .java file. The compiler will generate a class file for each class defined in the source file. The name of the class file is the name of the class, with .class appended. For class file generation, anonymous classes are treated as if their name were the concatenation of the name of their enclosing class, a $, and an integer. 

The keyword public denotes that a method can be called from code in other classes, or that a class may be used by classes outside the class hierarchy. The class hierarchy is related to the name of the directory in which the .java file is located. This is called an access level modifier. Other access level modifiers include the keywords private(a method that can only be accessed in the same class) and protected(which allows code from the same package to access). If a piece of code attempts to access private methods or protected methods, the JVM will throw a SecurityException 

The keyword static in front of a method indicates a static method, which is associated only with the class and not with any specific instance of that class. Only static methods can be invoked without a reference to an object. Static methods cannot access any class members that are not also static. Methods that are not designated static are instance methods and require a specific instance of a class to operate. 

The keyword void indicates that the main method does not return any value to the caller. If a Java program is to exit with an error code, it must call System.exit() explicitly. 

The method name main is not a keyword in the Java language. It is simply the name of the method the Java launcher calls to pass control to the program. Java classes that run in managed environments such as applets and Enterprise JavaBeans do not use or need a main() method. A Java program may contain multiple classes that have main methods, which means that the VM needs to be explicitly told which class to launch from. 

The main method in Java needs to take in an array of String objects. Usually, people call this array “args,” but you can use a different name if it follows the rules.

Starting from Java 5, the main method can also use something called “variable arguments.” Instead of just “String[] args,” you can write “String… args,” which means you can give the main method any number of String arguments. The result is the same as before (it’s still treated as an array of String objects), but it provides a different way to create and pass that array.

The Java launcher launches Java by loading a given class (specified on the command line or as an attribute in a JAR) and starting its public static void main(String[]) method. Stand-alone programs must declare this method explicitly. The String[] args parameter is 

Article on TestPrepTraining’s: Introduction to Programming Using JAVA – M.R.K.S.N.SAI 

The “main” method in Java takes an array of words or phrases called “arguments” that you pass to the class. These arguments are usually given through the command line when you run a Java program.

To display information on the screen in Java, we use something called “printing.” Java has a built-in way to do this using the “System” class, which has a special object called “out.” This “out” object belongs to the “PrintStream” class and has various methods for printing stuff on the screen. One common method is “println(String),” which not only displays the given text but also adds a new line afterward.

The string “Hello World!” is automatically converted to a String object by the compiler. 

This is the basic thing which I known in my initial days. Gradually, while I was keep on practising rigorously, I came to knew about the following things also… 

Applet 

Java applets were programs that were embedded in other applications, typically in a Web page displayed in a web browser. The Java applet API is now deprecated since Java 8 in 2017. Servlet 

Java servlet technology provides Web developers with a simple, consistent mechanism for extending the functionality of a Web server and for accessing existing business systems. Servlets are server-side Java EE components that generate responses (typically HTML pages) to requests (typically HTTP requests) from clients

The Java servlet API has to some extent been superseded by two standard Java technologies for web services: 

• The Java API for RESTful Web Services (JAX-RS 2.0) useful for AJAX, JSON and REST services, and 

• The Java API for XML Web Services (JAX-WS) useful for SOAP Web Services

JavaServer Pages 

JavaServer Pages (JSP) are like computer programs that run on a web server. They create web pages, usually in HTML, when someone asks for them through a web browser. JSPs mix regular HTML with special markers (<% and %>) to include Java code.

When you visit a JSP web page, it’s turned into a special kind of Java program called a servlet. This happens the first time you access it. Afterward, this servlet handles making the web page every time it’s requested.

Swing application 

Swing is a tool that helps create the visual part of computer programs in Java. You can make it look like different styles, such as Windows, GTK+, or Motif. Sun, the company behind Java, offers these styles, and Apple has one called Aqua for Mac.

In older versions, Swing didn’t always look quite right on different systems. But in Java SE 6, they improved it by making it use the computer’s own way of drawing buttons and windows, which makes it fit in better with the rest of the system.

JavaFX application 

JavaFX is a program for making desktop and web applications that can work on many different devices. It’s meant to take over from Swing, another program used for making the visual part of Java programs, but Swing will still be around for a while.

JavaFX works on Windows, Linux, and macOS, but it doesn’t try to copy the look of those systems exactly. Instead, it has its own style.

Generics 

In 2004, generics were added to the Java language, as part of J2SE 5.0. Prior to the introduction of generics, each variable declaration had to be of a specific type. For container classes, for example, this is a problem because there is no easy way to create a container that accepts only specific types of objects. Either the container operates on all subtypes of a class or interface, usually Object, or a different container class has to be created for each contained class. Generics allow compile-time type checking without having to create many container classes, each containing almost identical code. In addition to enabling more efficient code, certain runtime exceptions are prevented from occurring, by issuing compile- time errors. If Java prevented all runtime type errors (ClassCastExceptions) from occurring, it would be type safe

The Java Class Library is the standard library, developed to support application development in Java. It is controlled by Oracle in cooperation with others through the Java Community Process program.[69] Companies or individuals participating in this process can influence the design and development of the APIs. This process has been a subject of controversy during the 2010s.[70] The class library contains features such as: 

• The core libraries, which include: 

o IO/NIO o Networking o Reflection o Concurrency o Generics o Scripting/Compiler 

o Functional programming (Lambda, Streaming) o Collection libraries that implement data structures such as lists, dictionaries, 

trees, sets, queues and double-ended queue, or stacks[71] o XML Processing (Parsing, Transforming, Validating) libraries o Security[72] o Internationalization and localization libraries[73] 

• The integration libraries, which allow the application writer to communicate with external systems. These libraries include: 

o The Java Database Connectivity (JDBC) API for database access o Java Naming and Directory Interface (JNDI) for lookup and discovery o RMI and CORBA for distributed application development o JMX for managing and monitoring applications 

• User interface libraries, which include: 

o The (heavyweight, or native) Abstract Window Toolkit (AWT), which provides GUI components, the means for laying out those components and the means for handling events from those components o The (lightweight) Swing libraries, which are built on AWT but provide (non- 

native) implementations of the AWT widgetry o APIs for audio capture, processing, and playback o JavaFX 

• It’s a version of the Java virtual machine that runs Java programs and third-party apps, but it’s made specifically for a certain type of computer system.

• Plugins, which enable applets to be run in web browsers 

• Java Web Start, which allows Java applications to be efficiently distributed to end users across the Internet 

• Licensing and documentation 

Implementations 

Oracle Corporation is the company that now owns and manages the official version of the Java SE platform. They got it when they bought Sun Microsystems in 2010. This version of Java is built on the original one made by Sun.

You can use Oracle’s Java on Microsoft Windows (it even works on older versions like XP, but they only officially support newer ones), macOS, Linux, and Solaris.

Since Java doesn’t have a formal standard accepted by big organizations like Ecma International, ISO/IEC, or ANSI, the Oracle version has become the widely accepted standard that most people use.

The Oracle implementation is packaged into two different distributions: The Java Runtime Environment (JRE) which contains the parts of the Java SE platform required to run Java programs and is intended for end users, and the Java Development Kit (JDK), which is intended for software developers and includes development tools such as the Java compiler, Javadoc, Jar, and a debugger. Oracle has also released GraalVM, a high performance Java dynamic compiler and interpreter. 

OpenJDK is another notable Java SE implementation that is licensed under the GNU GPL. The implementation started when Sun began releasing the Java source code under the GPL. As of Java SE 7, OpenJDK is the official Java reference implementation. 

The goal of Java is to make all implementations of Java compatible. Historically, Sun’s trademark license for usage of the Java brand insists that all implementations be compatible. This resulted in a legal dispute with Microsoft after Sun claimed that the Microsoft implementation did not support RMI or JNI and had added platform-specific features of their own. Sun sued in 1997, and, in 2001, won a settlement of US$20 million, as well as a court order enforcing the terms of the license from Sun.[75] As a result, Microsoft no longer ships Java with Windows. 

Platform-independent Java is essential to Java EE, and an even more rigorous validation is required to certify an implementation. This environment enables portable server-side applications. 

Use outside the Java platform 

The Java programming language requires the presence of a software platform in order for compiled programs to be executed. 

Oracle supplies the Java platform for use with Java. The Android SDK is an alternative software platform, used primarily for developing Android applications with its own GUI system. 

Android 

The Android operating system makes extensive use of Java-related technology. The Java language is a key pillar in Android, an open source mobile operating system. Although Android, built on the Linux kernel, is written largely in C, the Android SDK uses the Java language as the basis for Android applications but does not use any of its standard GUI, SE, ME or other established Java standards.[76] The bytecode language supported by the Android SDK is incompatible with Java bytecode and runs on its own virtual machine, optimized for low-memory devices such as smartphones and tablet computers. Depending on the Android version, the bytecode is either interpreted by the Dalvik virtual machine or compiled into native code by the Android Runtime. 

Android does not provide the full Java SE standard library, although the Android SDK does include an independent implementation of a large subset of it. It supports Java 6 and some Java 7 features, offering an implementation compatible with the standard library (Apache Harmony). 

I would like to conclude with this quote… 

Truth can only be found in one place: the code. 

This line keeps motivating me, throughout my competitive coding journey!! 

Happy Coding ☺ 

Menu