Skip to main content

Posts

Showing posts from August, 2020

Conditional Statements

If I give you a number and asked you to find whether it is even or odd.  You can easily answer the question as we know how to check whether the number is even or odd. There are several techniques for that : * Method 1 : If the last digit of the given number is [0 or 2 or 4 or 6 or 8], then it is an even number, otherwise it is an odd number. * Method 2 :  If the given number is exactly divisible by 2, then it is even number, otherwise it is an odd number. We can check whether the number is exactly divisible by another number by using the "%" (remainder after division) operator. If the remainder is 0, then the first number is exactly divisible by the second number.  * Method 3 : The simplest way is, find the bitwise AND of the given number with 1. If the result is 1, then the given number is odd, if the result is 0 it is even. Let me explain, how this works, Ex : Given number 6 Here we are considering only 8 bits as the numbers are small. Internally an integer value is store

Comments

Comments are used in the program just to give the information to the person who reads your code, not the compiler. The compiler don't executes the comments, it just ignores them. There are two types of comments depending on the number of lines you want to write. If your comment is single line : Use "//" in the beginning of the line. If your comment is multiple lines : Use "/*" in the beginning of the comment, and "*/" in the end of the comment. NEXT

Operators

You have just learnt how to declare variables. Now let's know  what we can do with the variables. Operators takes some input and returns the result back. For example, The expression a + b returns the sum of a and b; We can store the result in another variable also. c = a + b; Then the sum of variable a and variable b is stored in variable c. The operators supported by Java are :  Arithmetic operators  : (works on two variables) + : returns the sum of two variable - : returns the difference between two variables * : returns the multiplication of two variables / : returns the quotient by dividing one variable with the other % : returns the remainder by dividing one variable with the other Comparison operators  : (works on two variables) == :  returns true if two variables has the same values. otherwise returns false. != :  returns false if two variables has the same values. otherwise returns true. >   :  returns true if

How to declare the variables

We can declare and define variables using the below format :  datatype variable_name; (or) datatype variable_name = initial_value; Some Examples :   int a; float c; char ch; int value = 10; double d = 5.26; char mycharacter = 'f'; boolean b = true; NEXT

Built-in DataTypes

In the process of solving any problem, you might need to work with different type of inputs.  Java has 8 built-in datatypes (primitive datatypes) :  byte, short, int, long, float, double, boolean, char byte : used to store numbers from -128 to 127 short : used to store numbers from -32,768 to 32767 int : used to stores numbers from - 2 31   to   2 31  - 1 long : used to store numbers from - 2 63   to   2 63  - 1 float : used to store decimal point numbers (32-bit) (Ex : 5.26) double : used to store decimal point numbers with double precision (64 - bit)  boolean : used to store only two values [true, false] char : used to store a single character (Ex : w) NEXT

How to Display Text on Monitor

In the case of competitive programming, we need to read some input from keyboard, do some process with them, and display the result on the monitor. To display text on monitor, you have to use System.out.println() function. For example, if you want to display "Hello World" on monitor, the program will be as follows : If you run the program, the output will be, The function displays the any text / string that is written inside the double quotation marks.   Now you can display anything on the monitor. We will discuss the above function clearly once we learn the the concept of classes. Practice is the most important thing while learning any programming language ! NEXT

Do Remember this

In most of the topics we are going to discuss from now, you will see the following code. Don't panic . I am not going to explain the above code now. I recommend you to remember the above code until we come across the concept of classes. It is not that much easy to learn about classes in the beginning itself. Please be patient for some time :) NEXT

Why to learn Java !!!

There are many programming languages in the world but you are here to learn Java. Let's know what we can make with Java. Java is majorly used in : 1. Web Development (Websites) 2. Mobile Application Development (Android) 3. Desktop Applications (Windows, Mac ..etc) and many... Advantages :   Large Developer Community :      If we struck at a point, we can search for that question in internet and find the best solution as we have many developers around the globe working with Java. Platform Independent  :      We can write Java code once, generate byte code and we can run that byte code on any machine whether it is Windows or Mac. Disadvantages :   A bit slower than C and C++  :      Reason : Java is an interpreted language. NEXT

New to Java ? You are at right place !

Hi, we are here to help you out to learn Java from basic to advanced level.  The steps involved in solving a problem  are : * Understand the problem * Design / Develop a solution * Tell your solution to the computer using a language. To solve a problem, language is not important. It is just a mediator between you and the computer. You have to develop the solution (i.e. Algorithm) independent of the programming language . To run java code, you have to install Java on you machine. You can watch videos in Youtube to install java. You can also run Java using online compilers. For example : Paiza Online Java Compiler Let's begin !!!  NEXT