Posts

Showing posts from February, 2017

How to compare strings correctly [JAVA Tip]

The main objective of this post is to explain the correct method of comparing the strings in Java. Can you answer the following quiz?  * QUIZ: Guess output of the following code snippet: String osName = System.getProperty(“osName”); if (osName.equals(“Windows”)) {        System.out.println(“You’re using Windows”); }   For now, let write down your answer on paper. I will let you know the correct answer at the end of this post. Friends, why I want you to answer the quiz above? Well, it’s because I’m going to share a tip about Strings comparison today. * Why Strings comparison? It sounds very simple, but do you know that you have to compare Strings in every coding day of your entire life? Unless you die or you don’t coding any more, comparing Strings is your day-to-day chore, like you eat and drink. I want to tell you about the comparison of a String variable against a String constant as shown in the code snippet above: String osName = System.getProp...

How to run Java program from CMD

Let's say your file is in C:\mywork\ Run Command Prompt C:> cd \mywork This makes C:\mywork the current directory. C:\mywork> javac filenamehere.java This runs javac.exe, the compiler. You should see nothing but the next system prompt... C:\mywork> dir javac has created the filenamehere.class file. You should see filenamehere.java and filenamehere.class among the files. C:\mywork> java filenamehere This runs the Java interpreter. You should then see your program output. If the system cannot find javac, check the set path command. If javac runs but you get errors, check your Java text. If the program compiles but you get an exception, check the spelling and capitalization in the file name and the class name and the java HelloWorld command. Java is case-sensitive!

How to Install the Java Software Development Kit (JDK)

Image
Before you can create and modify Java programs, you’ll need the Java Software Development Kit. You can download the kit (also known as Java SDK or JDK) for free from Oracle as a single installer file, which makes installation quick and easy. Learn the best way to download and install the Java Software Development Kit on your Windows, macOS, or Linux system. PART 1. Step 1.  Downloading the Java Software Development Kit Navigate to http://www.oracle.com/technetwork/java/javase/downloads/index.html . You can download a simple Java Software Development Kit (JDK) installer for Windows, macOS, or Linux directly from Oracle. Step 2.  Click the “Download” button beneath “JDK. ” This will open a new page containing several download options. Step 3.  Scroll to the latest version of Java SE Development Kit. You should always use the latest stable version of the toolkit. There may be more than one version listed, so look closely at the release number. For example, if you are presented with JD...