Understanding the basics is the key to a solid foundation. In this section, learn the basic terminologies, naming conventions, reserved words, conditions, functions, data structures, OOP, packages, etc.
* To print output use --> System.out.println();
* To take input from user --> Scanner or BufferedReader class can be used
Variable in Java is a data container that stores the data values during Java program execution. Every variable is assigned a data type, which designates the type and quantity of values it can hold. Variable is a memory location name of the data. The Java variables have mainly three types: Local, Instance and Static.
Data Types are divided into two group -
* Primitive - byte,short,int,long,float,double,boolean and char
<BadgeLinkcolorScheme='yellow'badgeText='Read'href='https://www.educative.io/answers/what-are-conditional-statements-in-programming'>What are Conditional statements?</BadgeLink>
A method/function is a way to perform some task. Similarly, in programming like Java, a function method is a block of code written to perform a specific task repeatedly. It provides reusability of code. We write the function once and use it many times. It works on the 'DRY' principle i.e., "Do not repeat yourself".
Steps -
1. Define function - datatype function_name(parameters){body}
As the name indicates itself, a **Data Structure** is a way of organizing the data in the **memory** so that it can be used efficiently. Some common data structures are array, linked list, stack, hashtable, queue, tree, heap, and graph.
* Array allocates continuous memory for homogeneous data
* Linked List stores data in nodes with references
Learn how to work with files i.e., reading, writing and deleting, files and folders, etc. Also, learn how to make API calls, parse the incoming response, and so on.
* FileWriter - this class is useful to create a file by writing characters into it
* FileReader - this class is useful to read data in form of characters from file
A package is a namespace that mainly contains classes and interfaces. For instance, the standard class `ArrayList` is in the package `java.util`. For this class, `java.util.ArrayList` is called its fully qualified name because this syntax has no ambiguity. Classes in different packages can have the same name. For example, you have the two classes `java.util.Date` and `java.sql.Date`, which are different. If no package is declared in a class, its package is the default package.
To create package use this command -> javac -d directory javafilename
<BadgeLinkcolorScheme='blue'badgeText='Official Site'href='https://docs.oracle.com/javase/8/docs/api/java/lang/Package.html'>Packages in Java</BadgeLink>
In Java and other programming languages, loops are used to iterate a part of the program several times. There are three types of loops in Java, `for`, `while`, and `do...while`.
In Java and other programming languages, loops are used to iterate a part of the program several times. There are four types of loops in Java, `for`, `forEach`, `while`, and `do...while`.
* Synatx of `for` loop is `for(initialization;condition;increment/decrement){}`
* Syntax of `forEach` loop is `for(data_type variable:array_name){}`
Exception Handling in Java is one of the effective means to handle the runtime errors so that the regular flow of the application can be preserved. Java Exception Handling is a mechanism to handle runtime errors such as ClassNotFoundException, IOException, SQLException, RemoteException, etc.
There are three types of exceptions -
1. Checked Exception - exceptions checked at compile time. Example - IOException
2. Unchecked Exception - exceptions checked at run time. Example - NullPointerException
3. Error - It is irrecoverable. Example - OutOfMemoryError