Page not found – ShopingServer Wiki http://wiki.shopingserver.com Tutorials and Articles About Technology and Gadgets Sat, 10 Oct 2020 05:37:02 +0000 en-US hourly 1 https://wordpress.org/?v=5.5.14 http://wiki.shopingserver.com/wp-content/uploads/2018/07/cropped-favicon-150x150.png Page not found – ShopingServer Wiki http://wiki.shopingserver.com 32 32 Why is it essential to know the basics of information security http://wiki.shopingserver.com/why-is-it-essential-to-know-the-basics-of-information-security/ http://wiki.shopingserver.com/why-is-it-essential-to-know-the-basics-of-information-security/#respond Sat, 10 Oct 2020 05:37:02 +0000 http://wiki.shopingserver.com/?p=28178 The importance of information security today is not hidden from anyone who works in the field of information technology. Websites, various software, and networks are all constantly under threat,

and these threats and vulnerabilities are often addressed when a successful attack occurs but the incident must be remedied before it occurs.

Information security Because potential security threats can occur and cause damage at various levels, it is essential for a large portion of IT professionals to be familiar with the basics of information security.

Software developers have sufficient knowledge of information security to eliminate vulnerabilities in their products and to be able to identify where the problem is in the event of an attack.

Network administrators need to have enough information about the basics of information security to apply the necessary security protocols and be aware of existing vulnerabilities, not based on conventional rules and stereotypes, but precisely based on their network conditions and needs.

They must be able to prioritize threats, and in the event that a network is attacked,

they must be able to respond to threats as quickly as possible and minimize damage.

Many resources are available on various topics related to information security.

In some of these sources, it is enough to mention the do’s and don’ts without giving the audience a basic knowledge about why these do’s and don’ts,

and there are other categories of resources that are so specialized and detailed that not everyone can study them.

The Facebook website plans to publish a collection of articles on information security fundamentals.

This series of articles tries to explain the key and basic issues related to information security,

so that the reader acquires sufficient knowledge about the various security protocols and tools and knows how each works and On what basis are they designed?

 Knowing this, the strengths and weaknesses of each can be identified and each tool is used in the right place and in the right way.

At the same time, addressing theoretical issues should not prevent one from engaging with real and practical issues. This series of articles, which will be gradually published on the Physite website, is written with such an approach.

This series covers articles on encryption, access control, security protocols, and software, respectively. The main reference in preparing these articles is the second edition of Information Security Principles and Practice.

This book is used as an academic reference in information security courses. The author of this book, Mark Stamp, is a professor at the University of San Jose in the United States and has written this book after 20 years of work in the field of information security.

 

]]>
http://wiki.shopingserver.com/why-is-it-essential-to-know-the-basics-of-information-security/feed/ 0
Familiarity with the key concepts of information security http://wiki.shopingserver.com/familiarity-with-the-key-concepts-of-information-security/ http://wiki.shopingserver.com/familiarity-with-the-key-concepts-of-information-security/#respond Sat, 10 Oct 2020 05:29:42 +0000 http://wiki.shopingserver.com/?p=28176 We have already read in the zero part of the collection of articles on the basics of information security why having knowledge of information security is a necessity for all IT activists.

Confidentiality and accuracy of information and accessibility are the basic concepts that we want to address in the continuation of the collection of articles teaching the basics of information security. In these articles, we look at ways to ensure that these conditions are met. But first we must have a clear understanding of the definition of these words to know exactly what goals we are seeking to achieve.

Welcome to Jafar Bank

Meet the characters that are going to accompany us in these articles.

Jafar - Manager of Jafar Bank

This is Jafar. Jafar has recently set up a bank called Jafar Bank.

Morteza - a normal user

This is Morteza. Morteza is one of the people who has an account in Jafar Bank. He uses Jafar Bank online system to perform transactions and receive financial reports. He is a law-abiding and ordinary user and never takes any action that damages the system.

Javad - Hacker and information security specialist

Unlike Morteza, Javad, whom you see in the picture above, is always looking to damage the system. He intends to harm Jafar in any way possible. You are looking for solutions that can stop Javad.

Confidentiality

Confidentiality means preventing information from being read without permission. For example, the balance of Morteza’s account in Jafar Bank is confidential information, if Javad can read this information, the confidentiality of the information is endangered.

To maintain the confidentiality of your information, you must ensure that any information is readable only by authorized persons.

Information Integrity

You should always make sure that the information in your system is correct. To do this, it must not be possible to write information without permission, or at least write information without permission must be recognizable so that you can identify which information in the system is incorrect.

Information integrity, then, means preventing unauthorized writing or at least detecting unauthorized writing.

Note that the accuracy of the information and the confidentiality of the information should not be confused. Javad may not be able to read the balance of Morteza’s account, in which case the confidentiality of the information is preserved,

but if he can replace the amount saved as the balance of Morteza’s account with a new value, then the accuracy of the information is compromised.

Availability

DOS attacks or denial of access are relatively new attacks. In these attacks, access to the system becomes impossible without disclosing confidential information or altering existing information. Javad,

who cannot be informed of the confidential information in the system and cannot destroy the accuracy of the information, may want to block access to Jafar Bank’s online system.

In this case, Morteza loses his trust in Jafar Bank and withdraws his money and opens an account in another bank.

You need to make sure that systems and information are always accessible while maintaining the confidentiality and accuracy of the information.

Authentication

Consider Morteza turning on his laptop and using it to make a transaction in Jafar Bank online system. In the first stage, how should Morteza laptop know that the person who works with the laptop is Morteza?

In a single computer, this is usually done by assigning a password to users, and encryption methods are used to make this process secure.

And In the next article, we will look at cryptography.

The process by which we verify a user’s identity is called Authentication. Morteza’s laptop has a password that only Morteza knows, so when he enters the password correctly, it becomes clear that the person using the laptop is really Morteza.

But network authentication faces more threats. For example, Javad may be able to eavesdrop on messages exchanged on the network. He may also be able to manipulate them. Suppose he can resend one of the previous messages sent by Morteza to Jafar Bank.

In this case, he may be able to introduce himself as Morteza. This type of attack is called a Man in the middle attack, which we will cover in later articles.

To prevent this from happening, the exchange of messages must be done exactly according to certain protocols. This means that the composition and order of the messages exchanged is very important and must follow a certain pattern. Encryption methods also have wide applications in the network-based authentication process.

Authorization

After Morteza’s authentication process was done correctly in Jafar Bank’s online system and it was verified that the person claiming to be Morteza is really Morteza, what information should be made available to him?

After authentication, permissions and permissible behaviors should be restricted, for example, Morteza should not be able to access the account balance. But Jafar, as the bank manager, can access the account balance of Morteza and Ali.

The mechanism that imposes restrictions on authenticated users is called Authorization.

Now that you are familiar with the key definitions of information security, it is time to know how each of these goals is met. What are the mechanisms to achieve these goals?

In the next few articles , we will get acquainted with one of the most important security mechanisms by entering the world of cryptography .

]]>
http://wiki.shopingserver.com/familiarity-with-the-key-concepts-of-information-security/feed/ 0
Introduction to cryptographic knowledge – Cryptography http://wiki.shopingserver.com/introduction-to-cryptographic-knowledge-cryptography/ http://wiki.shopingserver.com/introduction-to-cryptographic-knowledge-cryptography/#respond Sat, 10 Oct 2020 05:26:01 +0000 http://wiki.shopingserver.com/?p=28174 After getting acquainted with the basic concepts of information security, we want to enter the topic of cryptography and get acquainted with different methods of cryptography.

Cryptography, In the previous article of the Proceedings of the principles of information security with the key concepts of information security were introduced.

In this article, we start the topic of cryptography, and after getting acquainted with the basic definitions in this field, we examine the simple substitution method to use it to say what is meant by a secure cryptography method.

Remember these words

First of all, it is better to get acquainted with the definition of these words. Knowing these terms will help you to know exactly what they mean, especially if you come across them in specialized texts, and secondly, if you want to read more about these topics, you know exactly what phrases to look for.

Cryptology : Knowledge of making and breaking secret codes.

Cryptography : Knowledge of creating secret codes.

Cryptanalysis : Knowledge of breaking secret codes

You may also come across the word Crypto in specialized texts, which can mean any of the above three words. Depending on the text, you can tell which meaning is meant.

One crypto system ( Crypto System – Cipher ) receives the original data as input and returns another data as output, which is equivalent to the encrypted original data. So the original data as input to the system is encrypted plain text ( Plain text ) say and the encryption system output ciphertext ( Cipher text ) is called.

A procedure that converts plain text to ciphertext Encryption ( Encryption ) and it’s contrary to the plain text into ciphertext decryption ( Decryption ) is called. Also in the operation of a key ( Key) Is also used to configure the cryptographic system. The following figure gives a better understanding of the above definitions.

Encryption and decryption operations

Cryptographic methods are divided into two general categories, symmetric and asymmetric.

In symmetric encryption ( Symmetric cipher ) is a key for encryption and decryption operations.

When using this method, the key must be kept confidential because anyone who has access to the key can convert the ciphertext to plain text. Unlike the procedure in asymmetric cryptography ( Asymmetric ) of the two keys are used.

One key to encrypt information and the other key to decrypt. When this encryption method is used, the key used for decryption is usually made available to the public and the other key is kept confidential. That’s why these two keys, public key ( Public Key ) and the private keyPrivate Key ) is called.

When someone uses public key to decrypt information, they can ensure that the information is encrypted by the same person who holds the private key and is not manipulated by someone else. In this way encryption, encrypted with the public key ( Public key encryption ) is also called.

In an encryption system ideal ( Ideal Cipher ) to obtain the plaintext and ciphertext using the keyless impossible.

The security of a cryptographic system must be key-based. For added security, details of how the cryptographic system works should not be hidden. In fact, everyone should be able to have accurate information about how the cryptographic system works, and all that needs to be hidden is the key. This is known as the Kirkhoff principle , which should be considered in the design of cryptographic systems.

Substitution Cipher

You must remember Jafar, Morteza and Javad from the first article.

Jafar and Morteza's messages are heard by JavadMorteza wants to send a message to Jafar Bank and in this message his transaction information is written. Jawad Ibn is able to listen to the messages exchanged. For this reason, Morteza can not send the original message to Jafar Bank.

You have to provide him with an encryption system so that even if the message being exchanged is in Javad’s possession, Morteza’s account information will not be revealed.

To do this we can use a simple encryption system called substitution cipher ( Substitution Cipher ) use.

In this cryptographic system, we use another letter instead of each letter of the alphabet. In its simplest form, instead of each letter of the alphabet, we use another letter that is a certain number after that letter. And In this case, the space between the main letter and the letter that replaces it is used as the encryption key.

The following figure shows how to replace the letters.

In this example, instead of each letter, the letter in the alphabetical order of 3 is used, so here is the cryptographic key 3.

Letter substitution in cryptography Simple key substitution 3This encryption system is known as Caesar encryption when used with key 3. In ancient Rome, this method was used to encrypt confidential information.

According to the figure above, if n = 3 is used as the encryption key Message: thisismorteza is encrypted as WKLVLVPRUWHCD. To decrypt it, it is enough to do the opposite. That is, instead of each letter in the encrypted message, we put the 3 letters before it in alphabetical order.

By doing this, can we be sure that if Javad receives the encrypted message, he will not be able to understand the content of the original message?

Another issue that needs to be taken as the key ( Key Space ) is. Key space means all values ​​that may be used as encryption keys. In the simple substitution cryptography method we examined, in English, given that there are 26 letters in the alphabet, the key can have values ​​from 0 to 25. As a result, the size of the key space in this method is equal to 26.

Thus, if Javad knows that simple substitution encryption has been used, in order to obtain the encryption key, he must try all 26 possible values ​​to obtain the key. It’s not difficult to try all these 26 keys. So we can not say that this encryption mechanism provides sufficient security.

This type of attack where all the switches are looking for real value encryption key is searched comprehensive search key ( Exhaustive search key ) is called.

How big should the key space be?

We have seen that simple substitution encryption is not a good way to encrypt information,

because there is only one value that can be used as a key, and thus anyone who wants to break this encryption only needs to use these 26 values ​​as a one-to-one key. Do an experiment to find the right key.

But how big does the key space really have to be to make sure encryption can’t be attacked this way?

Suppose Javad’s computer has enough computing power to test 2.40 keys per second.

In this case,

if the number of possible keys is 2.5 x 56, it only takes 2.16 seconds, which is about 18 hours for Javad to try all possible keys and find the right key.

Similarly, if the size of the key space reaches 2.64 , it takes more than 6 months, and with a key space of ^ 128 بیش more than 90 trillion centuries, it takes Javad to try all the possible keys with his computer.

So we need to make a change to the simple replacement encryption method to make the key space large enough. To do this, we change the way letters are substituted so that each letter can replace any other letter.

This means that we can have 26 choices to choose which letter to use instead of the letter a,

and then we will have 25 choices to choose the successor to the letter b (obviously we can not choose the letter that replaces the letter a) And so to select the 26 key! That means we have about 2.88 options.

This key space is large enough that Javad can not find the cryptographic key by trying all the keys. The following figure is an example of a key in this encryption method.

Encryption key in succession encryption

Cryptanalysis

We said that cryptanalysis or Cryptanalysis of cracking. Now we want to see with a simple example what it is like to break a cryptographic method. Suppose Javad succeeds in listening to this message:

Message heard by JavadGiven that the cryptographic key can be any permutation of English letters, it is not possible for Javad to try all possible keys. So he has to use a smarter way to get to the content of the message.

The following is a graph of the frequency of letters in English.

Chart of frequency of letters in EnglishAnd this figure is a diagram of the frequency of letters in the message that Javad overheard.

Graph the frequency of letters in the message heardLooking at these messages and diagrams, one can guess that the letter F is used in the encrypted message instead of the letter e.

The first word is usually easier to guess than any other word.

Looking at the diagrams and knowing that the third letter was actually e instead of F, one can guess that the first word in the main message was the.

With this assumption in mind, the other two letters of the message are identified and can be used to find the next letters.

Something like solving a table.

Finally,

by continuing the same method, Javad can decrypt the message or make the remaining part of the key so small that it is possible to get the right key by trial and error.

So large key space, although necessary to have a secure encryption method, is not enough. How do we ensure a cryptographic method is secure?

What is meant by safe Cryptography?

If we can have a mathematical proof that it is not possible to get from encrypted text to plain text without a key,

we can be sure that the cryptographic method we use is secure. But such proof usually does not exist.

No such proof has been provided for any of the most widely used cryptographic methods.

In the absence of a mathematical proof of cryptographic system security,

if the best known attack on a cryptographic method is not computationally possible, we can consider that cryptographic system to be reliable.

In the series of articles where the term secure ( Secure ) encryption system used for an attack,

we mean is best known for its encryption system nearly as comprehensive search key ( Exhaustive key search ) requires time and computing power.

 

 

]]>
http://wiki.shopingserver.com/introduction-to-cryptographic-knowledge-cryptography/feed/ 0
Fundamentals of Information Security – OTP Encryption and cryptography http://wiki.shopingserver.com/fundamentals-of-information-security-otp-encryption-and-cryptography/ http://wiki.shopingserver.com/fundamentals-of-information-security-otp-encryption-and-cryptography/#respond Sat, 10 Oct 2020 05:17:48 +0000 http://wiki.shopingserver.com/?p=28171 In the previous article, we started with cryptography. After getting acquainted with the basic definitions of cryptography, now in this article we are going to describe the One Time Pad cryptography method.

Cryptography, This is one of the few cryptographic methods that can be proven to be secure.

In a previous article from the Introduction to Information Security Fundamentals series , we learned the basic definitions of cryptography.

Do you remember that Morteza wanted to send a message to Jafar Bank, but because Javad might have overheard Pabamha, he had to use an encryption method to send his message in encrypted form.

To do this , we reviewed the surrogate encryption method and saw how this encryption could be broken using encryption analysis methods.

 In this article, we describe One Time Pad encryption. A cryptographic method that has been proven to be secure.

Morteza, who recently worked as a spy in Nazi Germany, wants to send an encrypted message to Jafar, who is in charge of his superior. He wants to use One Time Pad encryption to encrypt his message. Javad, a spy for the Soviet Union, also intends to eavesdrop on the message and crack the code.

Morteza, Jafar and JavadTo make our job easier, we consider only the first part of Morteza’s message. This message starts with the phrase heilhitler. To use One Time Pad encryption, we assign a binary code to each letter of the code.

Because in this example we are dealing with only 8 letters of the alphabet, we can assign a 3-bit code to each letter as follows.

Base code attributed to lettersThese codes provide only a mapping of the alphabet to three-bit strings and should not be kept confidential. Using them here is something like using ASCII encoding.

In the previous article, we said that in a cryptographic method, there should be nothing secret other than the cryptographic key. We introduced this issue as the Karkhoff principle .

In this way, Morteza’s message (heilhitler phrase) becomes the following bit string:

001 000 010 100 001 010 111 100 000 101

How does One Time Pad encryption work?

Now Morteza has to encrypt his message using One Time Pad encryption. To do this, we need a key that is exactly the same length as the message. This key must be selected randomly. Morteza uses the following bit string as a key:

111 101 110 101 111 100 000 101 110 000

In the One Time Pad encryption method, to generate encrypted text or Cipher Text, we plain text with the XOR encryption key. One of the features of XOR operation is that:

a XOR b XOR b = a

For this reason, if the encrypted text (Cipher Text) is entered with the XOR encryption key, it will be the result of plain text operations. In this way, the encryption and decryption methods are exactly the same.

So Morteza’s message will be encrypted as follows:

Encryption with One Time PadEncrypted message means that the phrase srlhssthsr can be transmitted quite safely, without the listener of the message knowing anything about the content of the message.

The listener can only understand the length of the main message, but this problem can also be solved by using creative methods.

Jafar, who has the cryptographic key, repeats the same operation after receiving the message and obtains the main message.

Decryption with One Time PadIf we decrypt the same encrypted text with another key, the simple message we get is completely different. Imagine using the following bit string as an encryption key to decrypt the srlhssthst message:

101 111 000 101 111 100 000 101 110 000

Decryption with wrong key in One Time Pad.pngAs you can see, the result is killhitler instead of heilhitler. Without knowing the key, any phrase with the same length can probably be exactly the same as the main message.

As a result, without knowing the key and holding the encrypted message, no guess can be made about the main message. This means that this encryption method is completely secure. But provided that each key is used only once.

Why is the One Time Pad encryption key disposable?

Suppose the two messages P1 and P2 are both encrypted with the K key.

C1 = P1 XOR K

C2 = P2 XOR K

C1 XOR C2 = P1 XOR K XOR P2 XOR K = P1 XOR P2

The above statement indicates that if the same cryptographic key is used twice, information about the original message can be found. In this case, it is enough to reveal only a part of one of the messages or guess correctly, so that the encryption is broken and more information about the main messages without a key is obtained.

For example, if both kite and like are both encrypted with a key:

like.pngkite.pngThe person listening to the messages can guess that the second and fourth letters of both messages are the same. Breaking the encryption by revealing the details of the messages can be as simple as solving the table.

Why can’t One Time Pad encryption be used for today’s applications?

We saw that the encryption key in the One Time Pad encryption method needs to be changed each time, and the length of this key should be the same size as the original message.

Choosing a key of this length is practically very challenging in today’s applications dealing with very large data, and transmitting a key of this size to any message is not safe to do.

Therefore, this method of cryptography, although it offers very good security, but can not be used in most applications today. But knowing this helps to understand the cryptographic methods used today.

Challenge your findings

At the end of the third article in the collection of information security basics,

it is not bad to review a little of what we have learned in these three articles.

If you are familiar with programming languages, you can implement successor cryptography or One Time Pad cryptography.

You can also think of creative ways to prevent message length from being revealed

in One Time Pad encryption and implement the way you think.

In the next article, we will look at the cryptographic methods used in the computer world today and learn how they work.

]]>
http://wiki.shopingserver.com/fundamentals-of-information-security-otp-encryption-and-cryptography/feed/ 0
Java Programming Language: History, Features, Terms, and Tips for Beginners http://wiki.shopingserver.com/java-programming-language-history-features-terms-and-tips-for-beginners/ http://wiki.shopingserver.com/java-programming-language-history-features-terms-and-tips-for-beginners/#respond Fri, 18 Sep 2020 19:16:00 +0000 http://wiki.shopingserver.com/?p=27881 Java is a popular programming language and a computing platform. Fast, reliable and secure. According to Oracle, a Java patent company, Java runs on 3 billion devices worldwide.

Given the number of Java developers, Java implementations, and companies, it can be said that Java will be around for many years.

This tutorial covers everything you need to know about the Java programming language. In particular, you will learn about the features of Java programming, its applications, the reasons for learning it, and how to learn it properly. Get acquainted (gain, obtain) with present-day techniques that came from Java Programming.

Why was Java created? Brief history

In 1991, the Green Team led by James Gessling at Sun Microsystems developed a programming language for digital consumer devices. It was called the language of the oak. Why oak? Because there was an oak tree outside Gosling’s office.

The Green Team established interactive language and television. However, it was very advanced for digital cable TV at that time. Later, the language was renamed Green and eventually changed from Java coffee to Java. That’s why its logo is a cup of coffee.

Since C ++ / C were popular languages, James Gosling designed the language with C ++ / C syntax and the “write once, run everywhere” philosophy. Years later, Sun Microsystems released its first public Java implementation in 1995, announcing that the Netscape Navigator Internet browser incorporated Java technology.

In 2010, Sun Microsystems was wholly acquired by Oracle along with Java.

Java version history

June 1, 1991 – The Java language project begins

2- JDK 1.0 – January 1996

3- JDK 1.1 – February, 1997

4- J2SE 1.2 – December 1998

5- J2SE 1.3 – May, 2000

6- J2SE 1.4 – February, 2002

7- J2SE 5.0 – September, 2004

8- Java SE 6 – December 2006

9- Java SE 7 – July 2011

10- Java SE 8 (latest version) – March 18, 2014

11- Java SE 9 – July 2017

Features of the Java programming language

1. Java is a standalone platform

Java was created with the philosophy of “write once, run everywhere” (WORA). The Java code (specific code and libraries) that you write on one platform (operating system) will be executed on other operating systems without change.

To run Java, an abstract machine called Virtual Java Machine (JVM) is used. JVM executes Java bytecode. The CPU then runs the JVM. Since all JVMs work the same way, the same code works on other operating systems, so we can say that Java is independent of the operating system.

2- Object-oriented language

There are different styles of programming. The object-oriented approach is one of the most popular programming styles. In object-oriented programming, by creating objects, a complex problem is divided into small sets that make the code reusable.

Many programming languages, including Java, Python, and C ++, have object-oriented features. If you want to become a programmer, you have to learn object-oriented programming style.

3- Java is fast

Previous versions of Java have been criticized for being slow. However, now everything is completely different. The new JVM is significantly faster and the processor running JVM is also very powerful.

Java is currently one of the fastest programming languages. Well-optimized Java code is about as fast as low-level languages ​​like C ++ / C and much faster than Python, PHP, and so on.

4- Java is secure

The Java platform provides various features for the security of Java applications. Some of the high level features are:

  • Provides a secure platform for developing and running Java applications
  • Automatic memory management reduces vulnerabilities and memory loss
  • Establish secure communication by protecting the integrity and privacy of data transmission

5- Large standard library

One of the reasons Java is so widely used is that it has a large standard library. The Java environment has hundreds of classes and methods in different packages to help software developers. For example,

  • java.lang – For advanced features of strings, arrays, etc.
  • java.util – For data structures, regular expressions, date and time functions, and so on
  • java.io – for I / O file, exception management and so on

Java applications

Powerful Java technology is ubiquitous and supplies three billion devices worldwide. It is very likely that you have used Java at least once in your life. Here are some important Java users:

1- Android applications: Java uses the Android SDK to develop Android applications.

Web Applications : Java is used to create Web applications through Status, Servlets, or JSPs. Some of the most popular web applications written in Java include: Google.com, Facebook.com, eBay.com, Linkedln.com and…. Note that these sites are not all written in Java.

3- Development of various software : Software such as MATLAB, Vuze, OpenOffice, Eclipse and… use Java.

4- Big data processing: You can use the popular Hadoop software framework, which is written in Java, to process large data. To use it, you must have a good understanding of Java programming.

5- Trading systems: You can write trading software that has a small record with Java. In fact, you should use the Oracle Extreme Java trading operating system.

6. Built-in systems: Although C / C ++ programming languages ​​are still popular for working with built-in systems, Java built-in systems technology has provided the right operating system and runtime for billions of built-in devices. These devices include: TV, SIM card and Blu-ray Disc player.

In addition to these programs, Java is also used in the development of scientific games and applications such as natural language processing and..

Terms you should learn before learning Java

Learning a new programming language is challenging. You may hear new terms that are unfamiliar to a beginner. So we decided to explain the specialized terms that you may come across in the world of Java programming.

Run Java on the operating system

Java installation steps for Mac OS X and MacOS

1. Download the latest version of the Java platform (JDK).

2- Double click on DMG and follow the instructions to install Java.

3- To confirm the Java installation, go to the terminal and click the following command.

javac -version

If installed correctly, the command displays the Java version (such as javac 1.8.0_60)

The next step is to install the Java IDE in order to write and execute Java code. Here we see the installation steps of Intelli IDEA.

1. Download the generic version of the Intelli IDEA.

C: \ Users \ Mr \ Desktop \ intellij-idea-download.png

2. Open the DMG file and follow its instructions. You may want to save the Intelli IDEA to application folders.

3. Open IntelliJ IDEA. Select “Do not import settings” and click ok. Then click the Jetbrains Privacy Policy button and accept Accept.

4- You can now customize your user interface. You can reject all default settings or select your own custom changes. If you are not sure, just click on Skip All and Set Defaults.

5- At the end, you will enter the welcome page and you can create your project.

C: \ Users \ Mr \ Desktop \ open-intellij-idea.png

6. In the next window on the left, select Java and click NEW to select JDK. Select the JDK installation location that we copied during the Java installation and click Next.

C: \ Users \ Mr \ Desktop \ intellij-idea-jdk.png

7- In this step, you will see the Create project from template option. Ignore it and click Next.

8- On the next page, select a name for the project and click Finish (for example, Hello)

9- You should see your project in the menu on the left. If not, you can see it from the following path:

Views <Tool Windows <Project

10. Now go to hello> new> Java and name the Class. (Eg First)

C: \ Users \ Mr \ Desktop \ create-project-intellij-idea.png

11. Write and save the desired Java code.

12. To run the program, go to Run> run and click First.

C: \ Users \ Mr \ Desktop \ run-Java-intellij-Idea.png

C: \ Users \ Mr \ Desktop \ run-java-file.png

Install Java on Linux

To install and run Java on Linux, you need to install two programs: Java SE Developer Kit and IDE.

1. Open the terminal and type the following commands.

  1. sudo add-apt-repository ppa: webupd8team / java
  2. sudo apt update; The sudo apt install oracle-java8-installer

2- Agree with license and service by clicking ok and yes.

3- Congratulations! You have successfully installed java8. Make sure the installation is correct by typing the following in the terminal.

Install IntelliJ IDEA for Linux

1. Download the generic version of IntelliJ IDEA.

C: \ Users \ Mr \ Desktop \ intellij-idea-linux-download.jpg

2- After downloading, in the terminal, change the current directory to the download directory and extract Java using the following command.

sudo tar xf <filename> .tar.gz -C / opt /

3. Then change the current directory to the IntelliJ IDEA folder.

cd / opt / <intellij-folder> / bin

4. Run the following command to start the IDE.

./idea.sh

5. Do not import settings and click ok. Then click the accept button.

6. IntelliJ IDEA lets you customize your interface. Select the one you like and click Next. Create a shortcut on the desktop for easy access to the program. Then click Next to start all other pages.

7. Now you go to the welcome page. Click Create New Project to create a new project.

8. In the next window, select Java from the left pane. See if JDK is selected in the SDK project. If not selected, click New and go to the installation location. / usr / lib / jvm / java-8-oracle

C: \ Users \ Mr \ Desktop \ intellij-jdk-java-setup-linux.jpg

9- Double click on Next.

10. Write the name of the project (for example, HelloWorld) and click Finish. (If you do not see the sidebar on the left, go to View> Windows Tool> Project.)

11. To add a new Java class, click on the src folder on the left and right, then select new and then Java Class. Write the name of the class. Do not use space in the class name.

C: \ Users \ Mr \ Desktop \ java-new-class-linux.jpg

12. Write and save Java code.

13. Go to Run> Run to run the program. Then click on the project that creates the executable file and run it.

C: \ Users \ Mr \ Desktop \ intellij-idea-run-program-linux.jpg

Install Java on Windows 7, 8, 10

To install Java on Windows, we need to install two programs: Java SE Developer Kit and IDE.

1- Download the appropriate kit for your system.

C: \ Users \ Mr \ Desktop \ download-jdk-windows.jpg

2- After downloading, open the installation file and click Next. Select “This feature will be used on local hard drive”. Then copy the installation location (yellow highlight) to Notpad and click Next.

C: \ Users \ Mr \ Desktop \ java-enable-all-features.jpg

3- During the installation, you will be asked to install the JRE as well. Click Next. Finally, click the Finish button.

4. Now you need to edit the PATH variable. Go to Control Panel> System and Security> System. Click Advanced System settings on the left to go to System properties.

C: \ Users \ Mr \ Desktop \ java-system-path.jpg

5. Click on Environment Variables. Then find System variables at the bottom of the path and click Edit in the next window.

C: \ Users \ Mr \ Desktop \ java-path-variable.jpg

6. Select all the text in the Variable Value field and copy it to Notepad. This makes editing and reviewing easier. Check if the text includes C: \ ProgramData \ Oracle \ Java \ javapath. If there is, go to the next step. If not, copy the installation location that you copied earlier to the bottom of the bin. In fact, C: \ Program Files (x86) \ Java \ jdk1.8.0_112 \ bin; Place Notepad at the end of the text. The jdk model may be different. Now copy all the text and paste it in the Value PATH box.

C: \ Users \ Mr \ Desktop \ jdk-path-append.jpg

7. Click ok to save the changes.

8- Open the command prompt to check for the correct installation of Java. Type Java-version. If the version is displayed, you have Java installed correctly.

Install IntelliJ IDEA on Windows

1. Download the public version of IntelliJ IDEA.

C: \ Users \ Mr \ Desktop \ intellij-idea-download.jpg

2- Open and install the installation file. Create a desktop shortcut for the 64-bit version. Click Next.

C: \ Users \ Mr \ Desktop \ intellij-idea-installation.jpg

3. Now open IntelliJ IDEA from the desktop shortcuts.

4. Select “Do not import settings” and click ok. Then click Accept policy Jetbrains.

5. IntelliJ IDEA lets you customize your interface. You can reject all default settings or select your own custom changes. If you are unsure, just click Skip All and Set Defaults.

6. You enter the welcome page. Select Create New Project.

7. In the next window, select Java on the left side of the window. Click New to select JDK. Select the install location where we copied the JDK during the Java installation.

C: \ Users \ Mr \ Desktop \ intellij-idea-jdk.jpg

8. IntelliJ IDEA now detects the installed JDK. Click Next.

9- Select the name of the project. (For example, HelloWorld) Click Finish. If you encounter the message directory does not exist, just click ok. (If you do not see the sidebar on the left side, go to View> Tool Windows> Project Follow.

10. To add a new class, right-click on the src folder and select java, then New Class. Write the class name without space.

C: \ Users \ Mr \ Desktop \ java-new-class.jpg

11. Write and save Java code.

12. Go to Run> Run to run the program. Click on the project. This will create the executable file.

C: \ Users \ Mr \ Desktop \ java-run-program.jpg

]]>
http://wiki.shopingserver.com/java-programming-language-history-features-terms-and-tips-for-beginners/feed/ 0
Learn Hello World in Java (in very simple language) http://wiki.shopingserver.com/learn-hello-world-in-java-in-very-simple-language/ http://wiki.shopingserver.com/learn-hello-world-in-java-in-very-simple-language/#respond Fri, 18 Sep 2020 19:11:28 +0000 http://wiki.shopingserver.com/?p=27878 Hello World! Is a simple program that outputs Hello, World! Prints on the screen. Because the program is so simple, it is usually used to introduce a new programming language to a new user.

Let’s check out the “Hello World!” how it works.

If you want to run this program on your system, make sure Java is installed correctly. You also need an IDE (or text editor) to write and edit Java code.

Hello World application in Java

  1. // Your First Program
  2. class HelloWorld {
  3. public static void main (String [] args) {
  4. System.out.println (“Hello, World!”);
  5. }
  6. }

If you copied the code accurately, you must save the file name HelloWorld.java. Because the class name and file name in Java must match.

When you run the program, the output is:

Hello, World!

“Hello World!” How does it work in Java?

 // Your First Program

In Java, any line starting with // is a comment. Comments to read the description of the code and understand more about it. The Java compiler completely ignores these lines (the application that executes Java code for the computer).

 class HelloWorld……

In Java, every program starts with a class definition. In the above program, HelloWorld is the class name and the class definition is:

class HelloWorld {

… ..…

}

Remember that every Java program has a class definition, and the class name must match the file name in Java.

public static void main (String [] args) {……

The top line is the main method. Every program in Java must have a main method. The Java compiler starts executing the code from the main method.

Remember that the main function is the Java entry point of the mandatory program. The signature of the main function in Java is equal to:

public static void main (String [] args) {

… ..…

}

 System.out.println (“Hello, World!”);

The above code prints the string inside the quotation mark in the standard output (screen). Note, this is the line of code inside the main function that is inside the class definition.

important points

  • Every valid Java program must have a class definition (which matches the file name).
  • The main function must be in the class definition.
  • The compiler starts executing the code from the main function.

The following code is a valid Java program that does nothing.

public class HelloWorld {

public static void main (String [] args) {

// Write your code here

}

}

If you do not understand the meaning of class, static, methods and., Do not worry. We will explain them in full in the following sections.

]]>
http://wiki.shopingserver.com/learn-hello-world-in-java-in-very-simple-language/feed/ 0
Learn JDK, JRE and JVM in Java and their differences http://wiki.shopingserver.com/learn-jdk-jre-and-jvm-in-java-and-their-differences/ http://wiki.shopingserver.com/learn-jdk-jre-and-jvm-in-java-and-their-differences/#respond Fri, 18 Sep 2020 19:09:15 +0000 http://wiki.shopingserver.com/?p=27875 What is JVM?

JVM (Java Virtual Machine) is an abstract machine that enables the system to run a Java program.

When you run a Java program, the Java compiler first compiles the Java code into a bytecode. The JVM then converts the bytecode to local machine code (a set of instructions that the computer’s CPU executes directly).

Java is a platform-independent language. Because when you write Java code, it’s actually written for JVM, not your physical device (computer). Because JVM runs operating system-independent Java bytecode, Java is platform-independent.

 

What is a JRE?

(Java Runtime Environment) is a software package that provides Java class libraries with Java Virtual Machine (JVM) and other components to run Java applications. The JRE includes the JVM.

C: \ Users \ Mr \ Desktop \ java-realtime-enviornment_0.jpg

If you want to run Java applications without expansion, you need JRE. You can download the JRE from the Java 8 Runtime Environment 8 page.

What is JDK?

JDK (Java Development Kit) is a software development kit for developing applications in Java. When you download the JDK, the JRE is also downloaded and there is no need to download it separately. In addition to JRE, JDK also includes a number of development tools (compilers, JavaDoc, Java Debugger, etc.).

C: \ Users \ Mr \ Desktop \ java-development-kit.jpg

If you want to develop Java applications, download JDK.

The image below shows the relationship between JVM, JRE and JDK.

C: \ Users \ Mr \ Desktop \ jdk-jre-jvm.jpg

]]>
http://wiki.shopingserver.com/learn-jdk-jre-and-jvm-in-java-and-their-differences/feed/ 0
Learn variables and data types in Java (in very simple language) http://wiki.shopingserver.com/learn-variables-and-data-types-in-java-in-very-simple-language/ http://wiki.shopingserver.com/learn-variables-and-data-types-in-java-in-very-simple-language/#respond Fri, 18 Sep 2020 19:06:20 +0000 http://wiki.shopingserver.com/?p=27872 Java variables

A variable is a place to store data in memory (storage location). Each variable must be given a unique name (identifier) ​​to indicate the storage location.

How to define variables in Java?

Here is an example to define a variable in Java.

  1. int speedLimit = 80;

Here, speedLimit is an int data variable (integer) with a value of 80 assigned to it.

In this example, we assigned a variable to that value, but this is not mandatory. You can define variables and specify them later without specifying a value. For example,

int speedLimit;

speedLimit = 80;

The value of the variable can be changed in the program, hence it is called “variable”. For example,

int speedLimit = 80;

… ..…

speedLimit = 90;

Java is a static language. That is, all variables must be defined before use.

Also, variable data types cannot be changed in the program. For example, you are unable to do the following:

int speedLimit = 80;

… ..…

float speedLimit;

Rules for naming variables in Java

The Java programming language has a set of specific rules and conventions for naming variables. Here’s what you need to know:

  • Variables in Java are case sensitive.
  • The variable name is a sequence of Unicode letters and numbers and can start with the letter, $ or _. However, the beginning of a variable noun is more common. Also, the variable name cannot contain empty space.

When defining variables, choose a name that makes sense. For example, score, number, level are more meaningful than the names s, n and l.

If you selected a word for a variable name, lowercase all letters. For example, it is better to use speed than SPEED, or sPEED.

If you chose a variable name with more than one word, use all lowercase letters for the first word and capitalize the first letters of each subsequent word. For example, speedLimit.

There are four types of variables in the Java programming language:

  • Sample variables (non-static variables)
  • Class variables (static variables)
  • Local variables
  • Component

Basic Java data types

As mentioned above, Java is a static language. That is, all variables must be defined before use.

int speed;

Here speed is a variable and data type is an int variable. The data type int determines that the variable can only contain integers.

Simply put, the data type of a variable determines the values ​​that a variable can store. There are 8 predefined data types in the Java programming language known as core data types.

In addition to the main data types, there are also reference data types in Java that you will learn about later.

8 main data types

boolean

  • The boolean data type has two possible values, true or false.
  • Default value: false.
  • Usually used for right / wrong conditions.
  • Example:
  1. class BooleanExample {
  2. public static void main (String [] args) {
  3. boolean flag = true;
  4. System.out.println (flag);
  5. }
  6. }

Output

true

byte

  • The byte data type can be between -128 and 127.
  • If the value of the variable is in the range [-128,127], it is used instead of the data type int or other integers.
  • Default value: 0
  • Example:
  1. class ByteExample {
  2. public static void main (String [] args) {
  3. byte range;
  4. range = 124;
  5. System.out.println (range);
  6. // Error code below. Why?
  7. // range = 200
  8. }
  9. }

Output

124

short

  • The short data type can have values ​​from -32768 to 32767 (16-bit two-bit complement integer is signed).
  • If the value of the variable is certainly in the range [-32768, 32767], it is used instead of other types of correct data.
  • Default value: 0
  • Example:
  1. class ShortExample {
  2. public static void main (String [] args) {
  3. short temperature;
  4. temperature = -200;
  5. System.out.println (temperature);
  6. }
  7. }

Output

-200

int

  • Int data type can be values from -2 31 to 2 31 -1 have.
  • If you use Java 8 then, can the 32-bit unsigned integer with a minimum value of 0 and a maximum of 2 31 -1 use.
  • Default value: 0
  • Example:
  1. class IntExample {
  2. public static void main (String [] args) {
  3. int range = -4250000;
  4. System.out.println (range);
  5. }
  6. }

Output

-4250000

long

  • The long data type can range from -2 63 to 2 63-1 .
  • If you use Java 8 or higher, 64-bit unsigned integer can with a minimum value of 0 and a maximum of 2 64 -1 use.
  • Default value: 0
  • Example:
  1. class LongExample {
  2. public static void main (String [] args) {
  3. long range = -42332200000L;
  4. System.out.println (range);
  5. }
  6. }

Output

-42332200000

Note that the use of L at the end of -42332200000 indicates the word long.

double

  • The double data type has a resolution of 64 bits.
  • It should never be used for exact values ​​such as currency.
  • Default value: 0.0 (0.0 d)
  • Example:
  1. class DoubleExample {
  2. public static void main (String [] args) {
  3. double number = -42.3;
  4. System.out.println (number);
  5. }
  6. }

Output

-4.3

float

  • The float data type has a resolution of 32 bits.
  • It should never be used for exact values ​​such as currency.
  • Default value: 0.0 (f 0.0)
  • Example:
  1. class FloatExample {
  2. public static void main (String [] args) {
  3. float number = -42.3f;
  4. System.out.println (number);
  5. }
  6. }

Output

-4.3

Note that in the above program we used -42.3 f instead of -42.3. Because -42.3 is a double. To tell the compiler -42.3 is float and not double, you must use f or F.

char

  • The Unicode character is 16-bit.
  • The minimum value is ‘\ u0000’ and the maximum value is ‘\ uffff’.
  • Default value: ‘\ u0000’
  • Example:
  1. class CharExample {
  2. public static void main (String [] args) {
  3. char letter = ‘\ u0051’;
  4. System.out.println (letter);
  5. }
  6. }

Output

Q

The value of Unicode ‘/ u0051’ is equal to Q.

Another example:

  1. class CharExample {
  2. public static void main (String [] args) {
  3. char letter1 = ‘9’;
  4. System.out.println (letter1);
  5. char letter2 = 65;
  6. System.out.println (letter2);
  7. }
  8. }

Output

9

A

When you print letter1, the output is 9 because the letter1 is assigned a 9 character.

When you print letter2, the output is A because the letter value of the letter A is 65.

Java also supports character strings through the java.lang.String class. Here’s how to create a String object in Java:

myString = “Programming is awesome”;

Literal in Java

To understand literal, let’s give an example of assigning a value to a variable.

boolean flag = false;

here,

  • boolean – is a data type.
  • flag – is variable
  • false – is literal.

Litral represents the source code with a fixed value.

Values ​​such as 1.5, 4, true, ‘\ u0050’ that appear directly in the program without the need for calculation are literal.

In the example above, flag is a variable. Because it is boolean, it may be false or true. The compiler needs to calculate to understand it. However, literals such as -5, “a”, true indicate a constant value.

Litral correct

  • The correct literal is used to initialize the variables of data types int, byte, short, int and long.
  • If the correct literal ends with l or L, it is of type long. Note: It is better to use L instead of l.

// Error! literal 42332200000 of type int is out of range

long myVariable1 = 42332200000;

// 42332200000L is of type long, and it’s not out of range

long myVariable2 = 42332200000L;

  • The correct literal can be expressed in decimal, hexadecimal and binary systems.
  • Numbers starting with the prefix 0x indicate hexadecimal. Similarly, numbers beginning with the prefix 0b indicate binary.

// decimal

int decNumber = 34;

// 0x represents hexadecimal

int hexNumber = 0x2F;

// 0 represents binary

int binNumber = 0b10010;

Litral floating point

  • A floating point literal is used to initialize float and double variables.
  • If a floating point liter ends with f or F, it is float. Otherwise, it is double. The double type can optionally end in D or d. However, it is not necessary.
  • They can also be expressed in scientific symbol numbers using E or e.
  1. class DoubleExample {
  2. public static void main (String [] args) {
  3. double myDouble = 3.4;
  4. float myFloat = 3.4F;
  5. // 3.445 * 10.2
  6. double myDoubleScientific = 3,445e2;
  7. System.out.println (myDouble);
  8. System.out.println (myFloat);
  9. System.out.println (myDoubleScientific);
  10. }
  11. }

Output

  1. 3.4
  2. 3.4
  3. 344.5

Character and string literals

  • Contains Unicode characters (UTF-16).
  • For literal characters, a single quote is used. For example ‘a’ or ‘\ u0111’.
  • For string literals, double quotes are used. For example, “programming”, “java8 ″
  • Java also supports several special escape sequences. For example, \ b for backspace, \ t for moving cursor to 8 next places, \ n for moving cursor to next line, \ f for moving control to serious page, \ r for beginning of current line, \ ”for Print the quotation mark, \ ‘to print a single quote, and \\ to print a backlash.
  1. class DoubleExample {
  2. public static void main (String [] args) {
  3. char myChar = ‘g’;
  4. char newLine = ‘\ n’;
  5. String myString = “Java 8”;
  6. System.out.println (myChar);
  7. System.out.println (newLine);
  8. System.out.println (myString);
  9. }
  10. }

Output

g

Java

]]>
http://wiki.shopingserver.com/learn-variables-and-data-types-in-java-in-very-simple-language/feed/ 0
Training of Java operators (in quite simple language) http://wiki.shopingserver.com/training-of-java-operators-in-quite-simple-language/ http://wiki.shopingserver.com/training-of-java-operators-in-quite-simple-language/#respond Fri, 18 Sep 2020 19:02:11 +0000 http://wiki.shopingserver.com/?p=27868  Operators are special symbols (characters) that perform operations on operands (variables and values). For example, the + operator is a plural.

Assignment Operator

Assignment operators in Java are used to assign values ​​to variables. For example

int age;

age = 5;

The assignment operator assigns its right value to the variable on its left. Here, 5 is assigned to the age variable using the = operator.

There are other assignment operators. However, for convenience, we will train other assignment operators later.

Example 1: Assignment operator

  1. class AssignmentOperator {
  2. public static void main (String [] args) {
  3. int number1, number2;
  4. // Assigning 5 to number1
  5. number1 = 5;
  6. System.out.println (number1);
  7. // Assigning value of variable number2 to number1
  8. number2 = number1;
  9. System.out.println (number2);
  10. }
  11. }

Output

5

5

Mathematical Operators

Mathematical operators are used to perform mathematical operations such as addition, subtraction, multiplication, and so on.

 

Example 2: Mathematical operator

  1. class ArithmeticOperator {
  2. public static void main (String [] args) {
  3. double number1 = 12.5, number2 = 3.5, result;
  4. // Using addition operator
  5. result = number1 + number2;
  6. System.out.println (“number1 + number2 =” + result);
  7. // Using subtraction operator
  8. result = number1 – number2;
  9. System.out.println (“number1 – number2 =” + result);
  10. // Using multiplication operator
  11. result = number1 * number2;
  12. System.out.println (“number1 * number2 =” + result);
  13. // Using division operator
  14. result = number1 / number2;
  15. System.out.println (“number1 / number2 =” + result);
  16. // Using remainder operator
  17. result = number1% number2;
  18. System.out.println (“number1% number2 =” + result);
  19. }
  20. }

Output

number1 + number2 = 16.0

number1 – number2 = 9.0

number1 * number2 = 43.75

number1 / number2 = 3.5714285714285716

number1% number2 = 2.0

In the example above, all operands used are variable. Numbers can also be used, they do not have to be variable.

result = number1 + 5.2;

result = 2.3 + 4.5;

number2 = number1 -2.9;

The + operator can also be used to join two or more strings.

Example 3: Mathematical operator

  1. class ArithmeticOperator {
  2. public static void main (String [] args) {
  3. String start, middle, end, result;
  4. start = “Talk is cheap. “;
  5. middle = “Show me the code. “;
  6. end = “- Linus Torvalds”;
  7. result = start + middle + end;
  8. System.out.println (result);
  9. }
  10. }

Output

Talk is cheap. Show me the code. – Linus Torvalds

Unit operators

Operations are performed on only one operand.

 

Example 4: Unit operator

  1. class UnaryOperator {
  2. public static void main (String [] args) {
  3. double number = 5.2, resultNumber;
  4. boolean flag = false;
  5. System.out.println (“+ number =” + + number);
  6. // number is equal to 5.2 here.
  7. System.out.println (“- number =” + -number);
  8. // number is equal to 5.2 here.
  9. // ++ number is equivalent to number = number + 1
  10. System.out.println (“number =” + ++ number);
  11. // number is equal to 6.2 here.
  12. // – number is equivalent to number = number – 1
  13. System.out.println (“number =” + –number);
  14. // number is equal to 5.2 here.
  15. System.out.println (“! Flag =” +! Flag);
  16. // flag is still false.
  17. }
  18. }

Output

+ number = 5.2

-number = -5.2

number = 6.2

number = 5.2

! flag = true

You can also use ++ and – as prefixes and extensions in Java. The ++ operator increases the value by 1 unit and – decreases the value by 1 unit.

int myInt = 5;

++ myInt // myInt becomes 6

myInt ++ // myInt becomes 7

–MyInt // myInt becomes 6

myInt– // myInt becomes 5

There is a fundamental difference when using incremental and decrement operators as prefixes and suffixes. Consider the following example,

  1. class UnaryOperator {
  2. public static void main (String [] args) {
  3. double number = 5.2;
  4. System.out.println (number ++);
  5. System.out.println (number);
  6. System.out.println (++ number);
  7. System.out.println (number);
  8. }
  9. }

Output

5.2

6.2

7.2

7.2

When ordered

System.out.println (number ++)

Runs, first prints the original value and then increments one unit. That’s why the output is 5.2. Then, when

System.out.println (number)

Runs, prints 6.2.

But, when

System.out.println (++ number)

Runs, before printing on the screen, its value increases by 1 unit.

For – the same is true.

Equality and relational operators

Equality and relational operators determine the relationship between two operators. Checks that one operand is larger, smaller, equal, unequal, and از larger than another. Depending on the relationship, the result is right or wrong.

 

Equality and relational operators are used in decision making and loops.

Example 6: Equality and relational operators

  1. class RelationalOperator {
  2. public static void main (String [] args) {
  3. int number1 = 5, number2 = 6;
  4. if (number1> number2)
  5. {
  6. System.out.println (“number1 is greater than number2.”);
  7. }
  8. else
  9. {
  10. System.out.println (“number2 is greater than number1.”);
  11. }
  12. }
  13. }

Output

number2 is greater than number1.

Here, we used <to check if number1 is greater than number2.

Because number2 is greater than number1, the expression number1> number2 is considered incorrect.

Hence, the else part code is executed and if the condition is true, the code inside the if body is executed.

Remember that equality and relational operators compare two operators and evaluate them as true or false.

In addition to relational operators, there is an example comparative operator that compares an instance of an object with a specific type.

The instanceof operator

Here is an example of an instanceof operator.

  1. class instanceofOperator {
  2. public static void main (String [] args) {
  3. String test = “asdf”;
  4. boolean result;
  5. result = instanceof test String;
  6. System.out.println (result);
  7. }
  8. }

When you run the program, the output will be true. This is because test is an example of a String class.

Logical operators

Logical Operators || (Conditional-OR) and && (Conditional-AND) work with Boolean expressions.

 

Example 8: Logical operator

  1. class LogicalOperator {
  2. public static void main (String [] args) {
  3. int number1 = 1, number2 = 2, number3 = 9;
  4. boolean result;
  5. // At least one expression needs to be true for result to be true
  6. result = (number1> number2) || (number3> number1);
  7. // result will be true because (number1> number2) is true
  8. System.out.println (result);
  9. // All expression must be true from result to be true
  10. result = (number1> number2) && (number3> number1);
  11. // result will be false because (number3> number1) is false
  12. System.out.println (result);
  13. }
  14. }

Output

true

false

Logical operators are used in decision making and looping.

Triple operators

Conditional operator or triple operator?: Is an abbreviated if-else structure. The syntax of the conditional operator is:

variable = Expression? expression1: expression2

Here’s how it works.

  • If Expression is true, the value of expression1 is assigned to the variable.
  • If Expression is false, the value of expression2 is assigned to the variable.

Example 9: Triple operator

  1. class ConditionalOperator {
  2. public static void main (String [] args) {
  3. int februaryDays = 29;
  4. String result;
  5. result = (februaryDays == 28)? “Not a leap year”: “Leap year”;
  6. System.out.println (result);
  7. }
  8. }

Output

Leap year

Bitwise and Bit Shift operators

These operators are used to perform bit operations and bit shifts in Java.

 

These operators are not commonly used.

Other assignment operators

We only talked about one assignment operator = at the beginning of the tutorial. In addition to this operator, there are other assignment operators that help us write cleaner code.

 

]]>
http://wiki.shopingserver.com/training-of-java-operators-in-quite-simple-language/feed/ 0
Input and output tutorial in Java (in very simple language) http://wiki.shopingserver.com/input-and-output-tutorial-in-java-in-very-simple-language/ http://wiki.shopingserver.com/input-and-output-tutorial-in-java-in-very-simple-language/#respond Fri, 18 Sep 2020 18:56:43 +0000 http://wiki.shopingserver.com/?p=27865 Java output

Can simply be from

System.out.println ()

Or System.out.print ()

System.out.printf ()

Used to send output to standard output (screen).

System is a class and out is a general static field that takes the output data. Do not worry if you do not notice. We will explain the classes, public and static in the following chapters.

Let’s take an example to print a sentence as output.

  1. class AssignmentOperator {
  2. public static void main (String [] args) {
  3. System.out.println (“Java programming is interesting.”);
  4. }
  5. }

Output

Java programming is interesting.

Here, println is the method that displays the string inside the quote.

What is it? The difference between println () and print (), printf ()

Print () – Prints the string inside the quote.

Println () – Prints the string inside the quote. The cursor then moves to the beginning of the next line.

Printf () – Provides string formatting (similar to printf in C ++ / C programming).

Example 2: print () and println ()

  1. class Output {
  2. public static void main (String [] args) {
  3. System.out.println (“1. println”);
  4. System.out.println (“2. println”);
  5. System.out.print (“1. print”);
  6. System.out.print (“2. print”);
  7. }
  8. }

Output

1. println

۲. println

1. print 2. print

Do not use quotation marks to display integers, variables, and so on.

Example 3: Printing variables and literals

  1. class Variables {
  2. public static void main (String [] args) {
  3. Double number = -10.6;
  4. System.out.println (5);
  5. System.out.println (number);
  6. }
  7. }

Output

5

10.6

You can use the + operator to join strings and print them.

Example 4: Print interconnected strings

  1. class PrintVariables {
  2. public static void main (String [] args) {
  3. Double number = -10.6;
  4. System.out.println (“I am” + “awesome.”);
  5. System.out.println (“Number =” + number);
  6. }
  7. }

Output

I am awesome.

Number = -10.6

Consider the following line:

System.out.println (“I am” + “awesome.”);

“I am” and “awesome” strings. Before printing on the page, they are first appended.

In the following line:

System.out.println (“Number =” + number);

First, the value of the number variable is evaluated and converted to a string by the compiler. Then, the strings are collected and printed on the screen.

Java input

There are several ways to get input from a user in Java. Here you will learn how to use the Scanner object.

To do this, you need to import the Scanner class into the program:

import java.util.Scanner;

Then, we create an object of the Scanner class that is used to receive input from the user.

Scanner input = new Scanner (System.in);

int number = input.nextInt ();

Example 5: Get the input integer from the user

  1. import java.util.Scanner;
  2. class Input {
  3. public static void main (String [] args) {
  4. Scanner input = new Scanner (System.in);
  5. System.out.print (“Enter an integer:”);
  6. int number = input.nextInt ();
  7. System.out.println (“You entered” + number);
  8. }
  9. }

Output

Enter an integer: 23

You entered 23

Here, the input object of the Scanner class is created. The nextInt () method in the Scanner class is then used to receive the integer input from the user.

To get long, float, double and string input from the user, you can use the methods, respectively

nextLong (), nextFloat (), nextDouble () and next ()

use.

Example 6: Get float, double and String inputs

  1. import java.util.Scanner;
  2. class Input {
  3. public static void main (String [] args) {
  4. Scanner input = new Scanner (System.in);
  5. // Getting float input
  6. System.out.print (“Enter float:”);
  7. float myFloat = input.nextFloat ();
  8. System.out.println (“Float entered =” + myFloat);
  9. // Getting double input
  10. System.out.print (“Enter double:”);
  11. double myDouble = input.nextDouble ();
  12. System.out.println (“Double entered =” + myDouble);
  13. // Getting String input
  14. System.out.print (“Enter text:”);
  15. String myString = input.next ();
  16. System.out.println (“Text entered =” + myString);
  17. }
  18. }

Output

Enter float: 2,343

Float entered = 2,343

Enter double: -23.4

Double entered = -23.4

Enter text: Hey!

Text entered = Hey!

]]>
http://wiki.shopingserver.com/input-and-output-tutorial-in-java-in-very-simple-language/feed/ 0