Hot questions for Using Ubuntu in windows

Question:

Well, I am using IntelliJ to develop a project. I put some of my .java files in the folder src/model/. I have to begin with package src.model;, in Ubuntu , in order to avoid error. While in windows I have to begin with package model;.

Does anyone know why this happens and how can I avoid changing my code when I switch between the two platforms ?


Answer:

Most probably your content root is set to [something]/src in Ubuntu, See here to fix it.

Question:

A couple weeks ago I installed Ubuntu side by side with windows. I recently installed Eclipse on Ubuntu, and wasn't really thinking and when Eclipse asked for a workspace, I just browsed to the Window's Eclipse workspace and used that one(probably a bad idea). I opened up a project changed a few minor code in Ubuntu Eclipse and then saved. I just tried to open the workspace in Window's Eclipse and nothing is showing up, none of the projects or anything at all. I can still browse to the files and they exist haven't been deleted. Any idea about what or why this happened?


Answer:

Create a separate workspace only for the windows eclipse, re-import the projects from the current workspace that is broken on windows to the new windows-only workspace. I can't entirely explain why but I've experienced this as well and this is the solution. Workspaces, for whatever reason, are not cross platform.

Question:

I'm trying to parse day format like "dd/mm/yyyy" with useDelimiter but faced a strange problem. I used the code below, which works well on Ubuntu terminal.

Scanner k = new Scanner(System.in);
k.useDelimiter("/|\n");
String day,month,year;
day = k.next(); month = k.next(); year = next();
System.out.println(day + "/" + month + "/" + year);
int d = Integer.parseInt(day);
int m = Integer.parseInt(month);
int y = Integer.parseInt(year);

But on Windows when I copy this code to Eclipse, it gives an error at :

int y = Integer.parseInt(year);

I've found what causes this. When i print "year", it prints 2014 but there is some whitespace at the end of 2014 so the integer isn't parsed correctly. I solved this by changing the code in Eclipse to:

year = next().trim();

BUT :

My question is, how can it be possible that the same code works on Ubuntu but not on Windows platform ?


Answer:

You can also use a line.seperator. System.getProperty("line.separator") will retrieve a correct line separator that is used by your OS.

public class Tester {


 public static void main(String[] args) {
    Scanner k = new Scanner(System.in);
    String newLine = System.getProperty("line.separator");

    k.useDelimiter("/|"+newLine);
    String day,month,year;

    day = k.next(); 
    month = k.next(); 
    year = k.next();
    System.out.println(day + "/" + month + "/" + year);


 }
}

Question:

I am working on a simple program in java, which I use to read and write a few things in one SQLITE database, located within the directory I have the jar file. To access the database and a settings file, I use the

String wd = System.getProperty("user.dir");
String dbName = "jdbc:sqlite:"+wd+"\\"+sqliteDataNae;
c = DriverManager.getConnection(dbName);

Long story short, I have made a jar file wrapping all libraries in and tested it in Windows where everything works fine. I get my data stored in my database. Not exception at all!

Then I transfer all my files in a rar file to an ubuntu (14) hyperv virtual machine. I use the terminal to go to my directory where I have unzipped everything, and run:

java -jar myJar.jar

The script starts running, I get my println and the setting are all loaded (hence no issue reading the settings txt file - located in the same directory as the database = no directory issue), The problem is that I get an sqlite exception [SQLITE_ERROR] SQL error or missing database (no such table: User).

However, I open my database (using SQLite Database Browser) and the table exists.

Is there any logical explanation for this? and is there any solution?


Answer:

My guess is since Linux uses forward slashes for path separators you'll need to replace '\\' with '/'. However to make life easier just use File.separator instead as it automatically gives you the default separator for the current OS.

Question:

I am deploying a java application in windows IDE but this application will be run in Ubuntu. What cross compiler do I need to compile in windows and then deploy it in Ubuntu?

Thank you,


Answer:

All Java compilers are cross-platform. That's one of the most important characteristics of Java. Java compiles to byte-code, which is the interpreted by a virtual machine. If a computer has a virtual machine it can run byte code generated in any operating system.

Question:


Answer:

First of all, Lubuntu needs to know who is PCName, so ping it from terminal and verify:

ping PCName

If you can resolve PCName to XXX.YYY.KKK.ZZZ, you can mount it.

If you can't resolve the name, Lubuntu can't mount an undefined network resource and i suppose that it's your case:

mount error: could not resolve address for PCName

This is a network question, not really a programming question.

Have you a Domain Server or a DNS server in the network?

If you have it, on your Lubuntu PC set the DNS server to that ip and try to resolve PCName again. Lubuntu will be able to resolve PCName asking to the server (DNS or DC).

Have you access to the DHCP server (on the router I suppose) ?

If you have it, you can map you PCName's MAC address to a particular fixed address. Your Windows PC is still in DHCP but it receive always the same ip.

On Lubuntu add a row in /etc/hosts and the trick is done.

Can't you apply those solutions? ARP-scanning

If you know your Windows PCName's mac address, you can make an ARP scan on the network.

You'll receive a map IP -> MAC so from MAC you get the IP. Now, you can mount your PCName by his IP.

This solution may fail if a firewall, an antivirus software or a IPS block the arp-scanning.

Remember : you can do all linux commands throw Runtime.exec, read this other question. If you can do it in Linux, you can do it in Java

Question:

In an assignment designed to highlight race conditions, we were given the following code

public class IncreaseDecrease {

    public static int IntegerVariable = 0;
    public static final int NUM_ITER = 5000000;

    public static void main(String[] args) throws Exception {

        Increase inc;
        Decrease dec;

        while (true) {          
            inc = new Increase();
            dec = new Decrease();

            inc.start();
            dec.start();

            inc.join();
            dec.join();

            System.out.println(IntegerVariable);
            IntegerVariable = 0;
            Thread.sleep(750);
        }
    }   
}

class Increase extends Thread {

    @Override
    public void run() {
        for (int i = 0; i < IncreaseDecrease.NUM_ITER; i++) {
            IncreaseDecrease.IntegerVariable++;
        }
    }
}

class Decrease extends Thread {

    @Override
    public void run() {
        for (int i = 0; i < IncreaseDecrease.NUM_ITER; i++) {
            IncreaseDecrease.IntegerVariable--;
        }
    }
}

this code which would be expected to print 0 if each thread can update the value before the other one reads it, but that does not happen due to race conditions, it can print any value between -5000000 and 5000000. I ran that code on windows and repl.it, and it gave the expected output: -310951 -1918567 -3374495 -3219135 -2286639 -3221055 -3794319 -2442047 -2776415 -3617391 But on Ubuntu, when I ran it, it gave 0 every time.

My question is, why does this happen? Does Ubuntu manage threads differently, or is it just a special case for my computer?

Edit: After putting the increment in a different method and adding one more operation to it, I observed the race condition. Here's the final code:

public class IncreaseDecrease {

    public static int IntegerVariable = 0;
    public static final int NUM_ITER = 5000000;

    public static void main(String[] args) throws Exception {

        Increase inc;
        Decrease dec;

        while (true) {          
            inc = new Increase();
            dec = new Decrease();

            inc.start();
            dec.start();

            inc.join();
            dec.join();

            System.out.println(IntegerVariable);
            IntegerVariable = 0;
            Thread.sleep(750);
        }
    }
    public static void increment ()
    {
        IntegerVariable++;
        double a = Math.pow(3, 7);
    }
    public static void decrement()
    {
        IntegerVariable--;
        double a = Math.pow(3, 7);
    }
}

class Increase extends Thread {

    @Override
    public void run() {
        for (int i = 0; i < IncreaseDecrease.NUM_ITER; i++) {
            IncreaseDecrease.increment();
        }
    }
}

class Decrease extends Thread {

    @Override
    public void run() {
        for (int i = 0; i < IncreaseDecrease.NUM_ITER; i++) {
            IncreaseDecrease.decrement();
        }
    }
}

Answer:

I'd go out on a limb and claim that Hotspot under Linux using the server compiler while it doesn't on Windows is the more likely explanation: The compiler can replace the whole loop with a single expression which is something that HotSpot is definitely capable of. Adding any native method will make that impossible thereby making it much more likely to observe the race condition

I would guess that this might be the case as well.

Have you tried making your IntegerVariable volatile? This would prevent some compiler optimization that might occur.

public static volatile int IntegerVariable = 0;

Question:

I'm developing an enterprise management system using: JS, Java 8.91, Tomcat 8.5.4 and MySQL 5.7.

The system has many databases:

  • Main Database that stores user's information(login, password, email and user's database name).

  • User's Database, stores user's company information. When an user signs up, Hibernate creates a new DB for the new User.

It works perfectly on Windows but when I test it on UbuntuServer 16.04 64x, some bugs/issues happens, Hibernate:

  • Duplicates almost every table from MainDB(example: it duplicates table "users". creates a new table "Users").
  • When hibernate creates User's DB, it mess with tables name(example: hibernate should create a table named "address", but it creates a table named "Address" instead).

Honestly I don't know what's happening, I never saw this before and I don't know how to solve it. Every help/tip will be appreciated.


Answer:

Reference: Are table names in MySQL case sensitive?

Solution 1
  • sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
  • Under [mysqld], add this line: lower_case_table_names = 1
  • sudo service mysql restart
Solution 2
  • Make sure you named all classes using @Table. Example: @Table(name="your_table_name")

Question:

Here are the specific settings right now of the environment variables window of my Windows 7: Variable name: activator Variable value: C:\Users\Bryan\Documents\Client_Folders\activator-1.3.2-minimal Variable name: Java Variable value: C:\Program Files\Java\jdk1.8.0_40\bin Variable name: Javac Variable value: C:\Program Files\Java\jdk1.8.0_40\bin And when I issue an activator command I get the following errors: Microsoft Windows [Version 6.1.76011 Copyright 2009 Microsoft Corporation. All rights reserved. C:\Users\Bryan>activator new 'activator' is not recognized as an internal or external command, operable program or hatch file.

C:\Users\Bryan>cd C:\Users\Bryan\Documents\Client_Folders\activator-1.3.2-minima 1 C:\Users\Bryan\Documents\Client_Polders\activator-1_3_2-minimanal>activator new

A Java JDK is not installed or can't be found. Please go to http://www.oracle.com/technetwork/java/javase/downloads/index.html and download a valid Java JDK and install before running Activator. If you think this message is in error, please check your environment variables to see if "java.exe" and "javac.exe" are available via JAvA_HOME or PATH.

For the Ubuntu machine I followed some precise instructions on how to download the Play framework and the JDK, and setting the environment paths but I am getting errors there too. If you can tell me what command's output you need, I will supply them.

Thanks a million for any help in advance.


Answer:

Mkay, two things:

1. You didn't pay much attention when reading the docs.

For the activator environment variable:

This means update the PATH in the environment variables and don’t use a path with spaces.

Ergo: edit the existing PATH env. var and insert there the path to your activator. DO NOT create another user env. var. like you did(e.g. activator)

2. You're not setting your JAVA_HOME properly

Replace the Java and Javac env. vars with JAVA_HOME = path_to_your_java

After successfully completing 1 + 2 restart your CLI and everything will work just fine.

Cheers!

Question:

I have currently switched to Ubuntu and want to continue using it. So,I want to copy all my codes that was in windows workspace to Ubuntu's eclipse workspace so that I can use that code whenever required. So I copied all codes and pasted in ubuntu's eclipse workspace but facing problem that when I open eclipse in ubuntu,it is still empty. It is not recognizing any of the copied projects. How can I use it in Ubuntu?


Answer:

You need to import the projects into Eclipse, regardless of whether you pasted the files into the work space. Go to File>Import, choose the type of project it is that you want to import, and follow the prompts.

Here is a simple tutorial.

Also, maybe look into using version control such as git. Here are some resources on that. I really like TortoiseGit.

Git for Beginners

TortoiseGit

Question:


Answer:

PhoneGap uses html, Titanium uses javascript. Both run on iOS (after jumping through the proper hoops).

I believe you can use the xcodebuild option from commandline to work with native Objective C iOS projects in Linux if I'm not mistaken. If not, you can virtualize a Mac environment to run xcode in full.

Typically, it's best to learn the ropes of the native platform for best results. Most other options will require sacrificing functionality or ease of implementation.

As a last resort, you may be able to install OS X on your PC if you have compatible components. Check out "Hackintosh" for more info on this route.