Java Variables

Java variables are containers which hold values during execution of java program. These are names of a memory locations where values are temporarily saved.
A variable can hold:
simple text called String
Single character represented as char
a whole number called integer and represented by int
a number with fraction such as 2.65 called floating point numbers and represent as float
values with two states: true or false represented as boolean

How to create or Declare a variable

To use a variable in java we first need to declare it. To declare a variable first of all data type of variable is mentioned e.g. int, String, char, double followed by variable name and a termination character i.e. semicolon (;).

Syntax:


DataType variableName ;

Example

Following java code will create a variable named age with data type int and put a value “10” into it.

int age;
age = 10;

We can create and assign values in a single statement as follows:

int age = 10;

Java Comments

We can add comments in java code. They are not compiled. Java compiler simply ignores the java comments and only compiles the java code. There are two types of java comments.

Single line java comments

Multiline java comments

Single line java comments

Any line in java code starting with // is a java comment and java compile will ignore it while compiling.
Following example shows a single line java comment:

// This is a comment
System.out.println("Hello World");

We can add java comments at the end of a java code statement. Following example shows a single line java comment at the end of a java code statement:

System.out.println("Hello World"); // This is a comment

Java Multi-line Comments

We can add comments in a java program which span more than one lines.

Multi-line comments start with /* and ends with */. Any text between /* and */ will be ignored by Java.
Following example shows multi-line java comments:

/* It is a multi-line java comment
It is second line of java comment
It is third line of java comment
You can add as much lines of java comments as you want */
System.out.println("Hello World");

Java basic Syntax

In previous post we created a java file named FirstJavaProgram.java which prints “Hello Word” on screen when we run it using java command  after compilation using javac command.


class FirstJavaProgram {

public static void main(String args[]){

System.out.println("Hello World");

}

}

FirstJavaProgram.java explained

In Java every line of code must be inside a class. In above example, we named the class FirstJavaProgram. It is good programming practice to start each word in the class name with an uppercase letter.
Java is case-sensitive therefore “FirstClass” and “firstClass” has different meaning.

Java class name and file name in should be same . When saving the file, save it using the class name and add “.java” to the end of the filename. To run the example above on your computer, make sure that Java is properly installed: Go to the Get Started Chapter for how to install Java. The output should be:

Hello World

Main Method in Java Program


public static void main(String[] args)

Java program execution starts from main method. public, static, void are keywords of java which will be explained later. String[] args are command line arguments which be explained later in detail. For now you should only remember that main method is necessary for every java program with above syntax.

The code line System.out.println(“Hello World”); prints a line of text on command line. You can note a semicolon ( ; ) at the end of the statement. It is mandatory at the end of each java statement. The curly braces {} are used to start and stop a class and method name. You can note starting and ending curly braces of class and main method separately.

Java Getting Started

All applications in java begin with a class name, and that class must match the filename. Now let’s create our fist java program. Name of class will be FirstJavaProgram and name of file will FirstJavaProgram.java. We can do it in any text editor like notepad or an IDE like Netbeans. It will contain a main method which will print “Hello Word” on screen.

class FirstJavaProgram {

public static void main(String args[]){

System.out.println("Hello World");

}

}

Save the file as FirstJavaProgram.java
Open terminal, point it to directory where you have saved the above java file and type following command:
javac FirstJavaProgram.java
above command will compile the java file and create an new file named FirstJavaProgram.class. Now let’s run this file by type following command on termial:
java FirstJavaProgram.class
the above command will print the string “Hello World” on screen and will be terminated.

Java Environment Setup

In this section we will describe the process to setup Java on your local machine.

Option 1 setting path to use javac compiler:

You can write java program in any text editor, compile it using javac command and run by java command on command line. To install java environment go to here and follow the instructions. For windows operating system download latest jdk version install it and setup path as follows:

Assuming you have installed Java in c:\Program Files\java\jdk directory −

        • Right-click on ‘My Computer’ and select ‘Properties’.
        • Click the ‘Environment variables’ button under the ‘Advanced’ tab.
        • Now, alter the ‘Path’ variable so that it also contains the path to the Java executable. Example, if the path is currently set to ‘C:\WINDOWS\SYSTEM32’, then change your path to read ‘C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin’.

Option 2 using an IDE

use the IDE and leave the rest to IDE to set java path. Following are some popular java IDEs you can freely download and use to write and compile the java programs.

How to add comments in a batch file

The keyword REM (short for remarks) is used to add comments in batch file. Following are some examples of comments:

rem This batch file provides an example 

rem to add comments in batch file.

rem the keyword rem must be followed by a space to work correctly.

rem

rem Clear the screen in following statement.

cls

 

What does the “@” sign mean in “@echo off “?

By default, the echo feature is on in MS-DOS-based (and later, Windows) systems when executing a batch file. That means that every command issued in a batch file (and all of its output) would be echoed to the screen. By issuing, the ‘echo off’ command, this feature is turned off but as a result of issuing that command, the command itself will still show up on the screen. By including the ‘@’ symbol in ‘@echo off’, it will prevent the ‘echo off’ command from being seen on the screen.

How to Increase the Maximum File Upload Size in WordPress

WordPress provides a filter upload_size_limit  to  set the limit of  maximum upload size.

A simple way to set maximum upload size for frondend as well as admin dashbaord  just add following code to the end of file functions.php in active wordpress theme.

function filter_site_upload_size_limit( $size ) {

// Set the upload size limit to 20 MB for users lacking the ‘manage_options’ capability.

$size = 1024 *1024*20;

return $size;

}
add_filter( ‘upload_size_limit’, ‘filter_site_upload_size_limit’, 20 );

In case you need to increase file upload size for admin side only use following code:

function filter_site_upload_size_limit( $size ) {

// Set the upload size limit to 20 MB for users lacking the ‘manage_options’ capability.

$size = 1024 *1024*20;

return $size;

}

function set_max_file_upload_size_for_admin()

{

add_filter( ‘upload_size_limit’, ‘filter_site_upload_size_limit’, 20 );

}

add_action(“admin_init”, “set_max_file_upload_size_for_admin”);

 

Find the version of running instance of wordpress

Version of installed wordpress can be found by number of ways. We explain here one by one

WordPress files

Version.php

If you have cpanel of FTP access  then locate the file wp-includes/version.php and you will find following:

/**

* The WordPress version string

*

* @global string $wp_version

*/

$wp_version = ‘4.7.3’;  // current version of installed wordpress.

about.php

Login using username and password of administrator and type following in browser address bar:

https://<you-domain.com>/wp-admin/about.php

and it will display detail of currently installed wordpress including version.

Readme.html File

Generally readme.html file is publically accessible on websites and can be accessed by typing http://datumsol.com /readme.html.

By inspecting meta tag:

 

If admin of site has not edited a meta tag with version of wordpresss exists in source of page. You can view the meta tag by right clicking on page and view page source and search following meta tag:

<meta name=”generator” content=”WordPress 4.7.3″ />

Feed Link

Type  http://<youdomain.com>/feed/  and you will get an xml document which will include following tag:

<generator>https://wordpress.org/?v=4.7.3</generator>